session, session object auth_code, string, unsafe #TODO rename auth_code_string? checks if code is valid, and if so redeems returns True, signup_code object (or None), error_message (or None) signup_code has other stuff like project and permissions? Returns
(session,
auth_code,
email = None,
new_user = None)
| 82 | |
| 83 | |
| 84 | def attempt_redeem_code(session, |
| 85 | auth_code, |
| 86 | email = None, |
| 87 | new_user = None): |
| 88 | """ |
| 89 | session, session object |
| 90 | auth_code, string, unsafe |
| 91 | |
| 92 | #TODO rename auth_code_string? |
| 93 | |
| 94 | checks if code is valid, and if so redeems |
| 95 | |
| 96 | returns True, signup_code object (or None), error_message (or None) |
| 97 | |
| 98 | signup_code has other stuff like project and permissions? |
| 99 | |
| 100 | Returns |
| 101 | result bool, |
| 102 | message, |
| 103 | signup_code, class Auth_code (prior Signup_Code) object |
| 104 | |
| 105 | |
| 106 | |
| 107 | """ |
| 108 | # Is there a reason we wouldn't just directly filter by the signup code provided? |
| 109 | |
| 110 | # TODO extra handling here if email supplied? ie does signup email match code? |
| 111 | |
| 112 | auth = session.query(Signup_code).filter( |
| 113 | Signup_code.code == auth_code).first() |
| 114 | if auth is None: |
| 115 | return False, "Invalid code.", None |
| 116 | |
| 117 | if auth.is_available is False: |
| 118 | return False, "Already redeemed.", None |
| 119 | |
| 120 | # Context of verifying |
| 121 | # a user would create account with same email as we send a signup code to |
| 122 | if auth.email_sent_to and email: |
| 123 | if auth.email_sent_to != email: |
| 124 | return False, f"Code only valid for: {str(auth.email_sent_to)}", None |
| 125 | |
| 126 | if auth.type: |
| 127 | |
| 128 | if auth.type == "magic_login": |
| 129 | # 15 minute (time unit of 1 second * 60 * 15) |
| 130 | if time.time() >= auth.created_time_int + 900: |
| 131 | return False, "Expired.", None |
| 132 | |
| 133 | if auth.type == "add_to_project": |
| 134 | |
| 135 | # Careful, now we want auth object |
| 136 | # TODO clarify this!!! |
| 137 | process_project_auth_code( |
| 138 | session = session, |
| 139 | new_user = new_user, |
| 140 | auth_code = auth) |
| 141 |
nothing calls this directly
no test coverage detected