예제 #1
0
    def post(self, request):
        """ Data expected:
            {
              username: name,
              email: string(valid email),
              session_key: string(key obtained with a post to TwitterLoginView)
            }
        """
        self.validate_request(request)

        # Obtengo el session_id
        self.set_session(request)

        # Chequeo que tenga una sesión en el servidor
        data = self.get_session_data(request)

        # Valido los campos de signup (username y email)
        login = self.get_sociallogin(request, data)
        form = SignupForm(data=request.data, sociallogin=login)
        if not form.is_valid():
            raise ValidationError(form.errors)

        # Guardo el usuario y creo su binding con la cuenta social
        new_user = form.save(request)
        complete_social_signup(request, login)
        return self.get_user_response(new_user)
예제 #2
0
파일: views.py 프로젝트: Osmose/kuma
    def form_valid(self, form):
        """
        We use the selected email here and reset the social loging list of
        email addresses before they get created.

        We send our welcome email via celery during complete_signup.
        So, we need to manually commit the user to the db for it.
        """
        selected_email = form.cleaned_data['email']
        if form.other_email_used:
            email_address = {
                'email': selected_email,
                'verified': False,
                'primary': True,
            }
        else:
            email_address = self.email_addresses.get(selected_email, None)

        if email_address:
            email_address['primary'] = True
            primary_email_address = EmailAddress(**email_address)
            form.sociallogin.email_addresses = \
                self.sociallogin.email_addresses = [primary_email_address]
            if email_address['verified']:
                # we have to stash the selected email address here
                # so that no email verification is sent again
                # this is done by adding the email address to the session
                get_adapter().stash_verified_email(self.request,
                                                   email_address['email'])

        with transaction.atomic():
            form.save(self.request)
        return helpers.complete_social_signup(self.request,
                                              self.sociallogin)
예제 #3
0
    def form_valid(self, form):
        """
        We use the selected email here and reset the social loging list of
        email addresses before they get created.

        We send our welcome email via celery during complete_signup.
        So, we need to manually commit the user to the db for it.
        """
        selected_email = form.cleaned_data['email']
        if selected_email == form.other_email_value:
            email_address = {
                'email': form.cleaned_data['other_email'],
                'verified': False,
                'primary': True,
            }
        else:
            email_address = self.email_addresses.get(selected_email, None)
        if email_address:
            email_address['primary'] = True
            self.sociallogin.email_addresses = [EmailAddress(*email_address)]
            if email_address['verified']:
                # we have to stash the selected email address here
                # so that no email verification is sent again
                # this is done by adding the email address to the session
                get_adapter().stash_verified_email(self.request,
                                                   email_address['email'])

        with transaction.commit_on_success():
            form.save(self.request)
        return helpers.complete_social_signup(self.request, self.sociallogin)
예제 #4
0
    def form_valid(self, form):
        """
        We use the selected email here and reset the social loging list of
        email addresses before they get created.

        We send our welcome email via celery during complete_signup.
        So, we need to manually commit the user to the db for it.
        """
        selected_email = form.cleaned_data["email"]
        if selected_email == form.other_email_value:
            email_address = {"email": form.cleaned_data["other_email"], "verified": False, "primary": True}
        else:
            email_address = self.email_addresses.get(selected_email, None)
        if email_address:
            email_address["primary"] = True
            self.sociallogin.email_addresses = [EmailAddress(*email_address)]
            if email_address["verified"]:
                # we have to stash the selected email address here
                # so that no email verification is sent again
                # this is done by adding the email address to the session
                get_adapter().stash_verified_email(self.request, email_address["email"])

        with transaction.commit_on_success():
            form.save(self.request)
        return helpers.complete_social_signup(self.request, self.sociallogin)
예제 #5
0
def socialaccount_signup(request, *args, **kwargs):
    if request.user.is_authenticated():
        return http.HttpResponseRedirect(reverse(connections))
    signup = request.session.get('socialaccount_signup')
    if not signup:
        return http.HttpResponseRedirect(reverse('account_login'))
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", 
                               'socialaccount/signup.html')
    data = signup['data']
    extra_ctx = kwargs.pop("extra_ctx", {})
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            user.last_name = data.get('last_name', '')
            user.first_name = data.get('first_name', '')
            user.save()
            account = signup['account']
            account.user = user
            account.sync(data)
            profile = user.profile
            for p in request.FILES.getlist('profile_image'):
                profile.profile_image.save(p.name, p)
                profile.save()
            return helpers.complete_social_signup(request, user, account)
    else:
        form = form_class(initial=data)
    dictionary = dict(site=Site.objects.get_current(),
                      account=signup['account'],
                      form=form)
    return render_to_response(template_name, 
                              dictionary, 
                              RequestContext(request, extra_ctx))
예제 #6
0
    def form_valid(self, form):
        """
        We use the selected email here and reset the social logging list of
        email addresses before they get created.

        We send our welcome email via celery during complete_signup.
        So, we need to manually commit the user to the db for it.
        """
        selected_email = form.cleaned_data["email"]
        if form.other_email_used:
            data = {
                "email": selected_email,
                "verified": False,
                "primary": True,
            }
        else:
            data = self.email_addresses.get(selected_email, None)

        if data:
            primary_email_address = EmailAddress(email=data["email"],
                                                 verified=data["verified"],
                                                 primary=True)
            form.sociallogin.email_addresses = self.sociallogin.email_addresses = [
                primary_email_address
            ]
            if data["verified"]:
                # we have to stash the selected email address here
                # so that no email verification is sent again
                # this is done by adding the email address to the session
                get_adapter().stash_verified_email(self.request, data["email"])

        with transaction.atomic():
            form.save(self.request)
        return helpers.complete_social_signup(self.request, self.sociallogin)
예제 #7
0
 def post(self, request, format=None):
     fc = self.get_form_class()
     form = fc(data=request.DATA, files=request.FILES, sociallogin=self.sociallogin)
     if form.is_valid():
         user = form.save(request)
         return complete_social_signup(self.request, user, app_settings.EMAIL_VERIFICATION)
     return Response(form.errors, HTTP_400_BAD_REQUEST)
예제 #8
0
파일: views.py 프로젝트: pombredanne/kuma
 def form_valid(self, form):
     """
     We send our welcome email via celery during complete_signup.
     So, we need to manually commit the user to the db for it.
     """
     with transaction.commit_on_success():
         form.save(self.request)
     return helpers.complete_social_signup(self.request, self.sociallogin)
예제 #9
0
    def form_valid(self, form):
        form.save(self.request)

        # After loggin them in, assign the first Level training so we know where to route them
        Level.objects.create(user=self.user, task_type=self.request.session.get('initial_training'), level=3, created=timezone.now())

        return helpers.complete_social_signup(self.request,
                                              self.sociallogin)
예제 #10
0
파일: views.py 프로젝트: dkns/kuma
 def form_valid(self, form):
     """
     We send our welcome email via celery during complete_signup.
     So, we need to manually commit the user to the db for it.
     """
     with transaction.commit_on_success():
         form.save(self.request)
     return helpers.complete_social_signup(self.request,
                                           self.sociallogin)
예제 #11
0
    def facebook_login(self, request, **kwargs):
        """Facebook sign up using django allauth tastypie."""
        data = self.deserialize(
            request,
            request.body,
            format=request.META.get('CONTENT_TYPE', 'application/json'))

        if 'access_token' not in data:
            raise CustomBadRequest(
                code='missing_key',
                message='Must provide {missing_key} when login with facebook.'.format(missing_key='access_token'))

        # Assign the access_token
        access_token = data.get('access_token', '')

        # Import some modules necessary
        # from allauth.socialaccount import providers
        from allauth.socialaccount.models import (SocialLogin, SocialToken, SocialApp)
        from allauth.socialaccount.providers.facebook.views import fb_complete_login
        from allauth.socialaccount.helpers import complete_social_login, complete_social_signup
        from allauth.socialaccount import providers
        from allauth.socialaccount.providers.facebook.provider import FacebookProvider, GRAPH_API_URL

        try:
            app = SocialApp.objects.get(provider='facebook')

            token = SocialToken(app=app, token=access_token)

            provider = providers.registry.by_id(FacebookProvider.id)
            print(provider.get_fields())
            print(GRAPH_API_URL)

            login = fb_complete_login(request, app, token)
            login.token = token
            login.state = SocialLogin.state_from_request(request)

            ret = complete_social_signup(request, login)
            print(ret)
            # If we get here we've succeeded
            return self.create_response(
                request,
                {
                    'success': True,
                    'user_id': request.user.pk,
                    'username': request.user.username,
                })
        except Exception as ex:
            print(ex)
            raise CustomBadRequest(
                code="missing_key",
                message="Can't login.")
예제 #12
0
    def form_valid(self, form):
        """
        We use the selected email here and reset the social logging list of
        email addresses before they get created.

        We send our welcome email via celery during complete_signup.
        So, we need to manually commit the user to the db for it.
        """

        selected_email = form.cleaned_data["email"]
        if selected_email in self.email_addresses:
            data = self.email_addresses[selected_email]
        elif selected_email == self.default_email:
            data = {
                "email": selected_email,
                "verified": True,
                "primary": True,
            }
        else:
            return HttpResponseBadRequest("email not a valid choice")

        primary_email_address = EmailAddress(
            email=data["email"], verified=data["verified"], primary=True
        )
        form.sociallogin.email_addresses = self.sociallogin.email_addresses = [
            primary_email_address
        ]
        if data["verified"]:
            # we have to stash the selected email address here
            # so that no email verification is sent again
            # this is done by adding the email address to the session
            get_adapter().stash_verified_email(self.request, data["email"])

        with transaction.atomic():
            saved_user = form.save(self.request)

            if saved_user.username != form.initial["username"]:
                track_event(
                    CATEGORY_SIGNUP_FLOW,
                    ACTION_PROFILE_EDIT,
                    "username edit",
                )

        # This won't be needed once this view is entirely catering to Yari.
        self.request.session.pop("yari_signup", None)

        return helpers.complete_social_signup(self.request, self.sociallogin)
예제 #13
0
 def form_valid(self, form):
     form.save(self.request)
     return helpers.complete_social_signup(self.request, self.sociallogin)
예제 #14
0
 def form_valid(self, form):
     form.save(self.request)
     return helpers.complete_social_signup(self.request,
                                           self.sociallogin)