コード例 #1
0
 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())
コード例 #2
0
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)
コード例 #3
0
 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)
コード例 #4
0
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))
コード例 #5
0
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
コード例 #6
0
 def test_unconfirmed(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(IncorrectPassword):
         User.get("*****@*****.**").login("bad_password")
コード例 #7
0
 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")
コード例 #8
0
 def test_no_user(self, *_):
     with self.assertRaises(NoSuchUser):
         User.get("*****@*****.**").login("bad_password")
コード例 #9
0
 def test_invalid_token(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(IncorrectConfirmationToken):
         User.get("*****@*****.**").confirm("bad_token")
コード例 #10
0
 def test_no_user(self, *_):
     with self.assertRaises(NoSuchUser):
         User.get("*****@*****.**").confirm("bad_token")
コード例 #11
0
 def test_success(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     self.assertEqual(mock_db.DB["*****@*****.**"]['confirmed'], True)
コード例 #12
0
 def test_duplicate_user(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(UserAlreadyExists):
         User.create("*****@*****.**", "test_password")
コード例 #13
0
 def test_success(self, *_):
     User.create("*****@*****.**", "test_password")