def signup_verify(request, uidb36=None, token=None): """ View for the link in the verification email sent to a new user when they create an account and ``ACCOUNTS_VERIFICATION_REQUIRED`` is set to ``True``. Activates the user and logs them in, redirecting to the URL they tried to access when signing up. """ if settings.ACCOUNTS_APPROVAL_REQUIRED: raise Http404 user = authenticate(uidb36=uidb36, token=token, is_active=False) if user is not None: user.is_active = True user.save() auth_login(request, user) info(request, _("Successfully signed up")) send_welcome_mail(request, user, "signup_welcome") return login_redirect(request) else: error(request, _("The link you clicked is no longer valid.")) return redirect("/")
def complete_process(request, backend, *args, **kwargs): from social_auth.models import UserSocialAuth from social_friends_finder.models import SocialFriendList from django.core.cache import cache from itertools import chain from actstream import actions from actstream.models import Follow """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 user account is not already active or under verification, make it active. """ if not getattr(user, 'is_active', True): user.is_active = True 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 friends = SocialFriendList.objects.existing_social_friends(social_user) cache.delete(social_user.user.username+"SocialFriendList") cache.set(social_user.user.username+"SocialFriendList", friends) """ Default auto follow only for the new user. """ if is_new: # Disable it in case you want auto follow for each login. for friend_user in friends: if user.email != friend_user.email: if not Follow.objects.is_following(user, friend_user): if social_user.provider == "facebook" or social_user.provider == "google-oauth2" or social_user.provider == "google-oauth" or social_user.provider == "google": user.relationships.add(friend_user, symmetrical=True) actions.follow(user, friend_user, actor_only=False ) actions.follow(friend_user, user, actor_only=False) elif social_user.provider == "twitter": user.relationships.add(friend_user, symmetrical=False) actions.follow(user, friend_user, actor_only=False ) if social_user.provider != "twitter": send_welcome_mail(request, user, "signup_welcome") # friends_of_friends = list(friends) # for friend in friends: # socialAuthFriend = friend.social_auth.filter(provider="facebook") # if not socialAuthFriend: # socialAuthFriend = friend.social_auth.filter(provider="twitter") # if socialAuthFriend: # friends_level2 = SocialFriendList.objects.existing_social_friends(socialAuthFriend[0]) # if friends_level2: # friends_of_friends = list(chain(friends_of_friends, friends_level2)) # if friends_of_friends: # cache.delete(social_user.user.username+"SocialFriendListLevel2") # cache.set(social_user.user.username+"SocialFriendListLevel2", friends_of_friends) 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. 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)