示例#1
0
def newuser():
    if request.method == 'POST':
        username = request.form.get('username')
        psw1 = request.form.get('password1')
        psw2 = request.form.get('password2')

        if username == '' or psw1 == '' or psw2 == '':
            flash('All fields are required', 'danger')
            return redirect('/register')

        # username = username.encode('utf-8')
        psw1 = psw1.encode('utf-8')
        psw2 = psw2.encode('utf-8')

        if psw1 == psw2:
            psw = Password(psw1)
            hashed_psw = psw.get_hashed_password()
            message, success = database.insert_user(username, hashed_psw)
            if success == 1:
                flash('New user added!', 'primary')
                return redirect('/login')
            else:
                error('newuser', message, session.get('username'))
                flash('Internal error!', 'danger')
                return redirect('/register')

        flash('Passwords must be the same!', 'danger')
        return redirect('/register')
    else:
        return render_template('register.html')
示例#2
0
def register():
    if request.method == 'POST':
        form_username = request.form.get('username')
        form_password = request.form.get('password')
        guid = str(uuid.uuid4())
        password = Password(form_password, form_username, guid)
        hashed_password = password.get_hashed_password()
        message, success = database.insert_user(guid, form_username,
                                                hashed_password)
        # return render_template('login.html')
        if success:
            return "Registrado com sucesso"
        return "Registro falhou!"
    else:
        return "register"
示例#3
0
def newuser():
    if request.method == 'POST':
        username = request.form.get('username')
        psw1 = request.form.get('password1')
        psw2 = request.form.get('password2')

        if psw1 == psw2:
            psw = Password(str(psw1))
            hashed_psw = psw.get_hashed_password()
            message, success = database.insert_user(str(username), hashed_psw)
            if success == 1:
                flash("Novo usuario adicionado!", "primary")
                return redirect('/login')
            else:
                return redirect('/register')

        flash("Passwords must be the same!", "danger")
        return redirect('/register')
    else:
        return render_template('register.html')
示例#4
0
def register():
    if request.method == 'GET':
        return render_template('register.html')

    if request.method == 'POST':
        form_username = request.form.get('username', "")
        form_password = request.form.get('password', "")
        form_password2 = request.form.get('password2', "")

        if form_username == "" or form_password == "":
            return "Error! You have to pass username and password! \n"
        elif form_password != form_password2:
            return "Error! Passwords must be the same! \n"

        guid = str(uuid.uuid4())
        password = Password(form_password, form_username, guid)
        hashed_password = password.get_hashed_password()
        message, success = database.insert_user(guid, form_username,
                                                hashed_password)
        if success:
            return render_template('login.html')
        return "Error: account creation failed \n"