예제 #1
0
    def save(self, **kwargs):
        
        email = self.cleaned_data["email"]
        token_generator = kwargs.get("token_generator", default_token_generator)
        
        for user in self.users:
            
            temp_key = token_generator.make_token(user)
            
            # save it to the password reset model
            # password_reset = PasswordReset(user=user, temp_key=temp_key)
            # password_reset.save()
            
            current_site = Site.objects.get_current()

            # send the password reset email
            path = reverse("account_reset_password_from_key",
                           kwargs=dict(uidb36=int_to_base36(user.id),
                                       key=temp_key))
            url = 'http://%s%s' % (current_site.domain,
                                   path)
            context = { "site": current_site,
                        "user": user,
                        "password_reset_url": url }
            get_adapter().send_mail('account/email/password_reset_key',
                                    email,
                                    context)
        return self.cleaned_data["email"]
예제 #2
0
 def send(self, request, **kwargs):
     summer_camp_url = reverse('summer_camp_create_signup', kwargs={'source':'camp_signup'})
     summer_camp_flow = summer_camp_url == request.REQUEST.get('next')
     current_site = kwargs["site"] if "site" in kwargs else Site.objects.get_current()
     activate_url = reverse("account_confirm_email", args=[self.key])
     activate_url = request.build_absolute_uri(activate_url)
     ctx = {
         "user": self.email_address.user,
         "activate_url": activate_url,
         "current_site": current_site,
         "key": self.key,
     }
     try:
         from brilliant.utils.tmail import send_tmail
     except:
         get_adapter().send_mail('account/email/email_confirmation',
                             self.email_address.email,
                             ctx)
     else:
         if hasattr(self.email_address, 'initial_signup') \
                 and self.email_address.initial_signup:
             if summer_camp_flow:
                 tpl = "utils/email_confirmation_summer_camp_welcome"
             else:
                 tpl = "utils/email_confirmation_welcome"
         else:
             tpl = "utils/email_confirmation"
         send_tmail(tpl, [self.email_address.email], ctx)
     self.sent = timezone.now()
     self.save()
     signals.email_confirmation_sent.send(sender=self.__class__, confirmation=self)
예제 #3
0
    def save(self, **kwargs):

        email = self.cleaned_data["email"]
        token_generator = kwargs.get("token_generator",
                                     default_token_generator)

        for user in self.users:

            temp_key = token_generator.make_token(user)

            # save it to the password reset model
            # password_reset = PasswordReset(user=user, temp_key=temp_key)
            # password_reset.save()

            current_site = Site.objects.get_current()

            # send the password reset email
            path = reverse("account_reset_password_from_key",
                           kwargs=dict(uidb36=int_to_base36(user.id),
                                       key=temp_key))
            url = 'http://%s%s' % (current_site.domain, path)
            context = {
                "site": current_site,
                "user": user,
                "password_reset_url": url
            }
            get_adapter().send_mail('account/email/password_reset_key', email,
                                    context)
        return self.cleaned_data["email"]
예제 #4
0
def complete_social_login(request, sociallogin):
    assert not sociallogin.is_existing
    sociallogin.lookup()
    try:
        get_adapter().pre_social_login(request, sociallogin)
        signals.pre_social_login.send(sender=SocialLogin, request=request, sociallogin=sociallogin)
    except ImmediateHttpResponse, e:
        return e.response
예제 #5
0
 def save(self, **kwargs):
     
     email = self.cleaned_data["email"]
     token_generator = kwargs.get("token_generator", default_token_generator)
     
     for user in self.users:
         context = create_password_reset_context(user) 
         get_adapter().send_mail('account/email/password_reset_key',
                                 email,
                                 context)
     return self.cleaned_data["email"]
예제 #6
0
 def send(self, request, **kwargs):
     current_site = kwargs["site"] if "site" in kwargs else Site.objects.get_current()
     activate_url = reverse("account_confirm_email", args=[self.key])
     activate_url = request.build_absolute_uri(activate_url)
     ctx = {
         "user": self.email_address.user,
         "activate_url": activate_url,
         "current_site": current_site,
         "key": self.key,
     }
     get_adapter().send_mail('account/email/email_confirmation',
                             self.email_address.email,
                             ctx)
     self.sent = timezone.now()
     self.save()
     signals.email_confirmation_sent.send(sender=self.__class__, confirmation=self)
예제 #7
0
 def get_redirect_url(self):
     redirect_to_name = self.request.GET.get('redirect_to_name')
     try:
         if redirect_to_name:
             return reverse(redirect_to_name)
     except: pass
     return get_adapter().get_email_confirmation_redirect_url(self.request)
예제 #8
0
def get_default_redirect(request,
                         redirect_field_name="next",
                         login_redirect_urlname=LOGIN_REDIRECT_URLNAME,
                         session_key_value="redirect_to"):
    """
    Returns the URL to be used in login procedures by looking at different
    values in the following order:

    - a REQUEST value, GET or POST, named "next" by default.
    - LOGIN_REDIRECT_URL - the URL in the setting
    - LOGIN_REDIRECT_URLNAME - the name of a URLconf entry in the settings
    """
    if login_redirect_urlname:
        default_redirect_to = reverse(login_redirect_urlname)
    else:
        default_redirect_to = get_adapter().get_login_redirect_url(request)
    redirect_to = request.REQUEST.get(redirect_field_name)
    if not redirect_to:
        # try the session if available
        if hasattr(request, "session"):
            redirect_to = request.session.get(session_key_value)
    # light security check -- make sure redirect_to isn't garabage.
    if not redirect_to or "://" in redirect_to or " " in redirect_to:
        redirect_to = default_redirect_to
    return redirect_to
예제 #9
0
 def send(self, request, **kwargs):
     current_site = kwargs[
         "site"] if "site" in kwargs else Site.objects.get_current()
     activate_url = reverse("account_confirm_email", args=[self.key])
     activate_url = request.build_absolute_uri(activate_url)
     ctx = {
         "user": self.email_address.user,
         "activate_url": activate_url,
         "current_site": current_site,
         "key": self.key,
     }
     get_adapter().send_mail('account/email/email_confirmation',
                             self.email_address.email, ctx)
     self.sent = timezone.now()
     self.save()
     signals.email_confirmation_sent.send(sender=self.__class__,
                                          confirmation=self)
예제 #10
0
def setup_user_email(request, user):
    """
    Creates proper EmailAddress for the user that was just signed
    up. Only sets up, doesn't do any other handling such as sending
    out email confirmation mails etc.
    """
    from models import EmailAddress

    assert EmailAddress.objects.filter(user=user).count() == 0
    if not user.email:
        return
    adapter = get_adapter()
    is_verified = adapter.is_email_verified(request, user.email)
    adapter.stash_email_verified(request, None)
    email_address = EmailAddress.objects.create(user=user, email=user.email, verified=is_verified, primary=True)
    return email_address
예제 #11
0
 def test_signup_email_verified_externally(self):
     request = RequestFactory().post(reverse('account_signup'),
                   { 'username': '******',
                     'email': '*****@*****.**',
                     'password1': 'johndoe',
                     'password2': 'johndoe' })
     # Fake stash_email_verified
     from django.contrib.messages.middleware import MessageMiddleware
     from django.contrib.sessions.middleware import SessionMiddleware
     SessionMiddleware().process_request(request)
     MessageMiddleware().process_request(request)
     request.session['account_email_verified'] ='*****@*****.**'
     from views import signup
     resp = signup(request)
     self.assertEquals(resp.status_code, 302)
     self.assertEquals(resp['location'], 
                       get_adapter().get_login_redirect_url(request))
     self.assertEquals(len(mail.outbox), 0)
예제 #12
0
def setup_user_email(request, user):
    """
    Creates proper EmailAddress for the user that was just signed
    up. Only sets up, doesn't do any other handling such as sending
    out email confirmation mails etc.
    """
    from models import EmailAddress

    assert EmailAddress.objects.filter(user=user).count() == 0
    if not user.email:
        return
    adapter = get_adapter()
    is_verified = adapter.is_email_verified(request, user.email)
    adapter.stash_email_verified(request, None)
    email_address = EmailAddress.objects.create(user=user,
                                                email=user.email,
                                                verified=is_verified,
                                                primary=True)
    return email_address
예제 #13
0
def get_default_redirect(request, redirect_field_name="next",
        login_redirect_urlname=LOGIN_REDIRECT_URLNAME, session_key_value="redirect_to"):
    """
    Returns the URL to be used in login procedures by looking at different
    values in the following order:

    - a REQUEST value, GET or POST, named "next" by default.
    - LOGIN_REDIRECT_URL - the URL in the setting
    - LOGIN_REDIRECT_URLNAME - the name of a URLconf entry in the settings
    """
    if login_redirect_urlname:
        default_redirect_to = reverse(login_redirect_urlname)
    else:
        default_redirect_to = get_adapter().get_login_redirect_url(request)
    redirect_to = request.REQUEST.get(redirect_field_name)
    if not redirect_to:
        # try the session if available
        if hasattr(request, "session"):
            redirect_to = request.session.get(session_key_value)
    # light security check -- make sure redirect_to isn't garabage.
    if not redirect_to or "://" in redirect_to or " " in redirect_to:
        redirect_to = default_redirect_to
    return redirect_to
예제 #14
0
 def is_open(self):
     return get_adapter().is_open_for_signup(self.request)
예제 #15
0
 def get_redirect_url(self):
     return get_adapter().get_email_confirmation_redirect_url(self.request)
예제 #16
0
 def get_redirect_url(self):
     return get_adapter().get_email_confirmation_redirect_url(self.request)