def initialize_firebase_app():
        if CURRENT_ENV == DEV_ENV:
            return pyrebase.initialize_app(credentials.dev_credentials)
        elif CURRENT_ENV == PROD_ENV:
            return pyrebase.initialize_app(credentials.prod_credentials)
        else:
            logger.error("Current env is not set.")

        FirebaseManager.get_instance()
Beispiel #2
0
 def __init__(self, request):
     super().__init__(request)
     self.template_path = 'quiz/index.html'  # index.html'
     self.db = FirebaseManager.get_instance()
     self.user = FirebaseAuth.get_instance().initialize_user_auth_details(
         request.session.get('id_token'))
     self.user_id = self.user['localId']
 def __init__(self, request, mock_id, quiz_id):
     super().__init__(request)
     self.template_path = 'quiz/quiz_results.html'
     self.db = FirebaseManager.get_instance()
     self.user = FirebaseAuth.get_instance().initialize_user_auth_details(request.session.get('id_token'))
     self.quiz_id = quiz_id
     self.mock_id = mock_id
     self.user_id = self.user['localId']
    def __init__(self, request, mock_test_id, mock_test_question_id):
        super().__init__(request)
        self.mock_id = mock_test_id
        self.question_id = mock_test_question_id
        self.template_path = 'admin/edit_mock_question.html'
        self.db = FirebaseManager.get_instance()

        self.context['mock_id'] = mock_test_id
        self.context['question_id'] = mock_test_question_id
 def is_authenticated_and_email_verified(self, id_token):
     is_auth = FirebaseManager.get_instance().is_authenticated(id_token)
     if is_auth:
         self.user = self.initialize_user_auth_details(id_token)
         if not self.user['emailVerified']:
             logger.warning(
                 f"Email not verified for user ${self.user.email}")
             self.auth.send_email_verification(id_token)
         return self.user['emailVerified']
 def is_authenticated(self, id_token):
     if id_token:
         try:
             is_auth = FirebaseManager.get_instance().is_authenticated(
                 id_token)
             return is_auth and self.auth.get_account_info(
                 id_token)['users'][0]['emailVerified']
         except Exception as e:
             logger.error(e)
             return False
Beispiel #7
0
 def __init__(self, request):
     super().__init__(request)
     self.template_path = 'quiz/mock_quiz.html'
     self.mock_id = request.session.get('mock_id')
     self.db = FirebaseManager.get_instance()
     self.user = FirebaseAuth.get_instance().initialize_user_auth_details(
         request.session.get('id_token'))
     self.user_id = self.user['localId']
     self.start_time = utils.timestamp_to_datetime(
         request.session.get('start_time', 0))
     self.current_question_number = request.session.get(
         'current_question_number', 1)
     self.time_limit = float(request.session.get('time_limit', 60))
     self.num_questions = request.session.get('num_questions')
     self.quiz_state_id = request.session.get('quiz_state_id')
     self.questions = request.session.get('questions')
     if self.quiz_state_id is None:
         self.clear_session_quiz_data()
Beispiel #8
0
 def __init__(self, request):
     super().__init__(request)
     self.template_path = 'admin/admin_home.html'
     self.db = FirebaseManager.get_instance()
Beispiel #9
0
class Handler:
    class Decorators:
        @classmethod
        def auth_required(cls, function):
            def inner(self, *args):
                if not self.player.id:
                    return 'User not authenticated'
                return function(self, *args)

            return inner

        @classmethod
        def validate_quiz_type(cls, function):
            def inner(self, quiz_type, *args):
                if not QuestionManager.get_class(quiz_type):
                    return 'Quiz type invalid.'
                return function(self, quiz_type, *args)

            return inner

        @classmethod
        def validate_quiz_id(cls, function):
            def inner(self, quiz_type, quiz_id, *args):
                # TODO: Validate quiz id
                return function(self, quiz_type, quiz_id, *args)

            return inner

    def __init__(self, id_token=None):
        self.database_manager = FirebaseManager()
        self.player = Player()
        self.player.init_details(self.database_manager, id_token=id_token)

    @Decorators.auth_required
    @Decorators.validate_quiz_type
    def ask(self, quiz_type, quiz_id):
        return self.get_quiz(quiz_type, quiz_id).ask()

    @Decorators.auth_required
    @Decorators.validate_quiz_type
    def ask_next(self, quiz_type, quiz_id):
        return self.get_quiz(quiz_type, quiz_id).ask_next()

    @Decorators.auth_required
    @Decorators.validate_quiz_type
    @Decorators.validate_quiz_id
    def is_complete(self, quiz_type, quiz_id):
        return self.get_quiz(quiz_type, quiz_id).is_complete()

    @Decorators.auth_required
    @Decorators.validate_quiz_type
    @Decorators.validate_quiz_id
    def answer(self, quiz_type, quiz_id, choice_id):
        return self.get_quiz(quiz_type, quiz_id).answer(choice_id)

    def get_quiz(self, quiz_type, quiz_id):
        quiz = Quiz(
            player=self.player,
            quiz_id=quiz_id if quiz_id else self.database_manager.create_quiz(
                self.player.id, quiz_type),
            quiz_type=quiz_type,
            database_manager=self.database_manager)
        return quiz
Beispiel #10
0
 def __init__(self, id_token=None):
     self.database_manager = FirebaseManager()
     self.player = Player()
     self.player.init_details(self.database_manager, id_token=id_token)