1
0
forked from ScoDoc/ScoDoc

CAS: config routes login/logout/validate

This commit is contained in:
Emmanuel Viennet 2023-03-02 23:29:25 +01:00
parent 3edf34dfee
commit 8c0c4139df
6 changed files with 61 additions and 4 deletions

View File

@ -85,6 +85,13 @@ def set_cas_configuration(app: flask.app.Flask = None):
if ScoDocSiteConfig.is_cas_enabled(): if ScoDocSiteConfig.is_cas_enabled():
current_app.logger.debug("CAS: set_cas_configuration") current_app.logger.debug("CAS: set_cas_configuration")
app.config["CAS_SERVER"] = ScoDocSiteConfig.get("cas_server") app.config["CAS_SERVER"] = ScoDocSiteConfig.get("cas_server")
app.config["CAS_LOGIN_ROUTE"] = ScoDocSiteConfig.get("cas_login_route", "/cas")
app.config["CAS_LOGOUT_ROUTE"] = ScoDocSiteConfig.get(
"cas_logout_route", "/cas/logout"
)
app.config["CAS_VALIDATE_ROUTE"] = ScoDocSiteConfig.get(
"cas_validate_route", "/cas/serviceValidate"
)
app.config["CAS_AFTER_LOGIN"] = "auth.after_cas_login" app.config["CAS_AFTER_LOGIN"] = "auth.after_cas_login"
app.config["CAS_AFTER_LOGOUT"] = "auth.after_cas_logout" app.config["CAS_AFTER_LOGOUT"] = "auth.after_cas_logout"
app.config["CAS_ERROR_CALLBACK"] = cas_error_callback app.config["CAS_ERROR_CALLBACK"] = cas_error_callback

View File

@ -45,6 +45,21 @@ class ConfigCASForm(FlaskForm):
label="URL du serveur CAS", label="URL du serveur CAS",
description="""url complète. Commence en général par <tt>https://</tt>.""", description="""url complète. Commence en général par <tt>https://</tt>.""",
) )
cas_login_route = StringField(
label="Route du login CAS",
description="""ajouté à l'URL du serveur: exemple <tt>/cas</tt> (si commence par <tt>/</tt>, part de la racine)""",
default="/cas",
)
cas_logout_route = StringField(
label="Route du logout CAS",
description="""ajouté à l'URL du serveur: exemple <tt>/cas/logout</tt>""",
default="/cas/logout",
)
cas_validate_route = StringField(
label="Route de validation CAS",
description="""ajouté à l'URL du serveur: exemple <tt>/cas/serviceValidate</tt>""",
default="/cas/serviceValidate",
)
cas_attribute_id = StringField( cas_attribute_id = StringField(
label="Attribut CAS utilisé comme id (laissez vide pour prendre l'id par défaut)", label="Attribut CAS utilisé comme id (laissez vide pour prendre l'id par défaut)",

View File

@ -90,6 +90,9 @@ class ScoDocSiteConfig(db.Model):
# CAS # CAS
"cas_enable": bool, "cas_enable": bool,
"cas_server": str, "cas_server": str,
"cas_login_route": str,
"cas_logout_route": str,
"cas_valmidate_route": str,
"cas_attribute_id": str, "cas_attribute_id": str,
} }
@ -237,10 +240,12 @@ class ScoDocSiteConfig(db.Model):
return False return False
@classmethod @classmethod
def get(cls, name: str) -> str: def get(cls, name: str, default: str = "") -> str:
"Get configuration param; empty string if unset" "Get configuration param; empty string or specified default if unset"
cfg = ScoDocSiteConfig.query.filter_by(name=name).first() cfg = ScoDocSiteConfig.query.filter_by(name=name).first()
return (cfg.value or "") if cfg else "" if cfg is None:
return default
return cfg.value or ""
@classmethod @classmethod
def set(cls, name: str, value: str) -> bool: def set(cls, name: str, value: str) -> bool:

View File

@ -150,6 +150,12 @@ def config_cas():
flash("CAS " + ("forcé" if form.data["cas_force"] else "non forcé")) flash("CAS " + ("forcé" if form.data["cas_force"] else "non forcé"))
if ScoDocSiteConfig.set("cas_server", form.data["cas_server"]): if ScoDocSiteConfig.set("cas_server", form.data["cas_server"]):
flash("Serveur CAS enregistré") flash("Serveur CAS enregistré")
if ScoDocSiteConfig.set("cas_login_route", form.data["cas_login_route"]):
flash("Serveur CAS enregistré")
if ScoDocSiteConfig.set("cas_logout_route", form.data["cas_logout_route"]):
flash("Serveur CAS enregistré")
if ScoDocSiteConfig.set("cas_validate_route", form.data["cas_validate_route"]):
flash("Serveur CAS enregistré")
if ScoDocSiteConfig.set("cas_attribute_id", form.data["cas_attribute_id"]): if ScoDocSiteConfig.set("cas_attribute_id", form.data["cas_attribute_id"]):
flash("Serveur CAS enregistré") flash("Serveur CAS enregistré")
if ScoDocSiteConfig.set("cas_ssl_verify", form.data["cas_ssl_verify"]): if ScoDocSiteConfig.set("cas_ssl_verify", form.data["cas_ssl_verify"]):

View File

@ -928,6 +928,31 @@ def partition_editor(formsemestre_id: int):
return "\n".join(H) return "\n".join(H)
# Future page pour répartition parcours
@bp.route("/students_groups_auto_assignment", methods=["GET", "POST"])
@scodoc
@permission_required(Permission.ScoView)
@scodoc7func
def students_groups_auto_assignment(formsemestre_id: int):
"""En cours de dev."""
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
H = [
html_sco_header.sco_header(
page_title=f"DEV",
),
f"""<h2>
</h2>
""",
render_template(
"scolar/students_groups_auto_assignment.j2",
formsemestre=formsemestre,
),
html_sco_header.sco_footer(),
]
return "\n".join(H)
@bp.route("/create_partition_parcours", methods=["GET", "POST"]) @bp.route("/create_partition_parcours", methods=["GET", "POST"])
@scodoc @scodoc
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)

View File

@ -49,7 +49,6 @@ def login():
_external=True, _external=True,
), ),
) )
if "ticket" in flask.request.args: if "ticket" in flask.request.args:
flask.session[cas_token_session_key] = flask.request.args["ticket"] flask.session[cas_token_session_key] = flask.request.args["ticket"]