Internal authentication process locked by a mutex.
()
| 101 | |
| 102 | |
| 103 | def _login(): |
| 104 | """ |
| 105 | Internal authentication process locked by a mutex. |
| 106 | """ |
| 107 | form = _security.forms.get('login_form').cls(request.form) |
| 108 | if OAUTH2 in config.AUTHENTICATION_SOURCES \ |
| 109 | and 'oauth2_button' in request.form: |
| 110 | # Sending empty form as oauth2 does not require form attribute |
| 111 | auth_obj = AuthSourceManager({}, copy.deepcopy( |
| 112 | config.AUTHENTICATION_SOURCES)) |
| 113 | # Persist only the OAuth2 provider selection across the redirect. |
| 114 | # The auth-source instance lives on current_app's registry so we |
| 115 | # re-look-up rather than persist a live class instance in session. |
| 116 | session['oauth2_current_client'] = request.form.get('oauth2_button') |
| 117 | else: |
| 118 | auth_obj = AuthSourceManager(form, copy.deepcopy( |
| 119 | config.AUTHENTICATION_SOURCES)) |
| 120 | |
| 121 | session['auth_source_manager'] = None |
| 122 | |
| 123 | username = form.data['email'] |
| 124 | user = User.query.filter_by(username=username, |
| 125 | auth_source=INTERNAL).first() |
| 126 | |
| 127 | if user: |
| 128 | if user.login_attempts >= config.MAX_LOGIN_ATTEMPTS > 0: |
| 129 | user.locked = True |
| 130 | else: |
| 131 | user.locked = False |
| 132 | db.session.commit() |
| 133 | |
| 134 | if user.login_attempts >= config.MAX_LOGIN_ATTEMPTS > 0: |
| 135 | flash(gettext('Your account is locked. Please contact the ' |
| 136 | 'Administrator.'), |
| 137 | MessageType.WARNING) |
| 138 | logout_user() |
| 139 | return redirect(pga_utils.get_safe_post_logout_redirect()) |
| 140 | |
| 141 | # Validate the user |
| 142 | if not auth_obj.validate(): |
| 143 | for field in form.errors: |
| 144 | flash_login_attempt_error = None |
| 145 | if user and field in config.LOGIN_ATTEMPT_FIELDS: |
| 146 | if config.MAX_LOGIN_ATTEMPTS > 0: |
| 147 | user.login_attempts += 1 |
| 148 | left_attempts = \ |
| 149 | config.MAX_LOGIN_ATTEMPTS - user.login_attempts |
| 150 | if left_attempts > 1: |
| 151 | flash_login_attempt_error = \ |
| 152 | gettext('{0} more attempts remaining.'. |
| 153 | format(left_attempts)) |
| 154 | else: |
| 155 | flash_login_attempt_error = \ |
| 156 | gettext('{0} more attempt remaining.'. |
| 157 | format(left_attempts)) |
| 158 | db.session.commit() |
| 159 | for error in form.errors[field]: |
| 160 | if flash_login_attempt_error: |
no test coverage detected