示例#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")
示例#2
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")
示例#3
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")
示例#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")
示例#5
0
def logout():
    logout_user()
    return home()
示例#6
0
def logout():
    logout_user()
    return home()