def register(): # application/json方式传递 # data = request.json # form = ClientForm(data=data) # form-data方式传递 data = request.form form = RegisterForm(formdata=data) # if form.validate(): # User.create_user(form.account.data,form.secret.data) # return jsonify({ # 'code': '000', # 'msg': '注册成功', # "success": True # }) # else: # return jsonify({ # 'code': '001', # 'msg': '注册方式错误', # "success": False # }) if form.validate_for_api(): User.create_user(form.account.data, form.secret.data) return jsonify({ 'code': '000', 'msg': '注册成功', "success": True })
def register(): register_form = _RegisterForm() if not register_form.validate(): raise ParameterException(unique_data=register_form.errors) name = register_form.name.data password = register_form.password.data user = User.create_user(name, password) if User.get_user(identifier=name): raise ConflictExeception(toast="用户已经存在") user.save(commit=True) payload: Dict[str, Any] = {} payload = user.get_info() return response_success(body=payload)
def create(): data = request.get_data() print data jobj = json.loads(data) schoolid = jobj['schoolid'] password = jobj['password'] print(schoolid, password) existed_user = User.find_user_by_schoolid(schoolid) if existed_user: # test cookie cookies = request.cookies print cookies response = make_response( jsonify({ "status": "200", "error": "1", "message": "学号已经注册过" })) response.set_cookie("hey", "hahahahahah") return response # #return jsonify({"status": "200", "error": "1", "message": "学号已经注册过"}) else: user = User() user.schoolid = schoolid user.password = password localtime = time.localtime(time.time()) year = time.strftime("%Y", localtime) user.sessionno = year result = User.create_user(user) if result == 1: return jsonify({ "status": "200", "error": "0", "message": "注册成功,现在可以登录了", }) else: return jsonify({ "status": "200", "error": "1", "message": "未知错误", })