def complete(request, backend, *args, **kwargs): backend_name = backend.AUTH_BACKEND.name new_username = request.session.get(backend_name) if new_username: user = User.objects.get(username=new_username) else: user = auth_complete(request, backend, *args, **kwargs) if not user.is_active: request.session[backend_name] = user.username username = request.POST.get('username') if username: user.username = username user.is_active = True user.save() del request.session[backend_name] return redirect(reverse('socialauth_begin', args=[backend_name])) else: return render_to_response('socialauth/username.html', {'username':user.username}, RequestContext(request)) return complete_process(request, backend, user=user, *args, **kwargs)
def transfer(request, backend, *args, **kwargs): """Authentication complete process""" from social_auth import views as sav backend = sav.get_backend(backend, request, request.path) # copy + changes from social_auth.views.complete_process() user = sav.auth_complete(request, backend, *args, **kwargs) if user and not getattr(user, 'is_active', True): be = backend.AUTH_BACKEND login_backend = '%s.%s' % (be.__module__, be.__name__) request.session['SEEKINME_NEW_USER_ID'] = user.id request.session['SEEKINME_NEW_USER_BACKEND'] = login_backend url = '/user/' elif user and getattr(user, 'is_active', True): login(request, user) # user.social_user is the used UserSocialAuth instance defined # in authenticate process social_user = user.social_user if sav.SESSION_EXPIRATION : # Set session expiration date if present and not disabled by # setting. Use last social-auth instance for current provider, # users can associate several accounts with a same provider. if social_user.expiration_delta(): request.session.set_expiry(social_user.expiration_delta()) # store last login backend name in session request.session[sav.SOCIAL_AUTH_LAST_LOGIN] = social_user.provider # Remove possible redirect URL from session, if this is a new account, # send him to the new-users-page if defined. url = sav.NEW_USER_REDIRECT if sav.NEW_USER_REDIRECT and \ getattr(user, 'is_new', False) else \ request.session.pop(REDIRECT_FIELD_NAME, '') or \ sav.DEFAULT_REDIRECT else: url = sav.LOGIN_ERROR_URL return HttpResponseRedirect(url)
def complete_process(request, backend, *args, **kwargs): """Authentication complete process""" # pop redirect value before the session is trashed on login() redirect_value = request.session.get(REDIRECT_FIELD_NAME, '') or \ request.REQUEST.get(REDIRECT_FIELD_NAME, '') user = auth_complete(request, backend, *args, **kwargs) if isinstance(user, HttpResponse): return user if not user and request.user.is_authenticated(): return HttpResponseRedirect(redirect_value) msg = None if user: if getattr(user, 'is_active', True): # catch is_new flag before login() might reset the instance is_new = getattr(user, 'is_new', False) login(request, user) Event.log(metric_events.LOGIN, user) # user.social_user is the used UserSocialAuth instance defined # in authenticate process treshold = 10 # seconds if is_new: first_time_user_login.send(sender=request.user, user=request.user) if not redirect_value: redirect_value = FIRST_TIME_USER_REDIRECT_URL social_user = user.social_user if redirect_value: request.session[REDIRECT_FIELD_NAME] = redirect_value or \ DEFAULT_REDIRECT else: redirect_value = REGISTERED_USER_REDIRECT_URL if setting('SOCIAL_AUTH_SESSION_EXPIRATION', True): # Set session expiration date if present and not disabled by # setting. Use last social-auth instance for current provider, # users can associate several accounts with a same provider. expiration = social_user.expiration_datetime() if expiration: try: request.session.set_expiry(expiration) except OverflowError: # Handle django time zone overflow, set default expiry. request.session.set_expiry(None) # store last login backend name in session request.session['social_auth_last_login_backend'] = \ social_user.provider # Remove possible redirect URL from session, if this is a new # account, send him to the new-users-page if defined. new_user_redirect = backend_setting(backend, 'SOCIAL_AUTH_NEW_USER_REDIRECT_URL') if new_user_redirect and is_new: url = new_user_redirect else: url = redirect_value or \ backend_setting(backend, 'SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \ DEFAULT_REDIRECT else: msg = setting('SOCIAL_AUTH_INACTIVE_USER_MESSAGE', None) url = backend_setting(backend, 'SOCIAL_AUTH_INACTIVE_USER_URL', LOGIN_ERROR_URL) else: msg = setting('LOGIN_ERROR_MESSAGE', None) url = backend_setting(backend, 'LOGIN_ERROR_URL', LOGIN_ERROR_URL) if msg: messages.error(request, msg) if redirect_value and redirect_value != url: redirect_value = quote(redirect_value) if '?' in url: url += '&%s=%s' % (REDIRECT_FIELD_NAME, redirect_value) else: url += '?%s=%s' % (REDIRECT_FIELD_NAME, redirect_value) return HttpResponseRedirect(url)
def complete_process(request, backend, *args, **kwargs): """see .socialauth_complete""" # pop redirect value before the session is trashed on login() redirect_value = request.session.get(REDIRECT_FIELD_NAME, '') user = sviews.auth_complete(request, backend, *args, **kwargs) if isinstance(user, HttpResponse): return user if not user and request.user.is_authenticated(): return HttpResponseRedirect(redirect_value) if user: if getattr(user, 'is_active', True): # catch is_new flag before login() might reset the instance is_new = getattr(user, 'is_new', False) login(request, user) # user.social_user is the used UserSocialAuth instance defined # in authenticate process social_user = user.social_user if redirect_value: request.session[REDIRECT_FIELD_NAME] = redirect_value or \ DEFAULT_REDIRECT if setting('SOCIAL_AUTH_SESSION_EXPIRATION', True): # Set session expiration date if present and not disabled by # setting. Use last social-auth instance for current provider, # users can associate several accounts with a same provider. if social_user.expiration_delta(): request.session.set_expiry(social_user.expiration_delta()) # store last login backend name in session key = setting('SOCIAL_AUTH_LAST_LOGIN', 'social_auth_last_login_backend') request.session[key] = social_user.provider # Remove possible redirect URL from session, if this is a new # account, send him to the new-users-page if defined. new_user_redirect = backend_setting(backend, 'SOCIAL_AUTH_NEW_USER_REDIRECT_URL') if new_user_redirect and is_new: url = new_user_redirect else: url = redirect_value or \ backend_setting(backend, 'SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \ DEFAULT_REDIRECT else: """ OVERRIDEN PART """ # User created but not yet activated. details = { 'username':user.username, 'first_name':user.first_name, 'last_name': user.last_name } if user.email and user.email != '': details[ 'email' ] = user.email social_user = UserSocialAuth.objects.get(user=user) form = FMSNewRegistrationForm( initial=details ) return render_to_response( "registration/registration_form.html", {'form': form, 'social_connect': SocialProvider( backend.AUTH_BACKEND.name.capitalize() )}, context_instance=RequestContext(request)) """ -------------- OVERRIDEN PART """ else: msg = setting('LOGIN_ERROR_MESSAGE', None) if msg: messages.error(request, msg) url = backend_setting(backend, 'LOGIN_ERROR_URL', sviews.LOGIN_ERROR_URL) return HttpResponseRedirect(url)