def post(self) -> jsonify: """ 注册 post请求 :return: jsonify """ parse = MyParse() parse.add(name="account", required=True) parse.add(name="name", required=True) parse.add(name="password", required=True) parse.add(name="departmentId", type=int, required=False) parse.add(name="admin", type=bool, required=False, default=False) parse.add(name="gender", type=bool, required=False, default=True) parse.add(name="email", required=False) parse.add(name="phone", required=False) departmentId = parse.parse_args().get("departmentId") account = parse.parse_args().get("account") name = parse.parse_args().get("name") password = parse.parse_args().get("password") admin = parse.parse_args().get("admin") gender = parse.parse_args().get('gender') email = parse.parse_args().get("email") phone = parse.parse_args().get("phone") if departmentId: # departmentId验证 Department.get(departmentId, 'departmentId') # name 验证 User.verify_account(account.lower()) u = User(account=account, name=name, password=password, gender=gender, department=departmentId, admin=admin, email=email, phone=phone) u.save() return jsonify(myResponse(ResponseCode.SUCCESS, u.id, ResponseError.OK))
def register(request): ctx = {} if request.method == 'POST': username = request.POST.get("username", "") mobile = request.POST.get("mobile", "") password = request.POST.get("password", "") email = request.POST.get("email", "") if username == "": ctx['code'] = 1 ctx['msg'] = "username is no null" elif password == "": ctx['code'] = 1 ctx['msg'] = "password is no null" elif mobile == "": ctx['code'] = 1 ctx['msg'] = "mobile is no null" elif len(mobile) != 11: ctx['code'] = 1 ctx['msg'] = "mobile's length is must achieve 11" elif email == "": ctx['code'] = 1 ctx['msg'] = "email is no null" else: user_list = User.objects.filter(username=username, mobile=mobile) if len(user_list) > 0: ctx['code'] = 1 ctx['msg'] = "current user is exist" else: user = User(username=username, mobile=mobile, password=password, email=email) user.save() ctx['code'] = 0 ctx['msg'] = "register success" return return_json(ctx)
def build(): user = User(name='admin') user.password = generate_password_hash(password='******') user.save() print "Default Admin add Success!" execute(deploy)