def wrapper(self, *args, **kwargs): body = json.loads(self.request.body) if is_json( self.request.body) else {} token = self.request.GET.get('token') or self.request.POST.get( 'token') or body.get('token') user_id = self.request.GET.get('user_id') or self.request.POST.get( 'user_id') or body.get('user_id') if not token or not user_id: raise MSException(u'App token e o user_id devem ser enviados') app = App.query(App.token == token).get() user = User.get_by_id(user_id) if user_id != app.user_id: raise MSException(u'App token ou user_id invalido') if app and user and not app.deleted: self.app_data = { 'app': app.to_dict_json(), 'user': user.to_dict_json() } method(self, *args, **kwargs) ActivityLog.save(user_id=user_id, app_name=app.name, token=token, activity=activity) else: raise MSException(u'App token e o user_id invalido')
def wrapper(self, *args, **kwargs): body = json.loads(self.request.body) if is_json(self.request.body) else {} token = self.request.GET.get('token') or self.request.POST.get('token') or body.get('token') user_id = self.request.GET.get('user_id') or self.request.POST.get('user_id') or body.get('user_id') if not token or not user_id: raise MSException(u'App token e o user_id devem ser enviados') app = App.query(App.token == token).get() user = User.get_by_id(user_id) if user_id != app.user_id: raise MSException(u'App token ou user_id invalido') if app and user and not app.deleted: self.app_data = { 'app': app.to_dict_json(), 'user': user.to_dict_json() } method(self, *args, **kwargs) ActivityLog.save(user_id=user_id, app_name=app.name,token=token, activity=activity) else: raise MSException(u'App token e o user_id invalido')
def sign_up(form): _validate_form(form) user_key = User.save(form) user = user_key.get() ActivityLog.save(user_id=user.key.id(), activity="SignUp") return user.to_dict_json()
def save_user_cookie(handler, user_id): handler.response.set_cookie('user_id', user_id, max_age=MAX_AGE) ActivityLog.save(user_id=user_id, activity="SignIn")
def delete_user_cookie(handler): handler.response.delete_cookie('user_id') if handler.request.cookies.get('user_id'): ActivityLog.save(user_id=handler.request.cookies.get('user_id'), activity="SignOut") del handler.request.cookies['user_id']
def save_activity(self, user_id, activity, app_id=None): ActivityLog.save(user_id=user_id, activity=activity, app_id=app_id)