def auth_email_logout(token, user):
 redirect_url = cas.get_logout_url(service_url=cas.get_login_url(service_url=web_url_for('index', _absolute=True)))
 try:
  unconfirmed_email = user.get_unconfirmed_email_for_token(token)
 except InvalidTokenError:
  raise HTTPError(http.BAD_REQUEST, data={'message_short': 'Bad token', 'message_long': 'The provided token is invalid.'})
 except ExpiredTokenError:
  status.push_status_message('The private link you used is expired.')
  raise HTTPError(http.BAD_REQUEST, data={'message_short': 'Expired link', 'message_long': 'The private link you used is expired.'})
 try:
  user_merge = User.find_one(Q('emails', 'eq', unconfirmed_email))
 except NoResultsFound:
  user_merge = False
 if user_merge:
  remove_sessions_for_user(user_merge)
 user.email_verifications[token]['confirmed'] = True
 user.save()
 remove_sessions_for_user(user)
 resp = redirect(redirect_url)
 resp.delete_cookie(settings.COOKIE_NAME, domain=settings.OSF_COOKIE_DOMAIN)
 return resp

def auth_email_logout ( token , user ) : redirect_url = cas . get_logout_url ( service_url = cas . get_login_url ( service_url = web_url_for ( 'index' , _absolute = True ) ) ) try : unconfirmed_email = user . get_unconfirmed_email_for_token ( token ) except InvalidTokenError : raise HTTPError ( http . BAD_REQUEST , data = { 'message_short' : 'Bad token' , 'message_long' : 'The provided token is invalid.' } ) except ExpiredTokenError : status . push_status_message ( 'The private link you used is expired.' ) raise HTTPError ( http . BAD_REQUEST , data = { 'message_short' : 'Expired link' , 'message_long' : 'The private link you used is expired.' } ) try : user_merge = User . find_one ( Q ( 'emails' , 'eq' , unconfirmed_email ) ) except NoResultsFound : user_merge = False if user_merge : remove_sessions_for_user ( user_merge ) user . email_verifications [ token ] [ 'confirmed' ] = True user . save ( ) remove_sessions_for_user ( user ) resp = redirect ( redirect_url ) resp . delete_cookie ( settings . COOKIE_NAME , domain = settings . OSF_COOKIE_DOMAIN ) return resp
when a user is adding an email or merging an account .