<reponame>fastguer/com.fastguer.website<filename>views/homepage.py
from flask import Blueprint, render_template, request
import json
from api.pre import PreUser

homepage = Blueprint('homepage', __name__)

@homepage.route("/")
def home_ptbr():
    return render_template('home-ptBR.html'), 200

@homepage.route("/pre")
def home_signup():
    return render_template('signup-ptBR.html'), 200

@homepage.route("/pre/v1/new/", methods=['GET', 'POST'])
def api_v1_pre():
    if request.method == "POST":
        phone = request.form['phone']
        name = request.form['name']
        birthday = request.form['birthday']
        sex = request.form['sex']
        wSize = request.form['wSize']
        sSize = request.form['sSize']

        if not phone or not name or len(phone)>16 or len(name)>120 or len(birthday)>10 or len(sex)>10 or len(wSize)>30 or len(sSize)>30:
            return '{"status":500}', 500, {"Content-Type": "application/json"}
        
        result = PreUser(phone).new(name, birthday, sex, [request.remote_addr, request.accept_languages[0][0], request.user_agent.platform, request.user_agent.browser, sSize, wSize])
        return json.dumps(result), result['status'], {"Content-Type": "application/json"}
    return '{"status":false}', 500, {"Content-Type": "application/json"}
from flask import Blueprint, render_template, request
import json
from api.pre import PreUser

homepage = Blueprint('homepage', __name__)

@homepage.route("/")
def home_ptbr():
    return render_template('home-ptBR.html'), 200

@homepage.route("/pre")
def home_signup():
    return render_template('signup-ptBR.html'), 200

@homepage.route("/pre/v1/new/", methods=['GET', 'POST'])
def api_v1_pre():
    if request.method == "POST":
        phone = request.form['phone']
        name = request.form['name']
        birthday = request.form['birthday']
        sex = request.form['sex']
        wSize = request.form['wSize']
        sSize = request.form['sSize']

        if not phone or not name or len(phone)>16 or len(name)>120 or len(birthday)>10 or len(sex)>10 or len(wSize)>30 or len(sSize)>30:
            return '{"status":500}', 500, {"Content-Type": "application/json"}
        
        result = PreUser(phone).new(name, birthday, sex, [request.remote_addr, request.accept_languages[0][0], request.user_agent.platform, request.user_agent.browser, sSize, wSize])
        return json.dumps(result), result['status'], {"Content-Type": "application/json"}
    return '{"status":false}', 500, {"Content-Type": "application/json"}