LoginAction.class.php 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. class LoginAction implements IAction {
  3. public function execute() {
  4. $username = $_POST['username'] ?? $_GET['username'] ?? "";
  5. $password = $_POST['password'] ?? $_GET['password'] ?? "";
  6. if(!isset($username) || !isset($password) || empty($username) || empty($password))
  7. {
  8. return array("error" => "Username or password is required.");
  9. }
  10. $authData = $this->domainLogin($username, $password);
  11. if($authData) {
  12. $loggerData = array();
  13. $loggerData['display_name'] = $authData['display_name'];
  14. $loggerData['user_id'] = $authData['user_id'];
  15. SecurityLogger::action("login", $loggerData, time());
  16. return $authData;
  17. }
  18. $loggerData = array();
  19. $loggerData['attempted_username'] = $username;
  20. $loggerData['ip_address'] = $_SERVER['REMOTE_ADDR'];
  21. SecurityLogger::action("login-failed", $loggerData, time());
  22. return array("error" => "Username or password is invalid.");
  23. }
  24. private function domainLogin($username, $password) {
  25. return (new Authorize())->login($username, $password);
  26. }
  27. }