Exemplo n.º 1
0
def register(request):
    name = request.params['name']
    mail = request.params['mail']
    password = request.params['password']
    print password
    m = hashlib.md5()
    m.update(password)
    passwordStr = m.hexdigest()
    user_db = User()
    user_db.add_user(name, passwordStr, mail, ['user'])
    return {'status': 'ok'}
Exemplo n.º 2
0
def add_user(form):
    users = UserModel()

    if not assert_keys_in_form_exist(
            form, ['name', 'email', 'phone', 'password', 'major', 'degree']):
        return msg.error_msg("Please check your requests.")

    name = form['name']
    email = form['email']
    phone = form['phone']
    password = form['password']
    major = form['major']
    degree = form['degree']

    if name.strip() == "":
        return msg.error_msg("Username cannot be empty.")

    if password.strip() == "":
        return msg.error_msg("Password cannot be empty.")

    if len(password) < 6:
        return msg.error_msg("Password cannot less than 6 character.")

    if len(name) > 255:
        return msg.error_msg("Username cannot exceed 255 characters.")

    if len(password) > 255:
        return msg.error_msg("Password cannot exceed 255 characters.")

    findUser = users.get_user(email=email, enable=True)

    if findUser is None:
        return msg.error_msg("Failed to find user.")

    print('findUser', findUser)
    print(len(findUser))
    if len(findUser) != 0:
        return msg.error_msg("User already exists. (Email already in use)")

    args = {
        "Name": name,
        "Email": email,
        "Phone": phone,
        "Password": encrypt(password),
        "Major": major,
        "Degree": degree,
        "Enable": True
    }
    res = users.add_user(args)
    if res is None:
        return msg.error_msg("Failed to add user.")

    return msg.success_msg({"msg": "User added successfully."})
Exemplo n.º 3
0
def add_user(form):

    if not assert_keys_in_form_exist(form, ['name', 'email', 'phone', 'password']):
        return msg.error_msg("Invalid request.")

    name = form['name']
    email = form['email']
    phone = form['phone']
    password = form['password']

    if password.strip() == "":
        return msg.error_msg("Password cannot be empty.")

    if len(name) > 255:
        return msg.error_msg("Username cannot exceed 255 characters.")

    if len(password) > 255:
        return msg.error_msg("Password cannot exceed 255 characters.")

    findUser = User.get_user(email=email, enable=True)
    if findUser is None:
        return msg.error_msg("Failed to find user.")

    if len(findUser) != 0:
        return msg.error_msg("User already exists.")

    args = {
        "Name": name,
        "Email": email,
        "Phone": phone,
        "Password": encrypt(password),
        "Enable": True
    }
    res = User.add_user(args)
    if res is None:
        return msg.error_msg("Failed to add user.")

    return msg.success_msg({"msg": "User added successfully."})