示例#1
0
 def test_normal_user_schema(self):
     try:
         user_schema({
             'username': '******',
             'password': '******',
             'email': '*****@*****.**'
         })
     except Invalid as e:
         logging.error(e)
         self.assertTrue(False)
示例#2
0
 def test_long_email_schema(self):
     try:
         user_schema({
             'username': '******',
             'password': '******',
             'email': '*****@*****.**'
         })
         self.assertTrue(False)
     except Invalid as e:
         assert len(e.path) == 1
         assert e.path[0] == "email"
示例#3
0
 def test_short_password_schema(self):
     try:
         user_schema({
             'username': '******',
             'password': '******',
             'email': '*****@*****.**'
         })
         self.assertTrue(False)
     except Invalid as e:
         assert len(e.path) == 1
         assert e.path[0] == "password"
示例#4
0
文件: user.py 项目: suqi/mdpress
def register_user():
    data = json.loads(request.data)
    username = data.get('username')
    password = data.get('password')
    email = data.get('email')

    user = user_schema({
        'username': username,
        'password': password,
        'email': email
    })

    email_user = Models.User.objects.filter(email=user.get('email')).first()
    name_user = Models.User.objects.filter(
        username=user.get('username')).first()
    if email_user or name_user:
        resp = {'data': {}, 'msg': 'user exists', 'code': 1001, 'extra': {}}
    else:
        id = generator_user_id()
        user = Models.User(email=user.get('email'),
                           id=id,
                           username=user.get('username'),
                           password=user.get('password'),
                           role=1)
        status = user.is_valid()
        if status:
            user.save()
            resp = {
                'data': user.to_json(),
                'msg': 'register success',
                'code': 1000,
                'extra': {}
            }
        else:
            resp = {'data': {}, 'msg': user.errors, 'code': 1001, 'extra': {}}

    return jsonify(**resp)