Exemplo n.º 1
0
def login():
    if current_user.is_authenticated:
        content = [f"Session Active", f"You are already logged in."]
        flash(content, category="info")
        return redirect(url_for("BP_home.home"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and encryptor.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            if user.admin:
                content = [f"Login Successful", f"Welcome to Admin Dashboard."]
                flash(content, category="success")
                return redirect(url_for("BP_admin.home"))
            content = [f"Login Successful", f"You have been successfully logged in."]
            flash(content, category="success")
            next_page = request.args.get("next")
            return (
                redirect(next_page) if next_page else redirect(url_for("BP_home.home"))
            )
        else:
            content = [
                f"Login Failed.",
                f"Incorrect Credentials, please try again!",
            ]
            flash(content, category="danger")
    return render_template("login.html", title="Login", page="Login. . .", form=form)
Exemplo n.º 2
0
 def validate_new_password(self, new_password):
     if encryptor.check_password_hash(current_user.password,
                                      new_password.data):
         raise ValidationError(
             "New password cannot be same as old password")
Exemplo n.º 3
0
 def validate_current(self, current):
     if not encryptor.check_password_hash(current_user.password,
                                          current.data):
         raise ValidationError("Incorrect Password")