|
59 | 59 | // FIXME What's the deal with otp_enabled=v ?? |
60 | 60 |
|
61 | 61 |
|
| 62 | +function finish_2fa_success($msg = '') { |
| 63 | + global $app; |
| 64 | + $_SESSION['s'] = $_SESSION['s_pending']; |
| 65 | + unset($_SESSION['s_pending']); |
| 66 | + unset($_SESSION['otp']); |
| 67 | + $username = $_SESSION['s']['user']['username']; |
| 68 | + if (!empty($msg)) { |
| 69 | + $msg = ' ' . $msg; |
| 70 | + } |
| 71 | + $app->auth_log('Successful login for user \''. $username .'\' ' . $msg . ' from '. $_SERVER['REMOTE_ADDR'] .' at '. date('Y-m-d H:i:s') . ' with session ID ' .session_id()); |
| 72 | + $app->db->query('UPDATE `sys_user` SET otp_attempts=0 WHERE userid = ?', $_SESSION['s']['user']['userid']); |
| 73 | + session_write_close(); |
| 74 | + header('Location: ../index.php'); |
| 75 | + die(); |
| 76 | +} |
62 | 77 |
|
63 | 78 | //* Handle recovery code |
64 | 79 | if(isset($_POST['code']) && strlen($_POST['code']) == $otp_recovery_code_length && $_SESSION['otp']['recovery']) { |
|
68 | 83 |
|
69 | 84 | //* We allow one more try to enter recovery code |
70 | 85 | if($user['otp_attempts'] > $max_global_code_retry + 1) { |
71 | | - |
| 86 | + die("Sorry, contact your administrator."); |
72 | 87 | } |
73 | 88 |
|
74 | | - // show reset form to create a new 2fa secret? |
75 | | - |
76 | | - die('Handle recovery code'); |
| 89 | + if ($_SESSION['otp']['recovery'] == $_POST['code']) { |
| 90 | + finish_2fa_success('via 2fa recovery code'); |
| 91 | + } |
77 | 92 | } |
78 | 93 |
|
79 | 94 |
|
|
104 | 119 |
|
105 | 120 | //* 2fa success |
106 | 121 | if($_POST['code'] == $_SESSION['otp']['code']) { |
107 | | - $_SESSION['s'] = $_SESSION['s_pending']; |
108 | | - // Reset the attempt counter. |
109 | | - $app->db->query('UPDATE `sys_user` SET otp_attempts=0 WHERE userid = ?', $_SESSION['s']['user']['userid']); |
110 | | - unset($_SESSION['s_pending']); |
111 | | - unset($_SESSION['otp']); |
112 | | - header('Location: ../index.php'); |
113 | | - die(); |
| 122 | + finish_2fa_success(); |
114 | 123 | } else { |
115 | 124 | //* 2fa wrong code |
116 | 125 | $_SESSION['otp']['session_attempts']++; // FIXME can't we skip this and rely on the DB only? |
|
0 commit comments