~ubuntu-branches/debian/sid/social-auth-core/sid

« back to all changes in this revision

Viewing changes to social_core/backends/legacy.py

  • Committer: Package Import Robot
  • Author(s): Andre Bianchi
  • Date: 2018-02-22 19:49:12 UTC
  • Revision ID: package-import@ubuntu.com-20180222194912-4lqv8mlhnqc4ncd3
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from .base import BaseAuth
 
2
from ..exceptions import AuthMissingParameter
 
3
 
 
4
 
 
5
class LegacyAuth(BaseAuth):
 
6
    def get_user_id(self, details, response):
 
7
        return details.get(self.ID_KEY) or \
 
8
               response.get(self.ID_KEY)
 
9
 
 
10
    def auth_url(self):
 
11
        return self.setting('FORM_URL')
 
12
 
 
13
    def auth_html(self):
 
14
        return self.strategy.render_html(tpl=self.setting('FORM_HTML'))
 
15
 
 
16
    def uses_redirect(self):
 
17
        return self.setting('FORM_URL') and not \
 
18
               self.setting('FORM_HTML')
 
19
 
 
20
    def auth_complete(self, *args, **kwargs):
 
21
        """Completes loging process, must return user instance"""
 
22
        if self.ID_KEY not in self.data:
 
23
            raise AuthMissingParameter(self, self.ID_KEY)
 
24
        kwargs.update({'response': self.data, 'backend': self})
 
25
        return self.strategy.authenticate(*args, **kwargs)
 
26
 
 
27
    def get_user_details(self, response):
 
28
        """Return user details"""
 
29
        email = response.get('email', '')
 
30
        username = response.get('username', '')
 
31
        fullname, first_name, last_name = self.get_user_names(
 
32
            response.get('fullname', ''),
 
33
            response.get('first_name', ''),
 
34
            response.get('last_name', '')
 
35
        )
 
36
        if email and not username:
 
37
            username = email.split('@', 1)[0]
 
38
        return {
 
39
            'username': username,
 
40
            'email': email,
 
41
            'fullname': fullname,
 
42
            'first_name': first_name,
 
43
            'last_name': last_name
 
44
        }