Example #1
0
 def post(self):
     # Get info from json input
     info = request.json
     username = info['username']
     password = info['password']
     email = info['email']
     # input cannot be empty string
     if username == "" or password == "" or email == "":
         return {
             'message':
             'Register failed. Username, password or email cannot be empty'
         }, 401
     # username length restriction
     if len(username) < 4 or len(username) > 12:
         return {
             'message': 'The length of username should between 4 and 12.'
         }, 401
     # password length restriction
     if len(password) < 8 or len(password) > 32:
         return {
             'message': 'The length of password should between 8 and 32'
         }, 401
     # password symbol restriction
     if not (re.search('[a-z]', password) or re.search('[A-Z]', password)):
         return {
             'message': 'The password should contain at least one letter'
         }, 401
     try:
         success, errmsg = User.register_account(username, password, 0,
                                                 email)
         if not success:
             return {'message': errmsg}, 401
     except pymysql.Error as e:
         return {'message': e.args[1]}, 500
     return {'message': 'Register new user account successfully'}, 200
 def add_new_account(username, password, admin):
     return User.register_account(username, password, admin)