Пример #1
0
class TestAdminLogin(unittest.TestCase):
    def setUp(self):
        self._db = Database(logger, True)

    def test_admin_login(self):
        result = self._db.login("admin", "test_password")
        self.assertIsNotNone(result)
        new_session_token = result[0]
        admin_user_id = result[1]
        admin_user = self._db.validate_session(new_session_token)
        self.assertEqual(admin_user.user_id, admin_user_id)
        self.assertEqual(admin_user.session_token, new_session_token)
        self.assertEqual(admin_user.email_address, "admin")
        self.assertEqual(admin_user.full_name, "Administrator")
Пример #2
0
def login():
    with current_app.app_context():
        environment = Environment(current_app)

    input_data = request.get_json(True)

    username = input_data["username"]
    password = input_data["password"]

    db = Database(logger=current_app.logger, env=environment)
    try:
        result = db.login(username, password)
        session_token = result[0]
        return json.dumps({
            "success": True,
            "session_token": session_token.decode('utf-8')
        })
    except DatabaseException:
        flash("Invalid e-mail/password combination.", category="error")
        return json.dumps({
            "success": False,
            "error_msg": "Invalid e-mail/password combination."
        })