Beispiel #1
0
    def register(cls, data):

        hashed_pw = security.hash_password({"password": data['password']})
        data["password"] = hashed_pw
        result = user_svc.create_user(data)
        s_info = user_svc.get_by_email(data['email'])
        tok = security.generate_token(s_info)
        return result, tok
Beispiel #2
0
def t2():

    user = {
        "last_name": "Gamgee",
        "first_name": "Sam",
        "email": "*****@*****.**",
        "password": "******"
    }

    r = UserService.create_user(user)
    print("Result = ", r)
Beispiel #3
0
 def register(cls, data):
     hashed_pw = security.hash_password({"password" : data['password']})
     data["password"] = hashed_pw
     try:
         result = user_svc.create_user(data)
         logger.debug("CREATE RESULT: " + str(result))
         s_info = user_svc.get_by_email(data['email'])
         logger.debug("CREATE S_INFO: " + str(s_info))
         tok = security.generate_token(s_info)
         logger.debug("CREATE TOK: " + str(tok))
         return tok, s_info
     except Exception as e:
         logger.error("CREATE ERROR: " + str(e))
         return None
def register():
    last_name = request.args.get("last_name")
    first_name = request.args.get("first_name")
    email = request.args.get("email")
    password = request.args.get("password")

    valid = all([last_name, first_name, email, password])

    user_info = {
        "last_name": last_name,
        "first_name": first_name,
        "email": email,
        "password": password,
        "id": str(uuid4()),
        "status": "PENDING"
    }

    inputs = log_and_extract_input(
        register, {
            "last_name": last_name,
            "first_name": first_name,
            "email": email,
            "password": password
        })

    # http://127.0.0.1:5000/api/registrations?last_name=asd&first_name=dsa&email=fdsafdsgf&password=1123
    # If invalid argument
    if not valid:
        rsp = Response(
            "Some columns are empty. last_name, first_name, email, password are required",
            status=200,
            content_type="test/plain")
        return rsp

    user_data = UsersRDB.get_by_email(user_info["email"], include_deleted=True)
    if user_data:
        if user_data.get("status", None) != "PENDING":
            rsp = Response("User already exist",
                           status=400,
                           content_type="test/plain")
            return rsp
        else:
            notification.publish_it(email)
            rsp = Response("User " + user_data.get("id", "") +
                           " already exist, resent activation email.",
                           status=200,
                           content_type="test/plain")
            return rsp

    try:
        # result = UsersRDB.create_user(user_info)
        result = UserService.create_user(user_info)
        rsp = Response("User created, user ID is:" +
                       (result if result else "") +
                       " please verify your email",
                       status=200,
                       content_type="test/plain")
    except Exception as e:
        rsp = Response("Invalid argument",
                       status=400,
                       content_type="test/plain")
        logger.debug(str(e))
    return rsp