def test_add(self): m1 = Menu() m1.title = '艹' m1.name = '' session.add(m1) if session.commit(): print('success')
def post(self): # 注册功能 # 获取数据 face = self.get_argument('face_img') print(face) img = face.split(',')[-1] username = self.get_argument('username') realname = self.get_argument('realname') if face and username and realname: # 注册(用户模型) user = User() user.username = username user.realname = realname session.add(user) session.commit() # 调用百度人脸注册接口 res = face_register(img, user.id) if res: # 注册成功,跳转到登录 self.redirect('/login/') else: # 注册失败,则跳转到注册页面 session.delete(user) session.commit() self.redirect('/register/') else: error = '请填写完整的参数' self.render('register.html', error=error)
def post(self): username = self.get_argument('username') password = self.get_argument('passwd') # password = my_md5(password) # # if not re.match('^\w{6,20}$', username): # self.write("用户名不合法") # return # if not re.match('^\w{6,20}$', password): # self.write("密码不合法") # return # 判断用户是否存在 users = session.query(User).filter_by(username=username, password=password) if users.count() > 0: self.write("用户已注册") return # 添加用户 user = User() user.username = username user.password = password try: session.add(user) session.commit() except: session.rollback() session.flush() self.write('注册失败') else: self.redirect(self.reverse_url('login'))
def post(self, *args, **kwargs): # 获取数据 face = self.get_argument('face') username = self.get_argument('username') # 人脸注册 img = face.split(',')[-1] if not register_face_user(img, username): self.render('register.html', error='注册失败') user = User() user.username = username session.add(user) session.commit() self.write('注册成功')
def post(self): login_id = self.get_argument('login_id') pwd = self.get_argument('pwd') name = self.get_argument('name') admin = Admin() admin.name = name admin.login_id = login_id admin.password = hashlib.md5(pwd.encode('utf-8')).hexdigest() admin.purview = 0 admin.deleted = 0 session.add(admin) session.commit()
def post(self, *args, **kwargs): face = self.get_argument('face') username = self.get_argument('username') if not (face and username): self.render('register.html', error='注册信息请填写完整') user = session.query(User).filter(User.username == username).first() if user: self.render('register.html', error='该账号已被使用') img = face.split(',')[-1] if not register_face_user(img, username): self.render('register.html', error='注册失败') user = User() user.username = username session.add(user) session.commit() file = base64.b64decode(img) img_dir = os.path.join(IMAGE_DIR, username + '.jpg') with open(img_dir, 'wb') as f: f.write(file) self.write('注册成功')
def post(self): stu = Student() stu.s_name = '小米' session.add(stu) session.commit() self.write('添加数据成功')
def test_add(self): m1 = Menu() m1.title = '用户管理' session.add(m1) session.commit()