Newer
Older
return render(request, "user-profile-form.html", {
"is_inst_id_locked": is_inst_id_locked(request.user),
"enable_inst_id_if_not_locked": (
request.GET.get("first_login")
or (request.GET.get("set_inst_id")
and request.GET["referer"])
),
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
# {{{ manage auth token
class AuthenticationTokenForm(StyledForm):
def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
super(AuthenticationTokenForm, self).__init__(*args, **kwargs)
self.helper.add_input(Submit("reset", _("Reset")))
def manage_authentication_token(request):
# type: (http.HttpRequest) -> http.HttpResponse
if not request.user.is_authenticated:
raise PermissionDenied()
if request.method == 'POST':
form = AuthenticationTokenForm(request.POST)
if form.is_valid():
token = make_sign_in_key(request.user)
from django.contrib.auth.hashers import make_password
request.user.git_auth_token_hash = make_password(token)
request.user.save()
messages.add_message(request, messages.SUCCESS,
_("A new authentication token has been set: %s.")
% token)
else:
if request.user.git_auth_token_hash is not None:
messages.add_message(request, messages.INFO,
_("An authentication token has previously been set."))
else:
messages.add_message(request, messages.INFO,
_("No authentication token has previously been set."))
form = AuthenticationTokenForm()
return render(request, "generic-form.html", {
"form_description": _("Manage Git Authentication Token"),
"form": form
})
# }}}
# {{{ SAML auth backend
# This ticks the 'verified' boxes once we've receive attribute assertions
# through SAML2.
class Saml2Backend(Saml2BackendBase):
def _set_attribute(self, obj, attr, value):
mod = super(Saml2Backend, self)._set_attribute(obj, attr, value)
if attr == "institutional_id":
if not obj.institutional_id_verified:
obj.institutional_id_verified = True
mod = True
if attr in ["first_name", "last_name"]:
if not obj.name_verified:
obj.name_verified = True
mod = True
if attr == "email":
from course.constants import user_status
if obj.status != user_status.active:
obj.status = user_status.active
mod = True
return mod
# }}}
Dong Zhuang
committed
def sign_out_confirmation(request, redirect_field_name=REDIRECT_FIELD_NAME):
redirect_to = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name, ''))
next_uri = ""
if redirect_to:
next_uri = "?%s=%s" % (redirect_field_name, redirect_to)
return render(request, "sign-out-confirmation.html",
{"next_uri": next_uri})
Dong Zhuang
committed
def sign_out(request, redirect_field_name=REDIRECT_FIELD_NAME):
Dong Zhuang
committed
redirect_to = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name, ''))
if settings.RELATE_SIGN_IN_BY_SAML2_ENABLED:
from djangosaml2.views import _get_subject_id, logout as saml2_logout
if _get_subject_id(request.session) is not None:
response = saml2_logout(request)
auth_logout(request)
Dong Zhuang
committed
elif redirect_to:
return redirect(redirect_to)