Ejemplo n.º 1
0
def store_user_and_pw():
    """
    Adds user to database and redirects to todo page
    Reproduces page with appropriate error message if:
     - passwords don't match, or
     - user is already in database
     """
    email = bottle.request.forms.get('email')
    username = bottle.request.forms.get('username')
    password = bottle.request.forms.get('password')
    pwconf = bottle.request.forms.get('passwordconf')
    food = bottle.request.forms.get('food') #took this variable for fun

    if password == pwconf:
        user_error_check = manage_users.add_user(email,
                username, password, food)
        if not user_error_check:
            #Hooray, the pws match and the user is not in the system
            session_id = manage_users.start_session(email)
            cookie = manage_users.get_cookie(session_id)
            bottle.response.set_cookie("session", cookie)
            bottle.redirect('/todo')
        else:
            pw_error_message = "Your passwords do not match"
            return bottle.template('signup', dict(pw_error = None,
                user_error = user_error_check))
    else:
        return bottle.template('signup', dict(pw_error = pw_error_message,
            user_error = None))
Ejemplo n.º 2
0
def store_user_and_pw():
    """
    Adds user to database and redirects to main page
    Reproduces page with appropriate error message if:
     - passwords don't match, or
     - user is already in database
     """
    email = bottle.request.forms.get('email')
    username = bottle.request.forms.get('username')
    password = bottle.request.forms.get('password')
    pwconf = bottle.request.forms.get('passwordconf')

    if password == pwconf:
        user_error_check = manage_users.add_user(email, username, password)
        if not user_error_check:
            #Hooray, the pws match and the user is not in the system
            session_id = manage_users.start_session(email)
            cookie = manage_users.get_cookie(session_id)
            bottle.response.set_cookie("session", cookie)
            bottle.redirect('/main')
        else:
            pw_error_message = "Your passwords do not match"
            return bottle.template(
                'signup', dict(pw_error=None, user_error=user_error_check))
    else:
        return bottle.template(
            'signup', dict(pw_error=pw_error_message, user_error=None))
Ejemplo n.º 3
0
def log_user_in():
    """
    Checks for Hacker School users and general users of the site.
    If the email and password match the database, redirects to main page
    If user is a new Hacker Schooler with correct login info,
    adds them to the database
    If password is incorrect, asks them to retry
    If email is not recognized, asks them to sign_up for the email entered
    """
    email = bottle.request.forms.get('email')
    password = bottle.request.forms.get('password')

    hs_user_info = hs_auth.authenticate_with_hs(email, password)
    user_info = manage_users.get_info_from_db(email)

    user_error_msg = None
    pw_error_msg = None

    if hs_user_info or manage_users.email_matches_password(
            user_info, password):
        if hs_user_info:
            #user is a hackerschooler but isn't in my db
            username = "******" % (hs_user_info['first_name'],
                                  hs_user_info['last_name'])
            manage_users.add_user(email, username)

        session_id = manage_users.start_session(email)
        cookie = manage_users.get_cookie(session_id)
        bottle.response.set_cookie("session", cookie)
        bottle.redirect('/main')
    else:
        if user_info:
            pw_error_msg = "Log in not successful; check your email/pw"
        else:
            user_error_msg = "We don't have that email in our db,"
        return bottle.template(
            'login', dict(user_error=user_error_msg, pw_error=pw_error_msg))
Ejemplo n.º 4
0
def log_user_in():
    """
    Checks for Hacker School users and general users of the site.
    If the email and password match the database, redirects to todo page
    If user is a new Hacker Schooler with correct login info,
    adds them to the database
    If password is incorrect, asks them to retry
    If email is not recognized, asks them to sign_up for the email entered
    """
    email = bottle.request.forms.get('email')
    password = bottle.request.forms.get('password')

    hs_user_info = hs_auth.authenticate_with_hs(email, password)
    user_info = manage_users.get_info_from_db(email)

    user_error_msg = None
    pw_error_msg = None

    if hs_user_info or manage_users.email_matches_password(user_info, password):
        if hs_user_info:
            #user is a hackerschooler but isn't in my db
            username = "******" % (hs_user_info['first_name'],
                    hs_user_info['last_name'])
            manage_users.add_user(email, username)

        session_id = manage_users.start_session(email)
        cookie = manage_users.get_cookie(session_id)
        bottle.response.set_cookie("session", cookie)
        bottle.redirect('/todo')
    else:
        if user_info:
            pw_error_msg = "Log in not successful; check your email/pw"
        else:
            user_error_msg = "We don't have that email in our db,"
        return bottle.template('login', dict(user_error = user_error_msg,
            pw_error = pw_error_msg))
Ejemplo n.º 5
0
def store_user_and_pw():
  username = bottle.request.forms.get('username')
  password = bottle.request.forms.get('password')
  pwconf = bottle.request.forms.get('passwordconf')
  food = bottle.request.forms.get('food') #took this variable for fun

  pw_error_check = manage_users.check_if_pws_match(password, pwconf)

  if pw_error_check == None:
    user_error_check = manage_users.add_user(username, password, food)
    if user_error_check == None:
      entry = users.find_one({"_id": username})
      hashed_pw = entry["password"]
      #Houston we are a go, the pws match and the user is not in the system
      #THIS IS WHERE THE MAGIC HAPPENS
      session_id = manage_users.start_session(username)
      cookie = manage_users.get_cookie(session_id)
      bottle.response.set_cookie("session", cookie)
      bottle.redirect('/welcome')
    else:
      return bottle.template('signup', dict(pw_error = "", user_error =
                                            user_error_check))
  else:
    return bottle.template('signup', dict(pw_error = pw_error_check, user_error = ""))