Code Duplication    Length = 26-29 lines in 2 locations

th_github/my_github.py 1 location

@@ 134-162 (lines=29) @@
131
        request.session['oauth_id'] = auth.id
132
        return callback_url
133
134
    def callback(self, request, **kwargs):
135
        """
136
            Called from the Service when the user accept to activate it
137
            :param request: request object
138
            :return: callback url
139
            :rtype: string , path to the template
140
        """
141
        try:
142
            # finally we save the user auth token
143
            # As we already stored the object ServicesActivated
144
            # from the UserServiceCreateView now we update the same
145
            # object to the database so :
146
            # 1) we get the previous objet
147
            us = UserService.objects.get(
148
                user=request.user,
149
                name=ServicesActivated.objects.get(name='ServiceGithub'))
150
            # 2) Readability API require to use 4 params consumer_key/secret +
151
            # token_key/secret instead of usually get just the token
152
            # from an access_token request. So we need to add a string
153
            # separator for later use to split on this one
154
            access_token = request.session['oauth_token'] + "#TH#"
155
            access_token += str(request.session['oauth_id'])
156
            us.token = access_token
157
            # 3) and save everything
158
            us.save()
159
        except KeyError:
160
            return '/'
161
162
        return 'github/callback.html'
163

th_evernote/my_evernote.py 1 location

@@ 433-458 (lines=26) @@
430
            let's auth the user to the Service
431
        """
432
        client = self.get_evernote_client()
433
        request_token = client.get_request_token(
434
            self.callback_url(request, 'evernote'))
435
436
        # Save the request token information for later
437
        request.session['oauth_token'] = request_token['oauth_token']
438
        request.session['oauth_token_secret'] = request_token[
439
            'oauth_token_secret']
440
441
        # Redirect the user to the Evernote authorization URL
442
        # return the URL string which will be used by redirect()
443
        # from the calling func
444
        return client.get_authorize_url(request_token)
445
446
    def callback(self, request, **kwargs):
447
        """
448
            Called from the Service when the user accept to activate it
449
        """
450
        try:
451
            client = self.get_evernote_client()
452
            # finally we save the user auth token
453
            # As we already stored the object ServicesActivated
454
            # from the UserServiceCreateView now we update the same
455
            # object to the database so :
456
            # 1) we get the previous objet
457
            us = UserService.objects.get(
458
                user=request.user,
459
                name=ServicesActivated.objects.get(name='ServiceEvernote'))
460
            # 2) then get the token
461
            us.token = client.get_access_token(