Example #1
0
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")
Example #2
0
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")
Example #3
0
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")
Example #4
0
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")
Example #5
0
 def author(self):
     #return self.author_id
     #TODO: Check whats happends user is non existing
     return User.get(self.author_id).name
Example #6
0
def load_user(userid):
    return User.get(userid)
Example #7
0
 def author(self):
     #return self.author_id
     #TODO: Check whats happends user is non existing
     return User.get(self.author_id).name
Example #8
0
def load_user(userid):
    return User.get(userid)