Пример #1
0
def signin():
    #instantiates a class called form which was defined in forms.py
    form = UserLoginForm()
    try:
        if request.method == "POST" and form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            #prints user input to terminal for confirmation/debug purposes
            print(email, password)
            #creates an instance of the User class for the current user from the first matching email in the email column in the db.
            logged_user = User.query.filter(User.email == email).first()
            #if the logged user and the user returned from the matched passwords
            if logged_user and check_password_hash(logged_user.password,
                                                   password):
                #take the method to login from flask_user and login the loggeduser defined above
                login_user(logged_user)
                print(logged_user)
                #do the flash method defined on the home.html (text to display, information for the flash parameter)
                flash('You were successfully logged in via Email/Password',
                      'auth-success')
                #redirect user to home
                return redirect(url_for('home'))
            else:
                flash('Your email/password is incorrect. Please try again',
                      'auth-failure')
                #keep them on sign in page
                return redirect(url_for('signin'))
    except:
        raise Exception('Invalid Form Data: Please check your form...')
    #again, like jwt below, form=form allows template to see the variable and render it
    return render_template('sign_in.html', form=form)
Пример #2
0
def signup():
    #instantiates a class called form which was defined in forms.py
    form = UserLoginForm()
    try:
        if request.method == 'POST' and form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            #prints user input to terminal for confirmation/debug purposes
            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)
Пример #3
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('signup.html', form=form)
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()

            flash(f'You have successfully created a user account {email}', 'user-created')

            return redirect(url_for('site.home'))
    except:
        raise Exception('Invalid form data: Please check your form.')

    return render_template('signup.html', form = form)
Пример #5
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)