def __check_for_require_params(self,auth_token,mac_address,key_mod,key_ex): """ Check if the params is qualified :params auth_token mac_address public_key: :return user_id or responseObject: """ if not auth_token:#check if auth_token is available return CommonResponseObject.unauthorized_token_response() #get user_id and key from the auth_token user_id= User.decode_auth_token(auth_token) if isinstance(user_id,str):#check if user_id is valid return CommonResponseObject.unauthorized_token_response() if not mac_address: #check if mac_address is valid return CommonResponseObject.fail_response( 'Please provide your MAC address', status.HTTP_412_PRECONDITION_FAILED) #check if key is valid modulus, exponent = User.decode_public_key(auth_token) key = RSAPair.get_RSA_by_public(modulus) if not key:#check if key is existed return CommonResponseObject.response( 'Some errors occured, provided key does not exists') user = User.get_user_by_id(user_id) #retrieve the user entity if not user: #check if the user is existed return CommonResponseObject.unauthorized_token_response() #check if the mac_address is stored if DatabaseCheck.is_mac_address_existed(mac_address): if DatabaseCheck.is_root_by_mac(mac_address): return CommonResponseObject.fail_response( 'Your device is the root device', status.HTTP_202_ACCEPTED) return CommonResponseObject.fail_response( 'Your device is already authorized', status.HTTP_202_ACCEPTED) return user,key
def get(self): """ User Information retrieval API """ auth_token = RequestUtils.get_access_token(request) user_id = User.decode_auth_token(auth_token) user = User.query.filter_by(id=user_id).first() if not user: return CommonResponseObject.fail_response( 'User does not exist, please try again', status.HTTP_404_NOT_FOUND) responseObject = { 'status': 'success', 'birthday': user.birthday, 'fullname': user.fullname, 'job': user.job, 'country': user.country } return CommonResponseObject.response(responseObject, status.HTTP_200_OK)