-
-
Notifications
You must be signed in to change notification settings - Fork 457
Expand file tree
/
Copy pathmethod.py
More file actions
54 lines (40 loc) · 1.73 KB
/
method.py
File metadata and controls
54 lines (40 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from django.utils.translation import gettext_lazy as _
from two_factor.plugins.registry import MethodBase
from .forms import PhoneNumberForm
from .models import PhoneDevice
from .utils import format_phone_number, mask_phone_number
class PhoneMethodBase(MethodBase):
def get_devices(self, user):
return PhoneDevice.objects.filter(user=user, method=self.code)
def recognize_device(self, device):
return isinstance(device, PhoneDevice) and device.method == self.code
def get_setup_forms(self, *args):
return {self.code: PhoneNumberForm}
def get_device_from_setup_data(self, request, storage_data, **kwargs):
return PhoneDevice(
key=kwargs['key'],
name='default',
user=request.user,
method=self.code,
number=storage_data.get(self.code, {}).get('number'),
)
def get_action(self, device):
number = mask_phone_number(format_phone_number(device.number))
return self.action % number
def get_verbose_action(self, device):
return self.verbose_action
class PhoneCallMethod(PhoneMethodBase):
code = 'call'
verbose_name = _('Phone call')
action = _('Call number %s')
verbose_action = _('We are calling your phone right now, please enter the digits you hear.')
class SMSMethod(PhoneMethodBase):
code = 'sms'
verbose_name = _('Text message')
action = _('Send text message to %s')
verbose_action = _('We sent you a text message, please enter the token we sent.')
class WhatsAppMethod(PhoneMethodBase):
code = 'wa'
verbose_name = _('WhatsApp message')
action = _('Send WhatsApp message to %s')
verbose_action = _('We sent you a WhatsApp message, please enter the token we sent.')