def todo_save(): """ Saves the edited item into the database and redirects to main list for validated users Produces error message for anon or invalid users """ edit = bottle.request.forms.get('task', '').strip() status = bottle.request.forms.get('status', '').strip() num = bottle.request.forms.get('num', '').strip() if status == 'open': status = 1 else: status = 0 #verify user session = sign_up.get_session() email = session['email'] user_info = manage_users.get_info_from_db(email) if user_info: db.tasks.update({'_id': int(num)}, {'$set': { 'task': edit, 'status': status }}) return bottle.redirect('/todo') else: cur_task = db.tasks.find_one({'_id': int(num)}) return bottle.template( 'edit_task', old=cur_task, num=num, error_msg= "Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error" )
def save_new_item(): """ Saves the new item into the database and redirects to main list for validated users Produces error message for anon or invalid users """ new = bottle.request.forms.get('task', '').strip() new_id = db.tasks.count() + 1 #verify user session = sign_up.get_session() email = session['email'] user_info = manage_users.get_info_from_db(email) if user_info: db.tasks.insert({ "_id": new_id, "task": new, "status": 1, "username": user_info['username'] }) if 'food' in user_info: db.tasks.update({"_id": new_id}, {"$set": { "food": user_info['food'] }}) return bottle.redirect('/todo') else: return bottle.template( 'new_task', error_msg= "Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error" )
def get_username(): """ Uses the email from the session to go into db to get username """ email = get_email() if email: if email == 'anon': return 'Anonymous User' user_info = manage_users.get_info_from_db(email) return user_info['username'] else: return None
def say_hello_to_my_friend(): """ Mostly a test page to see if user is recognized """ session = get_session() email = session['email'] user_info = manage_users.get_info_from_db(email) if user_info: username = user_info['username'] food = user_info['food'] elif email == "anon": username = "******" food = "food" return bottle.template('welcome', dict(username = username, food = food))
def say_hello_to_my_friend(): """ Mostly a test page to see if user is recognized """ session = get_session() email = session['email'] user_info = manage_users.get_info_from_db(email) if user_info: username = user_info['username'] food = user_info['food'] elif email == "anon": username = "******" food = "food" return bottle.template('welcome', dict(username=username, food=food))
def save_new_item(): """ Saves the new item into the database and redirects to main list for validated users Produces error message for anon or invalid users """ new = bottle.request.forms.get('task', '').strip() new_id = db.tasks.count() + 1 #verify user session = sign_up.get_session() email = session['email'] user_info = manage_users.get_info_from_db(email) if user_info: db.tasks.insert({"_id": new_id, "task": new, "status": 1, "username": user_info['username']}) if 'food' in user_info: db.tasks.update({"_id": new_id}, {"$set": {"food": user_info['food']}}) return bottle.redirect('/todo') else: return bottle.template('new_task', error_msg = "Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error")
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))
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))
def todo_save(): """ Saves the edited item into the database and redirects to main list for validated users Produces error message for anon or invalid users """ edit = bottle.request.forms.get('task','').strip() status = bottle.request.forms.get('status','').strip() num = bottle.request.forms.get('num','').strip() if status == 'open': status = 1 else: status = 0 #verify user session = sign_up.get_session() email = session['email'] user_info = manage_users.get_info_from_db(email) if user_info: db.tasks.update({'_id': int(num)}, {'$set': {'task': edit, 'status': status}}) return bottle.redirect('/todo') else: cur_task = db.tasks.find_one({'_id': int(num)}) return bottle.template('edit_task', old=cur_task, num=num, error_msg="Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error")