def index(): RegistrationForm = registrationForm() LoginForm = loginForm() if RegistrationForm.validate_on_submit(): user = Users.query.filter_by( email=RegistrationForm.email2.data).first() if user is not None: flash("Email Id already registered!") else: passw = generate_password_hash(RegistrationForm.password2.data) user = Users( email=RegistrationForm.email2.data, name=RegistrationForm.username2.data, pasword_hash=passw, ) db.session.add(user) db.session.commit() flash("Thanks for registeration! Login to continue") return redirect(url_for("index")) if LoginForm.validate_on_submit(): user = Users.query.filter_by(email=LoginForm.email1.data).first() if user is not None and user.check_password(LoginForm.password1.data): login_user(user) # flash('Log in Success') next = request.args.get("next") if next == None or not next[0] == "/": next = url_for("dashboard") return redirect(next) elif user is None: flash("Email Id not registered!") else: flash("Wrong Password!") return render_template("index.html", logForm=LoginForm, signForm=RegistrationForm)
def test_init_user(client): # check if all fields are initialized properly #_init__(self, username, fullname, email, password, user_group, authenticated): from werkzeug.security import generate_password_hash, check_password_hash username = '******' fullname = 'Aiden Chia' email = '*****@*****.**' password = '******' user_group = 'student' user = Users(username, fullname, email, password, user_group, False) print("\n[INFO] Initializing new user with following fields:") print("[INFO] Username: {}".format(user.username)) print("[INFO] Email: {}".format(user.email)) print("[INFO] Password: {}".format(user.password)) print("[INFO] User Group: {}".format(user.user_group)) print("[INFO] Checking hash({}) == {}".format(user.password, generate_password_hash(password))) assert user.username == username assert user.fullname == fullname assert user.email == email assert user.password == password assert user.user_group == user_group assert user.authenticated == False assert user.check_password(password)