Coverage for superuser/model.py: 95%
22 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 14:02 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 14:02 +0000
1"""This module contains the Superuser class that is responsible for handling"""
3from flask import session, jsonify
5from core import handlers, shared
8class Superuser:
9 """A class used to represent a Superuser and handle superuser-related"""
11 def login(self, attempt_user):
12 """Validates user credentials and returns a JSON response indicating
13 invalid login credentials."""
14 if not attempt_user:
15 return jsonify({"error": "Missing email or password"}), 400
17 if "email" not in attempt_user or "password" not in attempt_user:
18 return jsonify({"error": "Missing email or password"}), 400
20 if attempt_user["email"] == shared.getenv("SUPERUSER_EMAIL") and attempt_user[
21 "password"
22 ] == shared.getenv("SUPERUSER_PASSWORD"):
23 session["user"] = {"email": attempt_user["email"]}
24 session["superuser"] = True
25 return jsonify({"message": "/user/search"}), 200
27 handlers.clear_session_save_theme()
29 return jsonify({"error": "Invalid login credentials"}), 401
31 def configure_settings(self, max_skills, min_num_ranking_student_to_opportunity):
32 """Configures the settings for the superuser."""
33 from app import CONFIG_MANAGER
35 try:
36 CONFIG_MANAGER.set_num_of_skills(max_skills)
37 CONFIG_MANAGER.set_min_num_ranking_student_to_opportunities(
38 min_num_ranking_student_to_opportunity
39 )
40 return jsonify({"message": "Settings updated successfully"}), 200
41 except Exception as e:
42 return jsonify({"error": str(e)}), 500