def login(): # if current_user.is_authenticated: # return redirect(url_for('dashboard')) if session.get('username', None): return redirect(url_for('dashboard')) form = LoginForm() if form.validate_on_submit(): # check if the entered email (from the form) exists in the database user = Users.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): # login_user(user) session['username'] = user.username flash('Login successful', 'success') return redirect(url_for('dashboard')) else: flash('Login Unsuccessful: Invalid email and/or password!', 'danger') return render_template('login.html', title="Login", form=form, signup=True) return render_template('login.html', title="Login", login=True, form=form, signup=False)
def index(): if current_user.is_authenticated: return redirect(url_for('home')) login_form = LoginForm() register_form = RegistrationForm() if login_form.validate_on_submit(): user = User.query.filter_by(email=login_form.email.data).first() if user and bcrypt.check_password_hash(user.password, login_form.password.data): login_user(user, remember=login_form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') if register_form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(register_form.password.data).decode('utf-8') user = User(username=register_form.username.data, email=register_form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('index')) return render_template('index.html', title='Please login or register!', register_form=register_form, login_form=login_form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if request.method == 'GET': return render_template('login.html', title='Login', form=form) if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: if bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('about')) msg = "Email or Password incorrect" return render_template("login.html", title="Login", form=form, msg=msg) msg = "User doesn't exists" return render_template("login.html", title="Login", form=form, msg=msg) msg = "Form is not valid,please check the entries!" return render_template("login.html", title="Login", form=form, msg=msg)
def adminLogin(): if session.get('admin', None): return redirect(url_for('adminDashboard')) form = AdminLoginForm() if form.validate_on_submit(): admin = Admins.query.filter_by(email=form.email.data).first() if admin and bcrypt.check_password_hash(admin.password, form.password.data): session['admin'] = admin.email flash(f'Admin - {admin.lastName}, {admin.firstName} has successfully logged in!', 'success') return redirect(url_for('adminDashboard')) return render_template('adminLogin.html', form=form, adminLogin=True)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') user = User.query.filter_by(username=username).first() if user and bcrypt.check_password_hash(user.password, password): login_user(user) return redirect(url_for('home')) else: flash('Login Unsuccessful. Please check email and password', 'fail') return render_template('login.html')
def login(): if 'loggedin' in session: return redirect(url_for("main.index")) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): session['loggedin'] = True session['id'] = user.id session['username'] = user.name return redirect(url_for("main.index")) else: flash("Login failed, please check credentials", "danger") return render_template("login.html", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for("home")) form = LoginForm() if request.method == "POST": print(request.form.get('username')) print(User.query.all()) print(request.form.get("username")) user = User.query.filter_by(email=request.form.get("username")).first() print(user) if user and bcrypt.check_password_hash( user.password, request.form.get("password") ): login_user(user) return redirect(url_for("skills")) # print(next_page) # print(user.todo) return render_template("login.html", form=form)
def is_valid(self, password=None): return bcrypt.check_password_hash(self.password, password)
def check_password(self, attempted_password): return bcrypt.check_password_hash(self.password, attempted_password)