def post(self): applog("INFO: Add_Video_Handler Called") resp_obj = Map() resp_obj.handler = "Add_Video_Handler" in_obj = Map() in_obj.video_name = self.get_argument('video_name', "") in_obj.video_url = self.get_argument('video_url', "") in_obj.video_tags = self.get_argument('video_tags', "") # If the JSON->Python object conversion was sucessfull the server # can access the objects data and return something to the client if 'video_name' in in_obj and 'video_url' in in_obj and 'video_tags' in in_obj: relaxdb = RelaxDB() relaxdb.open() user_id = self.get_current_user() video_id = relaxdb.add_video(in_obj.video_name, in_obj.video_url) relaxdb.map_video(user_id,video_id,in_obj.video_tags) resp_obj.video_list = relaxdb.get_mapped_videos(user_id) resp_obj.call_result = "SUCCESS" relaxdb.close() else: resp_obj.call_result = "FAILURE - Missing fields ", str(in_obj) self.write(json.dumps(resp_obj)) self.finish()
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()
def post(self): applog("INFO: Sign Out Called") resp_obj = Map() resp_obj.handler = "Sign_Out_Handler" user_id = self.get_current_user() applog("SECURITY: Signing out user_id %s\n" % user_id) self.set_current_user_id(False) resp_obj.call_result = "SUCCESS" self.write(json.dumps(resp_obj)) self.finish()