Change common_login to take in a user uuid, instead of a user DB object
This commit is contained in:
parent
7736de24fe
commit
aecec02b6c
7 changed files with 25 additions and 26 deletions
|
@ -882,7 +882,7 @@ class LoginWrappedDBUser(UserMixin):
|
|||
|
||||
@property
|
||||
def is_active(self):
|
||||
return self.db_user().verified
|
||||
return self.db_user() and self.db_user().verified
|
||||
|
||||
def get_id(self):
|
||||
return unicode(self._uuid)
|
||||
|
|
|
@ -401,7 +401,7 @@ class SuperUserCreateInitialSuperUser(ApiResource):
|
|||
superusers.register_superuser(username)
|
||||
|
||||
# Conduct login with that user.
|
||||
common_login(superuser)
|
||||
common_login(superuser.uuid)
|
||||
|
||||
return {
|
||||
'status': True
|
||||
|
|
|
@ -317,7 +317,7 @@ class User(ApiResource):
|
|||
model.user.change_password(user, user_data['password'])
|
||||
|
||||
# Login again to reset their session cookie.
|
||||
common_login(user)
|
||||
common_login(user.uuid)
|
||||
|
||||
if features.MAILING:
|
||||
send_password_changed(user.username, user.email)
|
||||
|
@ -436,7 +436,7 @@ class User(ApiResource):
|
|||
'awaiting_verification': True
|
||||
}
|
||||
else:
|
||||
common_login(new_user)
|
||||
common_login(new_user.uuid)
|
||||
return user_view(new_user)
|
||||
except model.user.DataModelException as ex:
|
||||
raise request_error(exception=ex)
|
||||
|
@ -528,7 +528,7 @@ def conduct_signin(username_or_email, password, invite_code=None):
|
|||
if invite_code:
|
||||
handle_invite_code(invite_code, found_user)
|
||||
|
||||
if common_login(found_user):
|
||||
if common_login(found_user.uuid):
|
||||
return {'success': True}
|
||||
else:
|
||||
needs_email_verification = True
|
||||
|
@ -688,7 +688,7 @@ class VerifyUser(ApiResource):
|
|||
'invalidCredentials': True,
|
||||
}, 403
|
||||
|
||||
common_login(result)
|
||||
common_login(result.uuid)
|
||||
return {'success': True}
|
||||
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ from _init import __version__
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def common_login(db_user, permanent_session=True):
|
||||
def common_login(user_uuid, permanent_session=True):
|
||||
""" Performs login of the given user, with optional non-permanence on the session. """
|
||||
if login_user(LoginWrappedDBUser(db_user.uuid, db_user)):
|
||||
logger.debug('Successfully signed in as: %s (%s)' % (db_user.username, db_user.uuid))
|
||||
new_identity = QuayDeferredPermissionUser.for_user(db_user)
|
||||
if login_user(LoginWrappedDBUser(user_uuid)):
|
||||
logger.debug('Successfully signed in as user with uuid %s', user_uuid)
|
||||
new_identity = QuayDeferredPermissionUser.for_id(user_uuid)
|
||||
identity_changed.send(app, identity=new_identity)
|
||||
session['login_time'] = datetime.datetime.now()
|
||||
|
||||
|
@ -37,19 +37,18 @@ def common_login(db_user, permanent_session=True):
|
|||
session.permanent_session_lifetime = convert_to_timedelta(session_timeout_str)
|
||||
|
||||
# Inform our user analytics that we have a new "lead"
|
||||
create_lead_future = user_analytics.create_lead(
|
||||
db_user.email,
|
||||
db_user.username,
|
||||
db_user.given_name,
|
||||
db_user.family_name,
|
||||
db_user.company,
|
||||
)
|
||||
create_lead_future.add_done_callback(build_error_callback('Create lead failed'))
|
||||
|
||||
#create_lead_future = user_analytics.create_lead(
|
||||
# db_user.email,
|
||||
# db_user.username,
|
||||
# db_user.given_name,
|
||||
# db_user.family_name,
|
||||
# db_user.company,
|
||||
#)
|
||||
#create_lead_future.add_done_callback(build_error_callback('Create lead failed'))
|
||||
return True
|
||||
else:
|
||||
logger.debug('User could not be logged in, inactive?')
|
||||
return False
|
||||
|
||||
logger.debug('User could not be logged in, inactive?')
|
||||
return False
|
||||
|
||||
|
||||
def _list_files(path, extension):
|
||||
|
|
|
@ -139,7 +139,7 @@ def _render_ologin_error(service_name, error_message=None, register_redirect=Fal
|
|||
def _perform_login(user_obj, service_name):
|
||||
""" Attempts to login the given user, returning the Flask result of whether the login succeeded.
|
||||
"""
|
||||
if common_login(user_obj):
|
||||
if common_login(user_obj.uuid):
|
||||
if model.user.has_user_prompts(user_obj):
|
||||
return redirect(url_for('web.updateuser'))
|
||||
else:
|
||||
|
|
|
@ -22,4 +22,4 @@ from test.fixtures import *
|
|||
def test_common_login(username, expect_success, app):
|
||||
db_user = model.user.get_namespace_user(username)
|
||||
with app.app_context():
|
||||
assert common_login(db_user) == expect_success
|
||||
assert common_login(db_user.uuid) == expect_success
|
||||
|
|
|
@ -464,7 +464,7 @@ def confirm_email():
|
|||
change_email_future = user_analytics.change_email(old_email, new_email)
|
||||
change_email_future.add_done_callback(build_error_callback('Change email failed'))
|
||||
|
||||
common_login(user)
|
||||
common_login(user.uuid)
|
||||
if model.user.has_user_prompts(user):
|
||||
return redirect(url_for('web.updateuser'))
|
||||
elif new_email:
|
||||
|
@ -481,7 +481,7 @@ def confirm_recovery():
|
|||
user = model.user.validate_reset_code(code)
|
||||
|
||||
if user is not None:
|
||||
common_login(user)
|
||||
common_login(user.uuid)
|
||||
return redirect(url_for('web.user_view', path=user.username, tab='settings', action='password'))
|
||||
else:
|
||||
message = 'Invalid recovery code: This code is invalid or may have already been used.'
|
||||
|
|
Reference in a new issue