Add mobile code login for Station client

V2_Rewrite
Skylar Ittner 6 years ago
parent 1a6ea182e2
commit e5294bbecd

@ -288,6 +288,14 @@ switch ($VARS['action']) {
exit(json_encode(["status" => "OK"])); exit(json_encode(["status" => "OK"]));
} }
exit(json_encode(["status" => "ERROR", "msg" => $result])); exit(json_encode(["status" => "ERROR", "msg" => $result]));
case "codelogin":
$database->delete("onetimekeys", ["expires[<]" => date("Y-m-d H:i:s")]); // cleanup
if ($database->has("onetimekeys", ["key" => $VARS['code'], "expires[>]" => date("Y-m-d H:i:s")])) {
$user = $database->get("onetimekeys", ["[>]accounts" => ["uid" => "uid"]], ["username", "realname", "accounts.uid"], ["key" => $VARS['code']]);
exit(json_encode(["status" => "OK", "user" => $user]));
} else {
exit(json_encode(["status" => "ERROR", "msg" => lang("no such code or code expired", false)]));
}
default: default:
http_response_code(404); http_response_code(404);
die(json_encode("404 Not Found: the requested action is not available.")); die(json_encode("404 Not Found: the requested action is not available."));

Binary file not shown.

@ -1,5 +1,5 @@
-- MySQL Script generated by MySQL Workbench -- MySQL Script generated by MySQL Workbench
-- Mon 20 Nov 2017 08:36:18 PM MST -- Mon 18 Dec 2017 12:56:23 AM MST
-- Model: New Model Version: 1.0 -- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering -- MySQL Workbench Forward Engineering
@ -275,6 +275,24 @@ CREATE TABLE IF NOT EXISTS `accounthub`.`rate_limit` (
ENGINE = MEMORY; ENGINE = MEMORY;
-- -----------------------------------------------------
-- Table `accounthub`.`onetimekeys`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `accounthub`.`onetimekeys` (
`key` VARCHAR(10) NOT NULL,
`uid` INT NOT NULL,
`expires` DATETIME NOT NULL,
INDEX `fk_onetimekeys_accounts1_idx` (`uid` ASC),
PRIMARY KEY (`key`),
UNIQUE INDEX `key_UNIQUE` (`key` ASC),
CONSTRAINT `fk_onetimekeys_accounts1`
FOREIGN KEY (`uid`)
REFERENCES `accounthub`.`accounts` (`uid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE; SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

@ -0,0 +1,14 @@
CREATE TABLE IF NOT EXISTS `onetimekeys` (
`key` VARCHAR(10) NOT NULL,
`uid` INT(11) NOT NULL,
`expires` DATETIME NOT NULL,
INDEX `fk_onetimekeys_accounts1_idx` (`uid` ASC),
PRIMARY KEY (`key`),
UNIQUE INDEX `key_UNIQUE` (`key` ASC),
CONSTRAINT `fk_onetimekeys_accounts1`
FOREIGN KEY (`uid`)
REFERENCES `accounthub`.`accounts` (`uid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8

@ -95,4 +95,5 @@ $STRINGS = [
"secret key" => "Secret key", "secret key" => "Secret key",
"label" => "Label", "label" => "Label",
"issuer" => "Issuer", "issuer" => "Issuer",
"no such code or code expired" => "That code is incorrect or expired."
]; ];

@ -117,6 +117,18 @@ switch ($VARS['action']) {
} }
} }
exit(json_encode(["status" => "OK", "apps" => $apps])); exit(json_encode(["status" => "OK", "apps" => $apps]));
case "gencode":
engageRateLimit();
$uid = $database->get("accounts", "uid", ["username" => $username]);
$code = "";
do {
$code = random_int(100000, 999999);
} while ($database->has("onetimekeys", ["key" => $code]));
$database->insert("onetimekeys", ["key" => $code, "uid" => $uid, "expires" => date("Y-m-d H:i:s", strtotime("+1 minute"))]);
$database->delete("onetimekeys", ["expires[<]" => date("Y-m-d H:i:s")]); // cleanup
exit(json_encode(["status" => "OK", "code" => $code]));
default: default:
http_response_code(404); http_response_code(404);
die(json_encode(["status" => "ERROR", "msg" => "The requested action is not available."])); die(json_encode(["status" => "ERROR", "msg" => "The requested action is not available."]));

@ -0,0 +1,9 @@
<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix}This Source Code Form is subject to the terms of the Mozilla Public
${licensePrefix}License, v. 2.0. If a copy of the MPL was not distributed with this
${licensePrefix}file, You can obtain one at http://mozilla.org/MPL/2.0/.
<#if licenseLast??>
${licenseLast}
</#if>

@ -1,5 +1,6 @@
include.path=${php.global.include.path} include.path=${php.global.include.path}
php.version=PHP_70 php.version=PHP_70
project.licensePath=./nbproject/mplheader.txt
source.encoding=UTF-8 source.encoding=UTF-8
src.dir=. src.dir=.
tags.asp=false tags.asp=false

Loading…
Cancel
Save