MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / _login

Function _login

web/pgadmin/authenticate/__init__.py:103–203  ·  view source on GitHub ↗

Internal authentication process locked by a mutex.

()

Source from the content-addressed store, hash-verified

101
102
103def _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:

Callers 1

loginFunction · 0.85

Calls 9

validateMethod · 0.95
authenticateMethod · 0.95
loginMethod · 0.95
as_dictMethod · 0.95
AuthSourceManagerClass · 0.85
gettextFunction · 0.85
popMethod · 0.80
firstMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected