def signup(): form = SignupForm() print(form.validate_on_submit()) if form.validate_on_submit(): username = form.name.data password = form.password.data password1 = form.password_conf.data if password != password1: return '<h1>Password do not match!</h1>' if check_user_present(username): flash('User already present') return redirect(url_for('login')) hashed_pwd = bcrypt.hashpw(password.encode('utf8'), bcrypt.gensalt()) if bcrypt.checkpw(password.encode('utf8'), hashed_pwd): res = create_user(username, hashed_pwd) username,_,user_id = login_user(username) if res: session['id'] = user_id session['username'] = username flash('Signup Success!') return redirect(url_for('index')) else: flash('Signup Failed!') return redirect(url_for('signup')) return render_template('signup.html',form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if request.method == "POST" and form.validate_on_submit(): email = form.email.data password = form.password.data user = User.query.filter_by(email=email).first() if user and md5_crypt.verify(password, user.password): login_user(user) next_page = request.args.get("next") is_safe_url(next_page, request.url) if is_safe_url(next_page, request.url): return redirect(next_page) return redirect("/dashboard") else: flash("e-mail or password is incorrect") return redirect("/login") else: return render_template("login.html", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): username = form.name.data password = form.password.data user_name, user_pwd_hash, user_id = login_user(username) if user_name is None: flash('User not present') return redirect(url_for('login')) elif not bcrypt.checkpw(password.encode('utf8'), user_pwd_hash): flash('Incorrect Password!') return redirect(url_for('login')) else: session['id'] = user_id session['username'] = username #flash('Login Success!') return redirect(url_for('index')) return render_template('login.html',form=form)
def login(): if request.method == 'GET': return render_template("/auth/login.html") user_name = request.form.get('username') user_pwd = request.form.get('password') user = login_user(user_name, user_pwd) if user is not None: if user.password == user_pwd: session['userid'] = user.id session['username'] = user.username g.user = user return redirect(url_for('ToDOListAll')) else: flash('Invalid Credentials....') else: flash('Invalid Credentials....') return render_template('/auth/login.html')