def post(self): applog("INFO: Sign In Called") resp_obj = Map() resp_obj.handler = "Sign_In_Handler" in_obj = Map() in_obj.user_email = self.get_argument('user_email', "") in_obj.user_password = self.get_argument('user_password', "") applog("SECURITY: Attempt to login by user_email %s\n" % in_obj.user_email) # Check Permissions relaxdb = RelaxDB() relaxdb.open() if relaxdb.check_user(in_obj.user_email, in_obj.user_password): user_id = relaxdb.check_user(in_obj.user_email,in_obj.user_password) applog("SECURITY: user_id " + str(user_id) + " has signed in sucessfully") self.set_current_user_id(user_id) resp_obj.call_result = "SUCCESS" resp_obj.user_id = user_id resp_obj.user_name = relaxdb.get_user_name(user_id) resp_obj.video_list = relaxdb.get_mapped_videos(user_id) else: applog("SECURITY: Invalid email or password") resp_obj.call_result = "FAILURE - Invalid email or password" relaxdb.close() self.write(json.dumps(resp_obj)) self.finish()
def post(self): applog("INFO: Register User Called") resp_obj = Map() resp_obj.handler = "Register_User_Handler" in_obj = Map() in_obj.user_name = self.get_argument('user_name', "") in_obj.user_email = self.get_argument('user_email', "") in_obj.user_password = self.get_argument('user_password', "") # If the JSON->Python object conversion was sucessfull the server # can access the objects data and return something to the client if 'user_name' in in_obj and 'user_email' in in_obj and 'user_password' in in_obj: relaxdb = RelaxDB() relaxdb.open() if not relaxdb.is_user(in_obj.user_email): # if email isn't registered, register user name, email and password user_id = relaxdb.add_user(in_obj.user_name,in_obj.user_email,in_obj.user_password) resp_obj.call_result = "SUCCESS" else: resp_obj.call_result = "FAILURE - Email",email,"has been used before. You may want to recover the password" print("Email",email,"has been used before. You may want to recover the password") relaxdb.close() else: resp_obj.call_result = "FAILURE - Missing a fields ", str(in_obj) self.write(json.dumps(resp_obj)) self.finish()