def login(): next_ = request.args.get("next") login_form = LoginForm(next_=next_) login_form.validate_on_submit() if login_form.validate_on_submit(): data = login_form.data username = data["username"] password = data["password"] customer = session.query(Customer).filter( Customer.email == username).first() if customer and customer.verify_password(password): login_user(customer, remember=True, duration=timedelta(1)) session.close() print(">>>>>>>>>>>>>>>", data['next_'], current_user.is_authenticated) if data['next_']: return redirect(data['next_']) return redirect(url_for('index_bp.index')) else: flash("Incorrect Credentials", "danger") signup_form = SignupForm(next_=next_) return render_template("signin_signup/signin-signup.html", show_login=True, login_form=login_form, signup_form=signup_form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) 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(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(url_for('home')) else: flash('Login unsuccessful. Email and/or password incorrect.') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for("home")) form = LoginForm() if form.validate_on_submit(): 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, remember=form.remember.data) next_page = request.args.get("next") if next_page: return redirect(next_page) else: return redirect(url_for("home")) return render_template("login.html", title="Login", form=form)
def signup(): next_ = request.args.get("next") signup_form = SignupForm(next_=next_) if signup_form.validate_on_submit(): data = signup_form.data name = data["name"] email = data["email"] telephone_code = data["telephone_code"] telephone = data["telephone"] password = data["password"] customer = Customer(name=name, email=email, contact=join_telephone(telephone_code, telephone), password=password) session.add(customer) session.commit() if customer: login_user(customer, duration=timedelta(1)) flash("Your account has been created.", "success") else: flash("There was an error creating your account.", "danger") if data['next_']: return redirect(data['next_']) return redirect(url_for('index_bp.index')) login_form = LoginForm(next_=next_) return render_template("signin_signup/signin-signup.html", show_signup=True, signup_form=signup_form, login_form=login_form)
def signin_signup(): next_ = request.args.get("next") signup_form = SignupForm(next_=next_) login_form = LoginForm(next_=next_) return render_template("signin_signup/signin-signup.html", show_login=True, signup_form=signup_form, login_form=login_form)