|
4 | 4 | # --- BEGIN_HEADER ---
|
5 | 5 | #
|
6 | 6 | # account - account page with info and account management options
|
7 |
| -# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH |
| 7 | +# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH |
8 | 8 | #
|
9 | 9 | # This file is part of MiG.
|
10 | 10 | #
|
|
34 | 34 | import os
|
35 | 35 |
|
36 | 36 | from mig.shared import returnvalues
|
| 37 | +from mig.shared.accountreq import renew_account_access_template |
| 38 | +from mig.shared.defaults import csrf_field, user_home_label |
37 | 39 | from mig.shared.functional import validate_input_and_cert
|
38 |
| -from mig.shared.init import initialize_main_variables, find_entry |
39 |
| -from mig.shared.htmlgen import html_user_messages, man_base_html, man_base_js |
| 40 | +from mig.shared.handlers import get_csrf_limit, make_csrf_token |
| 41 | +from mig.shared.htmlgen import html_user_messages, man_base_js |
| 42 | +from mig.shared.httpsclient import detect_client_auth, find_auth_type_and_label |
| 43 | +from mig.shared.init import find_entry, initialize_main_variables |
40 | 44 | from mig.shared.useradm import get_full_user_map
|
41 | 45 |
|
42 | 46 | _account_field_order = [('full_name', 'Full Name'),
|
@@ -93,7 +97,7 @@ def html_tmpl(configuration, client_id, environ, title_entry):
|
93 | 97 | user_token += claim_dump
|
94 | 98 | fill_helpers = {'short_title': configuration.short_title,
|
95 | 99 | 'user_msg': user_msg, 'show_user_msg': show_user_msg,
|
96 |
| - 'user_account': user_account, |
| 100 | + 'home_label': user_home_label, 'user_account': user_account, |
97 | 101 | 'user_token': user_token}
|
98 | 102 |
|
99 | 103 | html = '''
|
@@ -129,7 +133,70 @@ def html_tmpl(configuration, client_id, environ, title_entry):
|
129 | 133 | </div>
|
130 | 134 | '''
|
131 | 135 |
|
132 |
| - # TODO: add account management actions |
| 136 | + # Account management like renew account access for local users |
| 137 | + # TODO: add change password and delete account support for all accounts? |
| 138 | + (auth_type_name, auth_flavor) = detect_client_auth(configuration, environ) |
| 139 | + (auth_type, auth_label) = find_auth_type_and_label(configuration, |
| 140 | + auth_type_name, |
| 141 | + auth_flavor) |
| 142 | + show_local = [i for i in configuration.site_login_methods |
| 143 | + if i.startswith('mig')] |
| 144 | + fill_helpers.update({'auth_type': auth_type, |
| 145 | + 'auth_type_name': auth_type_name, |
| 146 | + 'auth_flavor': auth_flavor, |
| 147 | + 'auth_label': auth_label}) |
| 148 | + html += ''' |
| 149 | + <div id="manage-container" class="row"> |
| 150 | + <div class="manage-page__header col-12"> |
| 151 | + <h2>Manage Account</h2> |
| 152 | + <p class="sub-title">Depending on your %(short_title)s account |
| 153 | + type you have access to one or more account management actions |
| 154 | + below. |
| 155 | + </p> |
| 156 | + </div> |
| 157 | + ''' % fill_helpers |
| 158 | + form_method = 'post' |
| 159 | + csrf_limit = get_csrf_limit(configuration) |
| 160 | + target_op = 'accountaction' |
| 161 | + csrf_token = make_csrf_token(configuration, form_method, target_op, |
| 162 | + client_id, csrf_limit) |
| 163 | + fill_helpers.update({'target_op': target_op, 'form_method': |
| 164 | + form_method, 'csrf_field': csrf_field, |
| 165 | + 'csrf_token': csrf_token}) |
| 166 | + # TODO: extend renew to active ext accounts? |
| 167 | + if auth_type in show_local and user_dict.get('status', 'active') == 'temporal': |
| 168 | + fill_helpers['account_action'] = "RENEW_ACCESS" |
| 169 | + fill_helpers['peer_acceptance_notice'] = "" |
| 170 | + if configuration.site_peers_mandatory: |
| 171 | + peers_full_name = user_dict.get("peers_full_name", "") |
| 172 | + peers_email = user_dict.get("peers_email", "") |
| 173 | + peers_list = user_dict.get("peers", []) |
| 174 | + if peers_list or (peers_full_name and peers_email): |
| 175 | + fill_helpers['peer_acceptance_notice'] = """ |
| 176 | +Apparently %(peers_full_name)s <%(peers_email)s> accepted you as a peer |
| 177 | +and if that peer appointment has not yet ended you can renew your access here |
| 178 | +without further operator or peer contact involvement. Otherwise you may need to |
| 179 | +obtain or await explicit extension or peer assignment from someone else before |
| 180 | +your access renewal can proceed. |
| 181 | + """ % user_dict |
| 182 | + else: |
| 183 | + fill_helpers['peer_acceptance_notice'] = """ |
| 184 | +It looks like you may need someone with authority to appoint you as their peer |
| 185 | +before your access renewal can be accepted. |
| 186 | + """ |
| 187 | + fill_helpers['renew_helper'] = renew_account_access_template( |
| 188 | + configuration, default_values=fill_helpers) % fill_helpers |
| 189 | + html += ''' |
| 190 | + <div class="renew-account-access__header col-12"> |
| 191 | + <h3>Renew Account Access</h3> |
| 192 | + %(renew_helper)s |
| 193 | + </div> |
| 194 | + ''' % fill_helpers |
| 195 | + |
| 196 | + html += ''' |
| 197 | + <div class="col-lg-12 vertical-spacer"></div> |
| 198 | + </div> |
| 199 | + ''' |
133 | 200 |
|
134 | 201 | return html
|
135 | 202 |
|
|
0 commit comments