Example #1
0
    def post( self, request, *args, **kw ):
        user_details = self.user_details
        is_signup = 'signup' in request.POST

        tmp_user = request.unique_user

        if is_signup:
            self.form = SSORegistrationForm(self.request.POST, request=self.request)
            self.signup_form = self.form
            self.login_form = self.get_login_form()
        else:
            self.form = LoginForm( self.request.POST )
            self.login_form = self.form
            self.signup_form = self.get_signup_form()
        
        context = self.get_context_data(*args, **kw)

        if self.form.is_valid():
            if is_signup:
                user = self.form.save()
            else:
                user = self.form.user

            fb_user = FBUser.create_or_update(user_details)
            FBAssociation.objects.create(
                    fb_uid = fb_user.id,
                    fb_user = fb_user,
                    user = user)
            user = auth.authenticate(fb_uid=fb_user.id)
            auth.login(self.request, user)
            participation = ContestParticipation.objects.get(contest=self.contest, fb_user=fb_user)
            participation.user = user
            participation.save()

            if not is_signup and tmp_user and tmp_user.username.startswith('fb-'):
                # user logged in, remove temporary user
                tmp_user.delete()

            return http.HttpResponseRedirect(reverse(self.on_success_view))

        return self.render_to_response(context)
Example #2
0
class LoginOrSignupView( AjaxView ):
    template_name='fbapp/login_or_signup.html'
    on_success_view = "fbapp_the_end"

    def get_context_data( self, *args, **kw ):
        context = super( LoginOrSignupView, self ).get_context_data( *args, **kw )
        context.update({
            'login_form': self.login_form,
            'signup_form': self.signup_form
        })
        return context

    def get_login_form( self ):
        return LoginForm()

    def get_signup_form( self ):
        user_details = self.user_details
        initial = dict(
            username=user_details.get('username', user_details.get('name')),
            email=user_details.get('email'),
        )
        return SSORegistrationForm( initial=initial, request=self.request )

    def get( self, request, *args, **kw ):
        self.login_form = self.get_login_form()
        self.signup_form = self.get_signup_form()
        return super( LoginOrSignupView, self ).get( request, *args, **kw )

    def post( self, request, *args, **kw ):
        user_details = self.user_details
        is_signup = 'signup' in request.POST

        tmp_user = request.unique_user

        if is_signup:
            self.form = SSORegistrationForm(self.request.POST, request=self.request)
            self.signup_form = self.form
            self.login_form = self.get_login_form()
        else:
            self.form = LoginForm( self.request.POST )
            self.login_form = self.form
            self.signup_form = self.get_signup_form()
        
        context = self.get_context_data(*args, **kw)

        if self.form.is_valid():
            if is_signup:
                user = self.form.save()
            else:
                user = self.form.user

            fb_user = FBUser.create_or_update(user_details)
            FBAssociation.objects.create(
                    fb_uid = fb_user.id,
                    fb_user = fb_user,
                    user = user)
            user = auth.authenticate(fb_uid=fb_user.id)
            auth.login(self.request, user)
            participation = ContestParticipation.objects.get(contest=self.contest, fb_user=fb_user)
            participation.user = user
            participation.save()

            if not is_signup and tmp_user and tmp_user.username.startswith('fb-'):
                # user logged in, remove temporary user
                tmp_user.delete()

            return http.HttpResponseRedirect(reverse(self.on_success_view))

        return self.render_to_response(context)