1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from __future__ import unicode_literals |
3
|
|
|
""" |
4
|
|
|
Base class of registration backend |
5
|
|
|
|
6
|
|
|
All backends of django-inspectional-registration should be a subclass |
7
|
|
|
of the ``BackendBase`` |
8
|
|
|
""" |
9
|
|
|
__author__ = 'Alisue <[email protected]>' |
10
|
|
|
from registration.utils import get_site |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class RegistrationBackendBase(object): |
14
|
|
|
|
15
|
|
|
"""Base class of registration backend |
16
|
|
|
|
17
|
|
|
Methods: |
18
|
|
|
get_site -- return current site |
19
|
|
|
register -- register a new user |
20
|
|
|
accept -- accept a registration |
21
|
|
|
reject -- reject a registration |
22
|
|
|
activate -- activate a user |
23
|
|
|
get_supplement_class -- get registration supplement class |
24
|
|
|
get_activation_form_class -- get activation form class |
25
|
|
|
get_registration_form_class -- get registration form class |
26
|
|
|
get_supplement_form_class -- get registration supplement form class |
27
|
|
|
get_activation_complete_url -- get activation complete redirect url |
28
|
|
|
get_registration_complete_url -- get registration complete redirect url |
29
|
|
|
get_registration_closed_url -- get registration closed redirect url |
30
|
|
|
registration_allowed -- whether registration is allowed now |
31
|
|
|
|
32
|
|
|
""" |
33
|
|
|
|
34
|
|
|
def get_site(self, request): |
35
|
|
|
"""get current ``django.contrib.Site`` instance |
36
|
|
|
|
37
|
|
|
return ``django.contrib.RequestSite`` instance when the ``Site`` is |
38
|
|
|
not installed. |
39
|
|
|
|
40
|
|
|
""" |
41
|
|
|
return get_site(request) |
42
|
|
|
|
43
|
|
|
def register(self, username, email, request, |
44
|
|
|
supplement=None, send_email=True): |
45
|
|
|
"""register a new user account with given ``username`` and ``email`` |
46
|
|
|
|
47
|
|
|
Returning should be a instance of new ``User`` |
48
|
|
|
|
49
|
|
|
""" |
50
|
|
|
raise NotImplementedError |
51
|
|
|
|
52
|
|
|
def accept(self, profile, request, |
53
|
|
|
send_email=True, message=None, force=False): |
54
|
|
|
"""accept account registration with given ``profile`` (an instance of |
55
|
|
|
``RegistrationProfile``) |
56
|
|
|
|
57
|
|
|
Returning should be a instance of accepted ``User`` for success, |
58
|
|
|
``None`` for fail. |
59
|
|
|
|
60
|
|
|
This method **SHOULD** work even after the account registration has |
61
|
|
|
rejected. |
62
|
|
|
|
63
|
|
|
""" |
64
|
|
|
raise NotImplementedError |
65
|
|
|
|
66
|
|
|
def reject(self, profile, request, send_email=True, message=None): |
67
|
|
|
"""reject account registration with given ``profile`` (an instance of |
68
|
|
|
``RegistrationProfile``) |
69
|
|
|
|
70
|
|
|
Returning should be a instance of accepted ``User`` for success, |
71
|
|
|
``None`` for fail. |
72
|
|
|
|
73
|
|
|
This method **SHOULD NOT** work after the account registration has |
74
|
|
|
accepted. |
75
|
|
|
|
76
|
|
|
""" |
77
|
|
|
raise NotImplementedError |
78
|
|
|
|
79
|
|
|
def activate(self, activation_key, request, password=None, send_email=True, |
80
|
|
|
message=None, no_profile_delete=False): |
81
|
|
|
"""activate account with ``activation_key`` and ``password`` |
82
|
|
|
|
83
|
|
|
This method should be called after the account registration has |
84
|
|
|
accepted, otherwise it should not be success. |
85
|
|
|
|
86
|
|
|
Returning is ``user``, ``password`` and ``is_generated`` for success, |
87
|
|
|
``None`` for fail. |
88
|
|
|
|
89
|
|
|
If ``password`` is not given, this method will generate password and |
90
|
|
|
``is_generated`` should be ``True`` in this case. |
91
|
|
|
|
92
|
|
|
""" |
93
|
|
|
raise NotImplementedError |
94
|
|
|
|
95
|
|
|
def get_supplement_class(self): |
96
|
|
|
"""Return the current registration supplement class""" |
97
|
|
|
raise NotImplementedError |
98
|
|
|
|
99
|
|
|
def get_activation_form_class(self): |
100
|
|
|
"""get activation form class""" |
101
|
|
|
raise NotImplementedError |
102
|
|
|
|
103
|
|
|
def get_registration_form_class(self): |
104
|
|
|
"""get registration form class""" |
105
|
|
|
raise NotImplementedError |
106
|
|
|
|
107
|
|
|
def get_supplement_form_class(self): |
108
|
|
|
"""get registration supplement form class""" |
109
|
|
|
raise NotImplementedError |
110
|
|
|
|
111
|
|
|
def get_activation_complete_url(self, user): |
112
|
|
|
"""get activation complete url""" |
113
|
|
|
raise NotImplementedError |
114
|
|
|
|
115
|
|
|
def get_registration_complete_url(self, user): |
116
|
|
|
"""get registration complete url""" |
117
|
|
|
raise NotImplementedError |
118
|
|
|
|
119
|
|
|
def get_registration_closed_url(self): |
120
|
|
|
"""get registration closed url""" |
121
|
|
|
raise NotImplementedError |
122
|
|
|
|
123
|
|
|
def registration_allowed(self): |
124
|
|
|
"""return ``False`` if the registration has closed""" |
125
|
|
|
raise NotImplementedError |
126
|
|
|
|