Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. public function login()
  2.     {
  3.         # checking for an API key, or else create one.
  4.  
  5.         if (!$this->get("API")) {
  6.             # checking if there a login details in the data.
  7.            if ($this->get("username") && $this->get("password")) {
  8.                 $username = $this->get("username");
  9.                 $password = $this->get("password");
  10.                 $user = $this->checkUserDetails($username, $password);
  11.             } else {
  12.                 # throws error, and stops PHP from going further.
  13.                $this->denyAccess(1);
  14.                 exit;
  15.             }
  16.  
  17.             # If there is login data available
  18.            if ($user === true) {
  19.                 # Creating unique API key
  20.                $key = $this->createAPIKey();
  21.                 #for output
  22.                # Creating timestamp.
  23.                $time = $this->returnServerTime();
  24.                 $this->setUserDetails($username, $key, $time);
  25.  
  26.                 $returnData = $key;
  27.             } else {
  28.                 # If there is no login data, or they are missing.
  29.                $returnData = "Wrong credentials.";
  30.             }
  31.         } else {
  32.             $key = $this->get("API");
  33.             if ($this->UserModel->checkUserKey($key)) {
  34.                 if ($this->LegalLoginTime($key) === false) {
  35.                     $this->destroyKey($key); # Removing key, asking to login again.
  36.                    $returnData = "Key is invalid!";
  37.                 } else {
  38.                     $returnData = "Key is still valid!";
  39.                 }
  40.             } else {
  41.                 $returnData = "false";
  42.             }
  43.         }
  44.         $this->showData($returnData);
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement