コード例 #1
0
ファイル: views.py プロジェクト: manlan2/filmaster
    def get_context_data( self, request, user_id=None, oauth_token=None, **kwargs ):

        me = self.api.get('/me')

        fb_user = FBUser.create_or_update(me)

        try:
            assoc = FBAssociation.objects.get(fb_uid=user_id)
            user = assoc.user
            user = auth.authenticate(fb_uid=user_id)
            auth.login(request, user)
        except FBAssociation.DoesNotExist, e:
            if request.user.is_authenticated():
                user = request.user
                # auto create fbassociation
                FBAssociation.objects.create(
                        fb_uid = fb_user.id,
                        fb_user = fb_user,
                        user = user)
                FBUser.update_objects( self.api, '/me/friends', fb_user.friends )
            else:
                from film20.core.models import TemporaryUser
                user, created = TemporaryUser.objects.get_or_create(
                    username="******" % user_id,
                    defaults={'is_active':False},
                )
                if created:
                    FBUser.update_objects( self.api, '/me/friends', fb_user.friends )

                user.dirty = True 
                request._unique_user = user
コード例 #2
0
ファイル: views.py プロジェクト: manlan2/filmaster
    def post(self, *args, **kw):
        ticket_id = int(self.request.POST['ticket'])
        if not ticket_id:
            return http.HttpResponseRedirect(reverse("fbapp_choose_ticket"))
        ticket = ContestTickets.objects.get(id=ticket_id)

        contest = self.get_contest()

        try:
            participant = ContestParticipation.objects.get(
                            contest=contest,
                            user=self.request.unique_user
                        )
        except ContestParticipation.DoesNotExist:
            fb_user = FBUser.create_or_update(self.user_details)
            ratings_cnt = len(rating_helper.get_user_ratings(self.request.unique_user).keys())
            participant = ContestParticipation.objects.create(
                            contest=contest,
                            user=self.request.unique_user,
                            fb_user=fb_user,
                            contest_ticket=ticket,
                            score=5,
                            ratings_start_count = ratings_cnt,
                        )

        participant.state = ContestParticipation.STATE_TICKET
        participant.contest_ticket = ticket
        participant.save()

        return http.HttpResponseRedirect(reverse("fbapp_quiz"))
コード例 #3
0
 def fix_associations(self):
     api = graph.API()
     query = FBAssociation.objects.filter(fb_user__isnull=True)
     total = query.count()
     for n, assoc in enumerate(query):
         logger.info(assoc.fb_uid)
         try:
             user_data = api.get("/%s" % assoc.fb_uid)
         except urllib2.HTTPError, e:
             logger.warning(unicode(e))
             continue
         logger.info("%d / %d %r", n+1, total, user_data)
         if user_data:
             assoc.fb_user = FBUser.create_or_update(user_data)
         else:
             assoc.fb_user = FBUser.objects.create(id=assoc.fb_uid)
         assoc.save()
コード例 #4
0
ファイル: views.py プロジェクト: manlan2/filmaster
 def get_participant( self ):
     contest = self.get_object()
     fb_user = FBUser.create_or_update( self.request.session['user_details'] )
     try:
         participant = ContestParticipation.objects.get( contest=contest, fb_user=fb_user )
         if participant.user != self.request.unique_user:
             participant.user = self.request.unique_user
             participant.save()
     except ContestParticipation.DoesNotExist:
         ratings_cnt = len(rating_helper.get_user_ratings(self.request.unique_user).keys())
         participant = ContestParticipation.objects.create(
                 contest=contest,
                 user=self.request.unique_user, 
                 ratings_start_count = ratings_cnt,
                 fb_user=fb_user, state=ContestParticipation.STATE_TICKET
         )
     return participant
コード例 #5
0
ファイル: views.py プロジェクト: manlan2/filmaster
    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)