Exemplo n.º 1
0
def signup():

    if not session.get('logged_in'):

        form = forms.LoginForm(request.form)

        if request.method == 'POST':

            username = request.form['username'].lower()

            password = helpers.hash_password(request.form['password'])

            email = request.form['email']

            if form.validate():

                if not helpers.username_taken(username):

                    helpers.add_user(username, password, email)

                    session['logged_in'] = True

                    session['username'] = username

                    return json.dumps({'status': 'Signup successful'})

                return json.dumps({'status': 'Username taken'})

            return json.dumps({'status': 'User/Pass required'})

        return render_template('login.html', form=form)

    return redirect(url_for('login'))
Exemplo n.º 2
0
def signup():
    if not session.get("logged_in"):
        form = forms.LoginForm(request.form)
        if request.method == "POST":
            username = request.form["username"].lower()
            password = helpers.hash_password(request.form["password"])
            email = request.form["email"]
            if form.validate():
                if not helpers.username_taken(username):
                    helpers.add_user(username, password, email)
                    session["logged_in"] = True
                    session["username"] = username
                    return json.dumps({"status": "Signup successful"})
                return json.dumps({"status": "Username taken"})
            return json.dumps({"status": "User/Pass required"})
        return render_template("login.html", form=form)
    return redirect(url_for("login"))
Exemplo n.º 3
0
def register():
    if not session.get('logged_in'):
        form = forms.LoginForm(request.form)
        if request.method == 'POST':
            username = request.form['username'].lower()
            password = helpers.hash_password(request.form['password'])
            if form.validate():
                if request.form['password'] == request.form['cpassword']:
                    if not helpers.username_taken(username):
                        helpers.add_user(username, password)
                        session['logged_in'] = True
                        session['username'] = username
                        return redirect(url_for('homepage'))
                    return render_template('register.html', error="Username Taken")
                return render_template('register.html', error="Passwords do not match")
            return render_template('register.html', error="User/Pass Required")
        return render_template('register.html', form=form)
    return redirect(url_for('homepage'))
Exemplo n.º 4
0
def signup():
    if session.get('logged_in'):
        return redirect(url_for('home'))
    else:
        form = forms.SignupForm(request.form)

        if request.method == 'POST':
            username = request.form['username'].lower()
            password = helpers.hash_password(request.form['password'])
            email = request.form['email']

            if form.validate():
                if not helpers.username_taken(username):
                    helpers.add_user(username, password, email)
                    session['logged_in'] = True
                    session['username'] = username
                    return redirect(url_for('home'))
                flash('Username taken', 'error')
                return render_template("out_facing/signup.html"), 401
            flash("Missing a required field", 'error')
            return render_template("out_facing/signup.html"), 400
        return render_template("out_facing/signup.html")