def post_message(token, email, msg): if not db.is_online_by_token(token): return {'status' : 'Fail', 'msg' : 'User not signed in.'} db.write_message(token, email, msg) return {'status' : 'Success', 'msg' : 'Message posted.'}
def change_password(token, old_password, new_password): if not db.is_online_by_token(token): return {'status' : 'Fail', 'msg' : 'User not signed in.'} if not valid_password(token_to_email(token), old_password): return {'status' : 'Fail', 'msg' : 'Wrong password.'} db.set_user_password(token_to_email(token), new_password) return {'status' : 'Success', 'msg' : 'Password changed.'}
def sign_out(token): if not db.is_online_by_token(token): return {'status' : 'Fail', 'msg' : 'Token not valid.'} online_users = db.get_online_users() if online_users.__contains__(token): db.set_user_offline(token) return {'status' : 'Success', 'msg' : 'User signed out.'}
def get_user_messages_by_email(token, email): if not db.is_online_by_token(token): return {'status' : 'Fail', 'msg' : 'User not signed in.'} return db.retrive_messages(email)