diff --git a/api/actions/checkloginkey.php b/api/actions/checkloginkey.php new file mode 100644 index 0000000..8f70c47 --- /dev/null +++ b/api/actions/checkloginkey.php @@ -0,0 +1,15 @@ + "OK", "uid" => $uid]); +} catch (Exception $ex) { + sendJsonResp("", "ERROR"); +} diff --git a/api/actions/getloginkey.php b/api/actions/getloginkey.php new file mode 100644 index 0000000..166b488 --- /dev/null +++ b/api/actions/getloginkey.php @@ -0,0 +1,17 @@ + "OK", "code" => $code, "loginurl" => $url]); diff --git a/api/apisettings.php b/api/apisettings.php index b8b8222..043b339 100644 --- a/api/apisettings.php +++ b/api/apisettings.php @@ -212,4 +212,16 @@ $APIS = [ "id" => "numeric" ] ], + "getloginkey" => [ + "load" => "getloginkey.php", + "vars" => [ + "appname" => "string" + ] + ], + "checkloginkey" => [ + "load" => "checkloginkey.php", + "vars" => [ + "code" => "string" + ] + ] ]; diff --git a/database.mwb b/database.mwb index 4afbe0b..9479ae4 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/database_upgrade/2.1_3.0.sql b/database_upgrade/2.1_3.0.sql new file mode 100644 index 0000000..0992672 --- /dev/null +++ b/database_upgrade/2.1_3.0.sql @@ -0,0 +1,28 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +DROP TABLE IF EXISTS `available_apps`; +DROP TABLE IF EXISTS `apps`; + +CREATE TABLE IF NOT EXISTS `userloginkeys` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `key` VARCHAR(255) NOT NULL, + `expires` DATETIME NULL DEFAULT NULL, + `uid` INT(11) NULL DEFAULT NULL, + PRIMARY KEY (`id`, `key`), + UNIQUE INDEX `id_UNIQUE` (`id` ASC), + UNIQUE INDEX `key_UNIQUE` (`key` ASC), + INDEX `fk_userloginkeys_accounts1_idx` (`uid` ASC), + CONSTRAINT `fk_userloginkeys_accounts1` + FOREIGN KEY (`uid`) + REFERENCES `accounts` (`uid`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + +ALTER TABLE `userloginkeys` +ADD COLUMN `appname` VARCHAR(255) NOT NULL AFTER `uid`; \ No newline at end of file diff --git a/index.php b/index.php index 414accd..a922a89 100644 --- a/index.php +++ b/index.php @@ -1,238 +1,84 @@ exists()) { - $status = $user->getStatus()->getString(); - switch ($status) { - case "LOCKED_OR_DISABLED": - $alert = $Strings->get("account locked", false); - break; - case "TERMINATED": - $alert = $Strings->get("account terminated", false); - break; - case "CHANGE_PASSWORD": - $alert = $Strings->get("password expired", false); - $alerttype = "info"; - $_SESSION['username'] = $user->getUsername(); - $_SESSION['uid'] = $user->getUID(); - $change_password = true; - break; - case "NORMAL": - $username_ok = true; - break; - case "ALERT_ON_ACCESS": - $mail_resp = $user->sendAlertEmail(); - if ($SETTINGS['debug']) { - var_dump($mail_resp); - } - $username_ok = true; - break; - default: - if (!empty($error)) { - $alert = $error; - } else { - $alert = $Strings->get("login error", false); - } - break; - } - if ($username_ok) { - if ($user->checkPassword($VARS['password'])) { - $_SESSION['passok'] = true; // stop logins using only username and authcode - if ($user->has2fa()) { - $multiauth = true; - } else { - Session::start($user); - Log::insert(LogType::LOGIN_OK, $user->getUID()); - header('Location: app.php'); - die("Logged in, go to app.php"); - } - } else { - $alert = $Strings->get("login incorrect", false); - Log::insert(LogType::LOGIN_FAILED, null, "Username: " . $VARS['username']); - } - } - } else { // User does not exist anywhere - $alert = $Strings->get("login incorrect", false); - Log::insert(LogType::LOGIN_FAILED, null, "Username: " . $VARS['username']); +if (!empty($_GET['logout'])) { + // Show a logout message instead of immediately redirecting to login flow + ?> + + + + + +