def get(self, chat_room_name_from_url=None): chat_room_name_from_url = chat_room_name_from_url.decode('utf8') chat_room_name_normalized = chat_room_name_from_url.lower() if chat_room_name_normalized: logging.info('Query for room name: ' + chat_room_name_normalized) chat_room_obj = ChatRoomModel.query(ChatRoomModel.chat_room_name_normalized == chat_room_name_normalized).get() if chat_room_obj: response_dict = { 'chatRoomName': chat_room_name_normalized, 'roomIsRegistered': True, 'numInRoom': chat_room_obj.get_occupancy(), } logging.info('Found room: ' + repr(chat_room_obj)) else: response_dict = { 'chatRoomName': chat_room_name_normalized, 'roomIsRegistered' : False, 'numInRoom': 0 } logging.info('Room name is available: ' + chat_room_name_normalized) http_helpers.set_http_ok_json_response(self.response, response_dict) else: err_status = 'ErrorChatRoomNameRequired' # log this error for further analysis status_reporting.log_call_stack_and_traceback(logging.error, extra_info = err_status) http_helpers.set_http_error_json_response(self.response, err_status)
def get(self, username_from_url=None): username_from_url = username_from_url.decode('utf8') username_normalized = username_from_url.lower() if username_normalized: logging.info('Query for username: '******'usernameNormalized': username_normalized, 'usernameAvailable': False, } logging.info('Username taken: ' + repr(user_obj)) else: response_dict = { 'usernameNormalized': username_normalized, 'usernameAvailable': True, } logging.info('Username is available: ' + username_normalized) http_helpers.set_http_ok_json_response(self.response, response_dict) else: err_status = 'ErrorUsernameRequired' # log this error for further analysis status_reporting.log_call_stack_and_traceback(logging.error, extra_info = err_status) http_helpers.set_http_error_json_response(self.response, err_status)
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except: status_string = "serverError" request = None # Check if this is a method on a RequestHandler object, and if so we also write # out an error to the http response. # Note: this code is only executed if an error occurs, and therefore we don't worry # about the extra "cost" of executing the code below since it should be rarely executed. arg_spec = inspect.getargspec(func) if arg_spec.args and arg_spec.args[0] == 'self': # if the first parameter is 'self' then it is likely that this is a method on an object self = args[0] if hasattr(self, '__class__'): # if self has an attrute '__class__' this self is likely a parameter on a method object # as opposed to a parameter on a function cls = self.__class__ if issubclass(cls, webapp2.RequestHandler): # if cls is a subclass of RequestHander, then we are pretty sure that the user is generating http on the # self.response object if hasattr(self, 'response'): # If self has a 'response' attribute, then write out the error_status to self.response. request = self.request logging.debug('executing set_http_error_json_response self.response=%s and status_string=%s' % (repr(self.response), status_string)) http_helpers.set_http_error_json_response(self.response, status_string, 500) # Log the error to the server, along with stack trace and debugging information logging.debug('executing log_call_stack_and_traceback with extra_info = %s' % status_string) status_reporting.log_call_stack_and_traceback(logging.error, extra_info = status_string, request = request)
def post(self): data_object = json.loads(self.request.body) username_as_written = data_object['usernameAsWritten'] username_normalized = username_as_written.lower() auth_id = 'username:'******'t rely on auth_id because it is a list # containing various logins that the user may wish to use - such as email address, user name, perhaps # a facebook login token, etc. # Not necessary to include username in the unique_properties, since it will be included # in the "auth_id" in the create_user function, which will ensure that it is unique. unique_properties = None expiration_datetime = datetime.datetime.utcnow() + datetime.timedelta(minutes=constants.unregistered_user_token_session_expiry_minutes) user_created_bool, user_obj = users.UserModel.create_user(auth_id, unique_properties, username_normalized=username_normalized, username_as_written=username_as_written, registered_user_bool=False, expiration_datetime=expiration_datetime) if user_created_bool: user_id = user_obj.key.id() logging.info('New user object created. user_id: %d' % user_id) # close any active session the user has since he is trying to login # if self.session.is_active(): # self.session.terminate() # # # Writing a value to the session causes a new session to be created. # self.session.user_id = user_obj.key.id() # # self.redirect(self.uri_for('main')) jwt_token = token_sessions.generate_jwt_token(user_obj.key.id(), user_obj.username_as_written, expiration_datetime) response_dict = { 'token': jwt_token, } http_helpers.set_http_ok_json_response(self.response, response_dict) else: err_msg = 'Failed to create username %s', username_normalized logging.error(err_msg) http_helpers.set_http_error_json_response(self.response, err_msg, http_status_code=403)
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except: status_string = "serverError" request = None # Check if this is a method on a RequestHandler object, and if so we also write # out an error to the http response. # Note: this code is only executed if an error occurs, and therefore we don't worry # about the extra "cost" of executing the code below since it should be rarely executed. arg_spec = inspect.getargspec(func) if arg_spec.args and arg_spec.args[0] == 'self': # if the first parameter is 'self' then it is likely that this is a method on an object self = args[0] if hasattr(self, '__class__'): # if self has an attrute '__class__' this self is likely a parameter on a method object # as opposed to a parameter on a function cls = self.__class__ if issubclass(cls, webapp2.RequestHandler): # if cls is a subclass of RequestHander, then we are pretty sure that the user is generating http on the # self.response object if hasattr(self, 'response'): # If self has a 'response' attribute, then write out the error_status to self.response. request = self.request logging.debug( 'executing set_http_error_json_response self.response=%s and status_string=%s' % (repr(self.response), status_string)) http_helpers.set_http_error_json_response( self.response, status_string, 500) # Log the error to the server, along with stack trace and debugging information logging.debug( 'executing log_call_stack_and_traceback with extra_info = %s' % status_string) status_reporting.log_call_stack_and_traceback( logging.error, extra_info=status_string, request=request)