def _create_user(self): if User.by_name(self.get_argument('name','')): raise AuthError('Name is registered') if self.get_argument('password1','') != self.get_argument('password2',''): raise AuthError('Password error') user = User() user.username = self.get_argument('name','') user.password = self.get_argument('password1','') session.add(user) session.commit()
def _create_user(self): if User.by_name(self.get_argument('name', '')): raise AuthError('用户名已经被注册!') if self.get_argument('password1', '') != self.get_argument( 'password2', ''): raise AuthError('两次输入的密码不一致!') user = User() user.username = self.get_argument('name', '') user.password = self.get_argument('password1', '') session.add(user) session.commit()
def post(self): username = User.by_name(self.get_argument('name', '')) pwd = self.get_argument('password', '') if username and username[0].password == pwd: self.render('08sqlalchemy.html', username=username[0].username) else: self.render('08login.html', error='登录失败!')
def post(self): get_username = self.get_argument('name', '') del_username = User.by_name(get_username) pwd = self.get_argument('password', '') if del_username and del_username[0].password == pwd: row = session.query(User).filter_by(username=get_username)[0] session.delete(row) session.commit() self.write(u'---%s:销户成功---' % get_username) else: self.render('08cancellation.html', error='销户失败,请重新输入!')
def post(self): nextname = self.get_argument('next', '') username = self.get_argument('name', '') username = User.by_name(username) passwd = self.get_argument('password', '') print(username) if username and username[0].password == passwd: # self.set_secure_cookie('ID',username[0].username,max_age=100) self.session.set('user', username[0].username) self.redirect(nextname) else: self.render('10authenticated.html', nextname=nextname)
def post(self): username = self.get_argument('name','') username = User.by_name(username) passwd = self.get_argument('password', '') print(username) if username and username[0].password == passwd: self.set_secure_cookie('ID',username[0].username,max_age=100) self.write('登录成功---post') time.sleep(3) self.redirect('/index') else: self.render('09login.html')
def post(self): next_name = self.get_argument('next', '') username = User.by_name(self.get_argument('name', '')) pwd = self.get_argument('password', '') if username and username[0].password == pwd: # self.set_secure_cookie(name='ID', value=username[0].username, max_age=120) self.session.set('user', username[0].username) time.sleep(1) if next_name: self.redirect(next_name) else: self.redirect('/index') else: self.render('10auth.html', error='登录失败...请重新登录!', next_name=next_name)
def get(self): time.sleep(10) id = self.get_argument('id', 13) user1 = User.by_id(id) user = {'username': user1[0].username, 'userid': user1[0].id} self.write(user)