Exemplo n.º 1
0
def user(db_init, app, request):
    if request is None:
        u = None
    else:
        u = User.create(email=str(uuid.uuid4()) + '@test.com', password='******', first='first',
                        last='last', role=str(request), organization="USGS")

    def tearDown():
        if u is not None:
            db.session.delete(u)
            db.session.commit()

    return u
Exemplo n.º 2
0
def register():
    data = request.json
    # create user with the data,
    # all stormpath exceptions will be caught and passed on in standardized format
    user = User.create(**data)

    # if requires confirmation
    if current_app.config['AUTH_REQUIRE_CONFIRMATION']:
        token = generate_token(
            (user.email, user.custom_data['email_verification_token']),
            current_app.config['SECRET_KEY'])
        # Send Email #
        link = 'https://croplands.org/app/a/confirm?t=' + token
        send_confirmation_email(link, user.email)
        return JSONResponse(status_code=201, description='User created')

    # else just return token
    response_data = {'token': make_jwt(user)}
    return JSONResponse(status_code=201,
                        description='User created',
                        data=response_data)
Exemplo n.º 3
0
    def test_user_email_case_insensitivity(self):
        """
        Emails are by nature case insensitive. This test checks that
        the user model correctly handles this specification.
        :return:
        """
        with self.app.app_context():
            data = {
                'email': '*****@*****.**',
                'password': '******',
                'first': 'First',
                'last': 'Last'
            }
            user = User(**data)
            assert (user.email.islower())

            user = User.create(**data)
            assert (user.email.islower())

            user = User.from_email(data['email'])
            self.assertIsNotNone(user)

            user = User.from_login(data['email'], data['password'])
            self.assertIsNotNone(user)