def login(): """Public login view""" if current_user.is_authenticated: return redirect(url_for("main.index")) form = LoginForm() if request.method == "POST" and form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None or not user.verify_pass(form.password.data): flash("Invalid username or password") return redirect(url_for("auth.login")) elif not user.active: flash("You're banned!") return redirect(url_for("auth.login")) login_user(user, remember=True) next_page = request.args.get("next") if not next_page or url_parse(next_page).netloc != "": next_page = url_for("main.index") return redirect(next_page) return render_template("auth/login.html", title="Sign In", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash('Invalid username or password') return render_template('auth/login.html', form=form)
def login(): form = LoginForm() next_page = request.args.get('next', '/') form_error_message = None if request.method == 'POST' and form.validate_on_submit(): user = check_user(form.data['username'], form.data['password']) if user: session['user_id'] = user['id'] session['loginned'] = True return redirect(next_page) else: form_error_message = 'User Not Found' context = {'form': form, 'form_error_message': form_error_message} return render_template('auth/login.html', **context)
def post(self): form = LoginForm(request.form) if form.validate(): try: user = User.objects.get(username=form.username.data) except DoesNotExist, e: user = None if user and user.check_password(form.password.data): flask_login.login_user(user) return redirect(url_for("admin.index")) flash("Invalid Username or Password")
def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('auth.login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.index') return redirect(next_page) return render_template('auth/login.html', title='Sign In', form=form)
def sign_in(): forms = LoginForm() next_page = request.args.get('next', '/') if request.method == 'POST' and forms.validate_on_submit(): user = User.query.filter_by(username=forms.username.data).first() if user and user.check_password(forms.password.data): login_user(user) flash('Logged in succesfully.') return redirect(next_page) else: flash('User not found.') context = { 'forms': forms, } return render_template('auth/sign.html', **context)
def login_page(): if current_user.is_authenticated: return redirect(url_for('home.homepage')) form = LoginForm() if form.validate_on_submit(): user = UserModel.query.filter_by(email=form.email.data).first() if user and user.verify_password(form.password.data): login_user(user, remember=form.remember_me.data) next_url = request.args.get('next') return redirect(next_url) if next_url else redirect( url_for('home.homepage')) flash("Login unsuccessful. Please check your email and password", 'danger') return render_template('auth/login.html', title="Login", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.blog')) 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): # login_user takes user and remember as arg login_user(user, remember=form.remember.data) flash('You have been logged in.', 'success') next_page = request.args.get('next') return redirect( url_for('auth.account')) if next_page else redirect( url_for('main.blog')) else: flash('Login Unsucessful. Please check email and password', 'danger') return render_template('auth/login.html', form=form)