Browse Source

Add mobile code login for Station client

tags/v2.0
Skylar Ittner 1 year ago
parent
commit
e5294bbecd
8 changed files with 64 additions and 0 deletions
  1. 8
    0
      api.php
  2. BIN
      database.mwb
  3. 19
    0
      database.sql
  4. 14
    0
      database_upgrade/1.0.1_1.1.sql
  5. 1
    0
      lang/en_us.php
  6. 12
    0
      mobile/index.php
  7. 9
    0
      nbproject/mplheader.txt
  8. 1
    0
      nbproject/project.properties

+ 8
- 0
api.php View File

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

BIN
database.mwb View File


+ 19
- 0
database.sql View File

@@ -1,5 +1,5 @@
1 1
 -- MySQL Script generated by MySQL Workbench
2
+-- Mon 18 Dec 2017 12:56:23 AM MST
2 3
 -- Model: New Model    Version: 1.0
3 4
 -- MySQL Workbench Forward Engineering
4 5
 
@@ -275,6 +275,24 @@ CREATE TABLE IF NOT EXISTS `accounthub`.`rate_limit` (
275 275
 ENGINE = MEMORY;
276 276
 
277 277
 
278
+-- -----------------------------------------------------
279
+-- Table `accounthub`.`onetimekeys`
280
+-- -----------------------------------------------------
281
+CREATE TABLE IF NOT EXISTS `accounthub`.`onetimekeys` (
282
+  `key` VARCHAR(10) NOT NULL,
283
+  `uid` INT NOT NULL,
284
+  `expires` DATETIME NOT NULL,
285
+  INDEX `fk_onetimekeys_accounts1_idx` (`uid` ASC),
286
+  PRIMARY KEY (`key`),
287
+  UNIQUE INDEX `key_UNIQUE` (`key` ASC),
288
+  CONSTRAINT `fk_onetimekeys_accounts1`
289
+    FOREIGN KEY (`uid`)
290
+    REFERENCES `accounthub`.`accounts` (`uid`)
291
+    ON DELETE NO ACTION
292
+    ON UPDATE NO ACTION)
293
+ENGINE = InnoDB;
294
+
295
+
278 296
 SET SQL_MODE=@OLD_SQL_MODE;
279 297
 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
280 298
 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

+ 14
- 0
database_upgrade/1.0.1_1.1.sql View File

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

+ 1
- 0
lang/en_us.php View File

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

+ 12
- 0
mobile/index.php View File

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

+ 9
- 0
nbproject/mplheader.txt View File

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

+ 1
- 0
nbproject/project.properties View File

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

Loading…
Cancel
Save