75 if(isset($_SESSION[
'USER_ID']) && isset($_SESSION[
'LEPTOKENS']))
77 $token = $_SESSION[
'LEPTOKENS'][0];
78 $redirect = $_GET[
'redirect']?? LEPTON_URL;
82 'ACTION_URL' => LEPTON_URL.
"/account/tfa.php",
84 'redirect' => $redirect,
85 'post_login' => $_POST,
87 'new' => $this->key_new,
90 $this->oTwig->registerPath( LEPTON_PATH.
"/account/templates/" );
91 echo $this->oTwig->render(
99 elseif ( $id ==
'save')
101 if(isset($_POST[
'save']) && strlen($_POST[
'save']) == 6 )
103 $this->pin_encode = password_hash($_POST[
'save'], PASSWORD_DEFAULT);
106 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin` = '".$this->pin_encode.
"' WHERE user_id = ".$this->user_id);
109 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin_set` = 1 WHERE user_id = ".$this->user_id);
111 header(
'Location: '.$_POST[
'redirect'].
' ');
118 header(
'Location: '.LEPTON_URL.
'/account/logout.php');
124 if ( $id ==
'display' || $id ==
'resend')
129 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin` = '".$this->pin_encode.
"' WHERE user_id = ".$this->user_id);
130 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin_set` = 1 WHERE user_id = ".$this->user_id);
135 $page_values = array(
137 'ACTION_URL' => LEPTON_URL.
"/account/tfa.php",
138 'post_login' => $_POST,
139 'redirect' => $_POST[
'redirect'] ?? LEPTON_URL,
141 'token' => $_SESSION[
'LEPTOKENS'][0],
145 $this->oTwig->registerPath( LEPTON_PATH.
"/account/templates/" );
146 echo $this->oTwig->render(
151 elseif ( $id ==
'forward')
154 if(isset($_POST[
'token']) && strlen($_POST[
'pin']) == 6 )
158 $dbKey = $this->database->get_one(
"SELECT pin FROM ".TABLE_PREFIX.
"users WHERE user_id = ".$this->user_id);
159 $postKey = $_POST[
'pin'];
160 $forward = strip_tags($_REQUEST[
'redirect'] ?? LEPTON_URL);
163 if(password_verify ($postKey, $dbKey) ===
true)
166 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin_set` = 2 WHERE user_id = ".$this->user_id);
168 header(
'Location: '.$forward);
172 header(
'Location: '.LEPTON_URL.
'/account/logout.php');
178 header(
'Location: '.LEPTON_URL.
'/account/logout.php');
184 if ( $id ==
'create')
186 $page_values = array(
188 'ACTION_URL' => ADMIN_URL.
"/login/tfa.php",
189 'token' => $_SESSION[
'LEPTOKENS'][0],
190 'post_login' => $_POST,
192 'new' => $this->key_new,
195 $this->oTwig->registerPath(
THEME_PATH.
"theme",
"tfa" );
196 echo $this->oTwig->render(
197 "@theme/tfa_form.lte",
204 if(isset($_POST[
'save']) && strlen($_POST[
'save']) == 6 )
206 $this->pin_encode = password_hash($_POST[
'save'], PASSWORD_DEFAULT);
209 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin` = '".$this->pin_encode.
"' WHERE user_id = ".$this->user_id);
212 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin_set` = 1 WHERE user_id = ".$this->user_id);
214 header(
'Location: '.ADMIN_URL.
'/logout/index.php');
219 header(
'Location: '.ADMIN_URL.
'/logout/index.php');
226 if ( $id ==
'display' || $id ==
'resend')
231 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin` = '".$this->pin_encode.
"' WHERE user_id = ".$this->user_id);
232 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin_set` = 1 WHERE user_id = ".$this->user_id);
237 $page_values = array(
239 'ACTION_URL' => ADMIN_URL.
"/login/tfa.php",
240 'token' => $_SESSION[
'LEPTOKENS'][0],
245 $this->oTwig->registerPath(
THEME_PATH.
"theme",
"tfa" );
246 echo $this->oTwig->render(
247 "@theme/tfa_form.lte",
252 elseif ( $id ==
'forward')
254 if(isset($_POST[
'token']) && strlen($_POST[
'pin']) == 6 )
257 $dbKey = $this->database->get_one(
"SELECT pin FROM ".TABLE_PREFIX.
"users WHERE user_id = ".$this->user_id);
258 $postKey = $_POST[
'pin'];
261 if(password_verify ($postKey, $dbKey) ===
true)
264 $this->database->simple_query(
"UPDATE ".TABLE_PREFIX.
"users SET `pin_set` = 2 WHERE user_id = ".$this->user_id);
266 header(
'Location: '.ADMIN_URL.
'/start/index.php?leptoken='.$_POST[
'token']);
270 header(
'Location: '.ADMIN_URL.
'/logout/index.php');
276 header(
'Location: '.ADMIN_URL.
'/logout/index.php');