def login(): if current_user.is_authenticated(): return home() if request.method == "POST": if len(request.form.get("username")) == 0 or len(request.form.get("password")) == 0: return render_template("login.html", error="Username or password can not be blank") try: get_user = User.get(request.form.get("username").lower()) except: return render_template("login.html", error="Incorrect username") try: user_pass = get_user.password if request.form.get("password") == user_pass: login_user(get_user) else: return render_template("login.html", error="Incorrect password") except Exception as e: return e return home() return render_template("login.html")
def login(): if current_user.is_authenticated(): return home() if request.method == "POST": if len(request.form.get("username")) == 0 or len( request.form.get("password")) == 0: return render_template( "login.html", error="Username or password can not be blank") try: get_user = User.get(request.form.get("username").lower()) except: return render_template("login.html", error="Incorrect username") try: user_pass = get_user.password if request.form.get("password") == user_pass: login_user(get_user) else: return render_template("login.html", error="Incorrect password") except Exception as e: return e return home() return render_template("login.html")
def signup(): if current_user.is_authenticated(): return home() if request.method == "POST": email_signup = request.form.get("email_signup") username = request.form.get("username_signup").lower() password = request.form.get("password_signup") try: user_exist = User.get(username) #email_exist = Email.get(email_signup) return "Sorry, a user with that name or email already exist." except ResourceNotFound: #create user new_user = User(email=email_signup, name=username, password=password) new_user._id = username new_user.save() login_user(User.get(username.lower())) return home() #new_email = Email(email=email_signup) #new_email._id = email_signup #new_email.save() except Exception as e: return e return render_template("signup.html")
def author(self): #return self.author_id #TODO: Check whats happends user is non existing return User.get(self.author_id).name
def load_user(userid): return User.get(userid)