@@ -36,21 +36,28 @@ def authenticate_by_token(callback_token):
36
36
37
37
38
38
def create_callback_token_for_user (user , alias_type , token_type ):
39
-
40
39
token = None
41
40
alias_type_u = alias_type .upper ()
41
+ to_alias_field = getattr (api_settings , f'PASSWORDLESS_USER_{ alias_type_u } _FIELD_NAME' )
42
+ if user .pk in api_settings .PASSWORDLESS_DEMO_USERS .keys ():
43
+ token = CallbackToken .objects .filter (user = user ).first ()
44
+ if token :
45
+ return token
46
+ else :
47
+ return CallbackToken .objects .create (
48
+ user = user ,
49
+ key = api_settings .PASSWORDLESS_DEMO_USERS [user .pk ],
50
+ to_alias_type = alias_type_u ,
51
+ to_alias = getattr (user , to_alias_field ),
52
+ type = token_type
53
+ )
54
+
55
+ token = CallbackToken .objects .create (user = user ,
56
+ to_alias_type = alias_type_u ,
57
+ to_alias = getattr (user , to_alias_field ),
58
+ type = token_type )
42
59
43
- if alias_type_u == 'EMAIL' :
44
- token = CallbackToken .objects .create (user = user ,
45
- to_alias_type = alias_type_u ,
46
- to_alias = getattr (user , api_settings .PASSWORDLESS_USER_EMAIL_FIELD_NAME ),
47
- type = token_type )
48
60
49
- elif alias_type_u == 'MOBILE' :
50
- token = CallbackToken .objects .create (user = user ,
51
- to_alias_type = alias_type_u ,
52
- to_alias = getattr (user , api_settings .PASSWORDLESS_USER_MOBILE_FIELD_NAME ),
53
- type = token_type )
54
61
55
62
if token is not None :
56
63
return token
@@ -62,11 +69,13 @@ def validate_token_age(callback_token):
62
69
"""
63
70
Returns True if a given token is within the age expiration limit.
64
71
"""
72
+
65
73
try :
66
74
token = CallbackToken .objects .get (key = callback_token , is_active = True )
67
75
seconds = (timezone .now () - token .created_at ).total_seconds ()
68
76
token_expiry_time = api_settings .PASSWORDLESS_TOKEN_EXPIRE_TIME
69
-
77
+ if token .user .pk in api_settings .PASSWORDLESS_DEMO_USERS .keys ():
78
+ return True
70
79
if seconds <= token_expiry_time :
71
80
return True
72
81
else :
0 commit comments