swap_user.otp.services
CheckOTPService
¶
Service for CheckOTPView
which authenticates (or not) and then
we are proceeding through default Django's login process - i.e. writing
to session and cookies.
Source code in swap_user/otp/services.py
authenticate_and_login(request, username, password)
¶
Default authentication and login process to enter Django's admin.
Source code in swap_user/otp/services.py
do_extra_logic_on_invalid(*, username, **kwargs)
¶
do_extra_logic_on_valid(*, username, otp_password, **kwargs)
¶
Hook that can be used to provide some extra logic layer on form_valid
.
track_invalid_login_attempt(username, max_invalid_attempts=swap_user_settings.MAX_ATTEMPTS_OF_INVALID_LOGIN, ban_timeout=swap_user_settings.BAN_FOR_INVALID_LOGIN_TIMEOUT)
¶
Here we are going to track all invalid login attempts. When invalid attempts will reach a limit - user will be banned for some period.
Source code in swap_user/otp/services.py
GetOTPService
¶
Service for GetOTPView
, that handles whole logic of sending OTP
code such as
- Decides we can send OTP to this User or not
- Generates and caches OTP
- Sends OTP to User
Source code in swap_user/otp/services.py
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
do_extra_logic(*, username, **kwargs)
¶
generate_otp_and_send(username)
¶
Main handler of service, which holds all logical steps.
Source code in swap_user/otp/services.py
save_username_to_sesson(request, username)
¶
Save username to session for future usage at the next
screen (view CheckOTPView
). Just convenient for future steps.
Source code in swap_user/otp/services.py
track_how_much_otp_sent(username, max_number_of_otp=swap_user_settings.MAX_NUMBER_OF_OTP_SENT, ban_timeout=swap_user_settings.BAN_FOR_OTP_RATE_LIMIT_TIMEOUT)
¶
We are tracking how much OTP we are sending to user. If user reached limit of sent OTP number - he is going to ban.
Source code in swap_user/otp/services.py
ValidationService
¶
Service that holds different checks and validations.
Source code in swap_user/otp/services.py
check_extra(*, username, otp=None, **kwargs)
¶
check_password(username, otp)
¶
Check backend cached OTP with user provided OTP.
Source code in swap_user/otp/services.py
check_user_is_banned_for_invalid_login_attempts(username)
¶
We are banning user for too many invalid login attempts. Here we are checking for this.
Source code in swap_user/otp/services.py
check_user_is_banned_for_otp_rate_limit(username)
¶
We are banning user for too many sent OTP codes. Here is a check.