def post(self): # 从基本的请求解析器中复制请求参数说明 registParser = self.parser.copy() # 再添加注册时使用 registParser.add_argument('password', dest='pwd', required=True, help='密码不能为空') registParser.add_argument('email', required=True, help='邮箱不能为空!') registParser.add_argument('phone', required=True, help='手机号不能为空!') registParser.add_argument('nickname', required=True, help='昵称不能为空!') # 验证请求参数是否满足要求 args = registParser.parse_args() u = User() u.name = args.get('name') u.nickName = args.get('nickname') u.email = args.get('email') u.phone = args.get('phone') u.password = helper.md5_crypt(args.get('pwd')) if dao.save(u): helper.sendEmail(u) return {'status': 200, 'msg': '用户注册成功'} return {'status': 201, 'msg': '用户注册失败'}
def post(self): #从基本的请求解析器中复制请求参数说明 registParser=self.parser.copy() #再注册时使用 registParser.add_argument('password', required=True, help='密码不能为空', dest='pwd') registParser.add_argument('email', required=True, help='邮箱不能为空' ) registParser.add_argument('phone', required=True, help='电话不能为空' ) registParser.add_argument('nickname', required=True, help='昵称不能为空' ) registParser.add_argument('photo_1', type=FileStorage, location='files', required=True, help='必须提供一个photo' ) # 验证请求参数是满足要求 args=registParser.parse_args() u=User() u.name=args.get('name') u.nickname=args.get('nickname') u.phone=args.get('phone') u.email=args.get('email') u.password=helper.md5_crypt(args.get('pwd')) uFile: FileStorage = args.get('photo_1') print('上传的文件名:', uFile.filename) newFileName = str(uuid.uuid4()).replace('-', '') newFileName += '.' + uFile.filename.split('.')[-1] uFile.save(os.path.join(settings.MEDIA_DIR, newFileName)) if dao.save(u): helper.sendEmail(u) return {'status':200, 'msg':'上传成功,用户注册成功', 'path': '/static/uploads/{}'.format(newFileName)} return {'status':201, 'msg':'用户注册失败'}
def reactive(self): parser = reqparse.RequestParser() parser.add_argument('email', required=True, help='必须提供邮箱') args = parser.parse_args() email = args.get('email') qs = dao.query(User).filter(User.email.__eq__(email)) if not qs.count(): return {'status': 661, 'msg': '该邮箱未注册'} helper.sendEmail(qs.first()) return {'msg': '重写申请用户激活成功,请去邮箱查收'}
def reactive(self): # 重新申请用户激活 reactiveParser = self.parser.copy() reactiveParser.add_argument('email', required=True, help='必须提供邮箱') args = reactiveParser.parse_args() email = args.get('email') qs = dao.query(User).filter(User.email.__eq__(email)) if not qs.count(): return {'status': 700, 'msg': email + '邮箱未被注册'} # 重新发送邮箱 helper.sendEmail(qs.first()) return {'msg': '重新申请用户激活成功,注意查收邮箱进行激活'}