Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login()
- {
- # checking for an API key, or else create one.
- if (!$this->get("API")) {
- # checking if there a login details in the data.
- if ($this->get("username") && $this->get("password")) {
- $username = $this->get("username");
- $password = $this->get("password");
- $user = $this->checkUserDetails($username, $password);
- } else {
- # throws error, and stops PHP from going further.
- $this->denyAccess(1);
- exit;
- }
- # If there is login data available
- if ($user === true) {
- # Creating unique API key
- $key = $this->createAPIKey();
- #for output
- # Creating timestamp.
- $time = $this->returnServerTime();
- $this->setUserDetails($username, $key, $time);
- $returnData = $key;
- } else {
- # If there is no login data, or they are missing.
- $returnData = "Wrong credentials.";
- }
- } else {
- $key = $this->get("API");
- if ($this->UserModel->checkUserKey($key)) {
- if ($this->LegalLoginTime($key) === false) {
- $this->destroyKey($key); # Removing key, asking to login again.
- $returnData = "Key is invalid!";
- } else {
- $returnData = "Key is still valid!";
- }
- } else {
- $returnData = "false";
- }
- }
- $this->showData($returnData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement