Exemplo n.º 1
0
def signup_user_oauth():
    username = g.user_info["sub"]
    email_address = g.user_info["email"]
    password = ''.join([
        random.choice(string.ascii_letters + string.digits) for n in range(32)
    ])  # received_form_response.get("password")
    organization = None  #received_form_response.get("organization")
    testing = False  # received_form_response.get("testing")

    if not (username and email_address):
        return error_response(
            message="Please make sure you have added values for all the fields"
        )

    if not is_email(email_address, check_dns=True):
        return error_response(message="Invalid email.")

    if testing:  # our pytest is hitting this API, so don't create the user
        return success_response()

    new_user = User(username=username,
                    password=password,
                    email_address=email_address,
                    organization=organization)
    user_uuid = new_user.insert_into_db(datastore.get_client())
    return new_user
Exemplo n.º 2
0
def login():
    """TODO: Fill in Documentation

    .. :quickref: UNDOCUMENTED;

    """
    received_form_response = json.loads(request.data.decode('utf-8'))

    username = received_form_response.get("username")
    password = received_form_response.get("password")

    if not (username and password):
        return error_response(
            message="Please make sure you have added values for all the fields"
        )

    user = User(username=username, password=password)
    user_uuid, is_admin = user.login_user(client=datastore_client)
    if user_uuid is None:
        return error_response(
            message="Login failed. Please check your credentials."
        )

    session_token = UserSession(user_uuid=user_uuid).insert_into_db(client=datastore_client)
    return success_response(
        user_uuid=user_uuid,
        user_token=session_token,
        is_admin=is_admin,
        message="Login Successful"
    )
def signup():
    received_form_response = json.loads(request.data.decode('utf-8'))
    username = received_form_response.get("username")
    email_address = received_form_response.get("email_address")
    password = received_form_response.get("password")
    organization = received_form_response.get("organization")

    if not (username and email_address and password):
        return error_response(
            message="Please make sure you have added values for all the fields"
        )

    if not is_email(email_address, check_dns=True):
        return error_response(message="Invalid email.")

    user_uuid = User(
        username=username,
        password=password,
        email_address=email_address,
        organization=organization).insert_into_db(datastore_client)

    if user_uuid:
        return success_response()

    else:
        return error_response(message="User creation failed.")
Exemplo n.º 4
0
def login():
    """Log a user into this API, returns a session token.

    .. :quickref: Authentication; Log in

    :reqheader Accept: application/json
    :<json string username: Users username (from the /api/signup API call)
    :<json string password: Users password (from the /api/signup API call)

    **Example response**:

        .. sourcecode:: json

          {
            "user_uuid": "Users UUID from the registration process",
            "user_token": "token string",
            "is_admin": False
            "message": "Login Successful"
            "response_code": 200
          }
    """
    received_form_response = json.loads(request.data.decode('utf-8'))

    username = received_form_response.get("username")
    password = received_form_response.get("password")

    if not (username and password):
        return error_response(
            message="Please make sure you have added values for all the fields"
        )

    user = User(username=username, password=password)
    user_uuid, is_admin = user.login_user(client=datastore.get_client())
    if user_uuid is None:
        return error_response(
            message="Login failed. Please check your credentials.")

    session_token = UserSession(user_uuid=user_uuid).insert_into_db(
        client=datastore.get_client())
    return success_response(user_uuid=user_uuid,
                            user_token=session_token,
                            is_admin=is_admin,
                            message="Login Successful")
Exemplo n.º 5
0
def signup():
    """Create a user account.

    .. :quickref: Authentication; Create account

    :reqheader Accept: application/json
    :<json string username: Users login name
    :<json string email_address: Users email address
    :<json string password: Users password
    :<json string organization: Users organization (self chosen)

    **Example response**:

        .. sourcecode:: json

          {
            "response_code": 200
          }
    """
    received_form_response = json.loads(request.data.decode('utf-8'))
    username = received_form_response.get("username")
    email_address = received_form_response.get("email_address")
    password = received_form_response.get("password")
    organization = received_form_response.get("organization")
    testing = received_form_response.get("testing")

    if not (username and email_address and password):
        return error_response(
            message="Please make sure you have added values for all the fields"
        )

    if not is_email(email_address, check_dns=True):
        return error_response(message="Invalid email.")

    if testing:  # our pytest is hitting this API, so don't create the user
        return success_response()

    user_uuid = User(username=username,
                     password=password,
                     email_address=email_address,
                     organization=organization).insert_into_db(
                         datastore.get_client())

    if user_uuid:
        return success_response()
    else:
        return error_response(message="User creation failed.")