示例#1
0
    def signin(self):
        if current_user.is_authenticated:
            return redirect(url_for('ProviderView:dashboard'))

        form = SignInForm()
        if request.method == 'POST':
            return post_login(form)

        return render_template('home/login.html', form=form)
示例#2
0
def post_login(form: SignInForm):
    if not form.validate_on_submit():
        flash_error(form.errors)
        return render_template('home/login.html', form=form)

    email = form.email.data.lower()
    check_user = ProviderUser.get_by_email(email)
    if not check_user:
        flash_error('User not found.')
        return render_template('home/login.html', form=form)

    if check_user.status == ProviderUser.Status.NO_ACTIVE:
        flash_error('User not active.')
        return render_template('home/login.html', form=form)

    if not ProviderUser.check_password_hash(check_user.password, form.password.data):
        flash_error('Invalid password.')
        return render_template('home/login.html', form=form)

    check_user.login()
    return redirect(url_for('ProviderView:dashboard'))