Ejemplo n.º 1
0
def login():
    if not User.login_validate(request.form):
        return redirect("/")

    user = User.get_by_email({"email": request.form['email']})

    # uuid = unique user id
    session['uuid'] = user.id

    return redirect("/users")
Ejemplo n.º 2
0
def login():
    list_of_users = User.get_by_email(request.form['email'])
    if len(list_of_users) == 0:
        flash("Invalid Email/Password")
        return redirect("/")
    if not bcrypt.check_password_hash(list_of_users[0]['password'], request.form['password']):
        flash("Invalid Email/Password")
        return redirect('/')
    else:
        session['uuid'] = list_of_users[0]['id']
        return redirect("/wall")
Ejemplo n.º 3
0
def login():
    data = {"email": request.form["email"]}
    user_in_db = User.get_by_email(data)
    if not user_in_db:
        flash("Invalid Email/Password")
        return redirect("/")
    if not bcrypt.check_password_hash(user_in_db.password,
                                      request.form['password']):
        flash("Invalid Email/Password")
        return redirect('/')
    session['user_id'] = user_in_db.id
    return redirect("/dashboard")
Ejemplo n.º 4
0
def login_success():
    data = {"email": request.form['email']}
    user_in_db = User.get_by_email(data)
    if not user_in_db:
        flash("Invalid Email or Password")
        return redirect("/")
    if not bcrypt.check_password_hash(user_in_db.password,
                                      request.form['password']):
        flash("Invalid Email or Password")
        return redirect('/')
    # if the passwords matched, we set the user_id into session
    session['user_id'] = user_in_db.id
    # never render on a post!!!
    return redirect(f"/success/{user_in_db.id}")
Ejemplo n.º 5
0
def login():
    # see if the username provided exists in the database
    data = { "email" : request.form["email"] }
    user_in_db = User.get_by_email(data)
    # user is not registered in the db
    if not user_in_db:
        flash("Invalid Credentials")
        return redirect("/")
    if not bcrypt.check_password_hash(user_in_db.password, request.form['password']):
        # if we get False after checking the password
        flash("Invalid Credentials")
        return redirect('/')
    # if the passwords matched, we set the user_id into session
    session['user_id'] = user_in_db.id
    # never render on a post!!!
    return redirect("/dashboard")
Ejemplo n.º 6
0
def create():
    list_of_users = User.get_by_email(request.form['email'])
    if len(list_of_users) > 0:
        flash('Email already exists')
        return redirect('/')
    if not User.validate_inputs(request.form):
        return redirect('/')
    pw_hash = bcrypt.generate_password_hash(request.form['password'])
    data = {
        'first_name': request.form["first_name"],
        'last_name': request.form["last_name"],
        'email': request.form["email"],
        'password': pw_hash
    }
    user_id = User.create(data)
    print(user_id)
    session['uuid'] = user_id
    return redirect('/dashboard')
Ejemplo n.º 7
0
def add():
    if not User.validate_userInfo(request.form):
        return redirect('/')

    data = {"email": request.form['email']}
    user_in_db = User.get_by_email(data)
    if user_in_db:
        flash("Please add new email address, this email address already exist")
        return redirect('/')

    pw_hash = bcrypt.generate_password_hash(request.form['password'])

    data = {
        "first_name": request.form['first_name'],
        "last_name": request.form['last_name'],
        "email": request.form['email'],
        "password": pw_hash
    }
    user_id = User.save(data)
    session['user_id'] = user_id
    flash("You've been succssesfully regirstres")
    return redirect("/dashboard")
Ejemplo n.º 8
0
def register():

    if not User.validate_register(request.form):
        return redirect("/")

    data = {"email": request.form["email"]}
    user_in_db = User.get_by_email(data)
    if user_in_db:
        flash("Plesae create a new account! Email already in use!")
        return redirect("/")

    hashed_pw = bcrypt.generate_password_hash(request.form['password'])

    data = {
        "first_name": request.form['first_name'],
        "last_name": request.form['last_name'],
        "email": request.form['email'],
        "password": hashed_pw
    }

    user_id = User.register_user(data)

    session['user_id'] = user_id
    return redirect("/dashboard")