def create_model(self, *args): params = self.decode(self.request.body) if self.current_user: user = User.objects(email=self.current_user).first() params['user'] = user obj = self.model(**params) obj.save() return obj
def post(self): errors = [] email = self.get_argument('email', None) #未输入邮箱地址 if not email: errors.append('reqired field email.') user = User.objects(email=email) if user: errors.append('email already.') if errors: self.redirect(self.get_sigup_url(), errors) return user = User(email=email, password=make_password(), name=email) user.save() self.set_secure_cookie('email', email) self.redirect('/')
def post(self): errors = [] email = self.get_argument('email', None) password = self.get_argument('password', None) if not email: errors.append('email reqired') if not password: errors.append('password required') user = User.objects(email=email, password=password).first() if user: self.set_secure_cookie('email', email) self.redirect('/') else: self.redirect(self.get_login_url(), errors)
def get_collection(self, *args, **kwargs): params = {} if self.current_user: user = User.objects(email=self.current_user).first() params['user'] = user return self.model.objects(**params)