Esempio n. 1
0
def signup():
    form = UserLoginForm()

    try:
        if request.method == 'POST' and form.validate_on_submit(
        ):  #request - is the user requesting to POST or GET
            email = form.email.data
            password = form.password.data
            print(email, password)

            user = User(
                email, password=password
            )  #creating a user and this is their email and this is their password
            #The password field is going to equal the password that you pass in in models.py otherwise flask doesn't know which of the optional parameters the password is referring to

            db.session.add(
                user
            )  #session - you're git add .     .session adds the user to the database session (local host) and then when you commit you add it to the actual database
            db.session.commit()

            return redirect(url_for('signin'))

    except:
        raise Exception('Invalid Form Data: Please Check your form')

    return render_template('signup.html', form=form)
Esempio n. 2
0
def signup():
    form = UserLoginForm()
    try:
        if request.method == 'POST' and form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            print(email, password)
            user = User(email, password=password)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('signin'))
    except:
        raise Exception('Invalid Form Data: Please check your form')

    return render_template('sign_up.html', form=form)
Esempio n. 3
0
def signin():
    form = UserLoginForm()

    try:
        if request.method == 'POST' and form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            print(email,password)

            logged_user = User.query.filter(User.email == email).first()
            if logged_user and check_password_hash(logged_user.password, password):
                login_user(logged_user)
                flash('You were successfully logged in: Via Email/Password', 'auth-success')
                return redirect(url_for('home'))
            else:
                flash('Your Email/Password is incorrect', 'auth-failed')
                return redirect(url_for('signin'))
    except:
        raise Exception('Invalid Form Data: Please Check Your Form')
    return render_template('signin.html', form=form)