def load_user(id): if id is None: redirect('/login') user = User() user.get_by_id(id) if user.is_active(): return user else: return None
def login(): if request.method == "POST" and "email" in request.form: email = request.form["email"] userObj = User() user = userObj.get_by_email_w_password(email) if user and flask_bcrypt.check_password_hash(user.password,request.form["password"]) and user.is_active(): remember = request.form.get("remember", "no") == "yes" if login_user(user, remember=remember): flash("Logged in!") return redirect('/') else: flash("unable to log you in") return render_template("login.html")
def register(): registerForm = forms.SignupForm(request.form) current_app.logger.info(request.form) if request.method == 'POST' and registerForm.validate() == False: current_app.logger.info(registerForm.errors) return "uhoh registration error" elif request.method == 'POST' and registerForm.validate(): email = request.form['email'] # generate password hash password_hash = flask_bcrypt.generate_password_hash(request.form['password']) # prepare User user = User(email,password_hash) print user try: user.save() if login_user(user, remember="no"): flash("Logged in!") return redirect('/sportnews') else: flash("unable to log you in") except: flash("unable to register with that email address") current_app.logger.error("Error on registration - possible duplicate emails") # prepare registration form # registerForm = RegisterForm(csrf_enabled=True) templateData = { 'form' : registerForm } return render_template("register.html", **templateData)