def test_success(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     self.assertEqual(
         User.get("*****@*****.**").login("test_password"),
         jwt.encode({
             "user": "******"
         },
                    SUPER_SECRET_SECRET_KEY,
                    algorithm='HS256').decode())
def activate_user(token):  # noqa: E501
    """activate_user

    Confirm a registered user # noqa: E501

    :param token: Confirmation token previously e-mailed to the user
    :type token: str

    :rtype: None
    """
    User.confirm(token)
 def endpoint_wrapper(*args, **kwargs):
     try:
         header = connexion.request.headers['Authorization']
         User.authenticate(header)
     except KeyError:
         logger.info("Missing 'Authorization' header")
         raise AuthException("Missing 'Authorization' header")
     except AuthenticationFailure as e:
         logger.info("Unable to authenticate: {}".format(e))
         raise AuthException("Resource requires authentication")
     else:
         return func(*args, **kwargs)
def create_user(user):  # noqa: E501
    """create_user

    Register a new user # noqa: E501

    :param user: User to register
    :type user: dict | bytes

    :rtype: None
    """
    user = UserData.from_dict(connexion.request.get_json())  # noqa: E501

    try:
        User.create(user.email, user.password)
        logger.info("Successfully created user '{}'".format(user.email))
    except UserAlreadyExists:
        logger.info("User already exists: '{}'".format(user.email))
def login_user(user):  # noqa: E501
    """login_user

    A user logs in. # noqa: E501

    :param user: User to log in as
    :type user: dict | bytes

    :rtype: str
    """
    user = UserData.from_dict(connexion.request.get_json())  # noqa: E501

    try:
        return str(User.get(user.email).login(user.password))
    except (NoSuchUser, IncorrectPassword) as e:
        logger.info("Unable to log '{}' in: {}".format(user.email, e))
        return "Invalid login information", 403
 def test_unconfirmed(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(IncorrectPassword):
         User.get("*****@*****.**").login("bad_password")
 def test_wrong_password(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     with self.assertRaises(IncorrectPassword):
         User.get("*****@*****.**").login("bad_password")
 def test_no_user(self, *_):
     with self.assertRaises(NoSuchUser):
         User.get("*****@*****.**").login("bad_password")
 def test_invalid_token(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(IncorrectConfirmationToken):
         User.get("*****@*****.**").confirm("bad_token")
 def test_no_user(self, *_):
     with self.assertRaises(NoSuchUser):
         User.get("*****@*****.**").confirm("bad_token")
 def test_success(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     self.assertEqual(mock_db.DB["*****@*****.**"]['confirmed'], True)
 def test_duplicate_user(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(UserAlreadyExists):
         User.create("*****@*****.**", "test_password")
 def test_success(self, *_):
     User.create("*****@*****.**", "test_password")