(session, user)
| 22 | |
| 23 | class OneTimePass(): |
| 24 | def new(session, user): |
| 25 | |
| 26 | |
| 27 | secret = pyotp.random_base32() |
| 28 | user.otp_secret = secret |
| 29 | user.otp_enabled = True |
| 30 | |
| 31 | backup_code_list = [] |
| 32 | for i in range(3): |
| 33 | backup_code = pyotp.random_base32() |
| 34 | backup_code_list.append(backup_code) |
| 35 | user.otp_backup[backup_code] = True |
| 36 | |
| 37 | session.add(user) |
| 38 | |
| 39 | totp = pyotp.TOTP(secret) |
| 40 | otp = totp.now() |
| 41 | |
| 42 | qr_code_url = totp.provisioning_uri( |
| 43 | user.email, |
| 44 | issuer_name="Diffgram") |
| 45 | |
| 46 | return otp, qr_code_url, backup_code_list |
| 47 | |
| 48 | |
| 49 |
no test coverage detected