def _validate_form(form): more_info = {} _fieldsRequireds = [ 'userId', 'confirmPassword', 'password', 'email', 'birth', 'name' ] for field in _fieldsRequireds: if not form.get(field): more_info[field] = u'Campo obrigatório' if form.get('password') and form.get('confirmPassword') and form.get( 'password') != form.get('confirmPassword'): more_info['password'] = '******' if form.get('userId') and User.get_by_id(form.get('userId')): more_info['userId'] = u'O id ja existe' if form.get('email') and not re.match(r"[^@]+@[^@]+\.[^@]+", form.get('email')): more_info['email'] = u'Email inválido' if form.get('birth'): form['birth'] = form['birth'].split('T')[0] form['birth'] = datetime.strptime(form['birth'], "%Y-%m-%d").date() if more_info: raise MSException(u'A campos com informações inválidas', more_info=more_info)
def sign_in(handler, user_id, password): is_authenticate = User.authenticate(user_id, password) if not is_authenticate: raise MSException(u'Username ou senha incorreto!', more_info={'type': 'authentication'}) cookie.save_user_cookie(handler, user_id)
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 _validate_form(form): more_info = {} _fieldsRequireds = ['userId', 'confirmPassword', 'password', 'email', 'birth', 'name'] for field in _fieldsRequireds: if not form.get(field): more_info[field] = u'Campo obrigatório' if form.get('password') and form.get('confirmPassword') and form.get('password') != form.get('confirmPassword'): more_info['password'] = '******' if form.get('userId') and User.get_by_id(form.get('userId')): more_info['userId'] = u'O id ja existe' if form.get('email') and not re.match(r"[^@]+@[^@]+\.[^@]+", form.get('email')): more_info['email'] = u'Email inválido' if form.get('birth'): form['birth'] = form['birth'].split('T')[0] form['birth'] = datetime.strptime(form['birth'], "%Y-%m-%d").date() if more_info: raise MSException(u'A campos com informações inválidas', more_info=more_info)
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 get_logged_user(self): user_id = self.request.cookies.get('user_id') if user_id: user = User.get_by_id(user_id) return user