public static function login($username, $password) { Database::setup(); if (!Model_User::userExists($username, $password)) { throw new NonExistingUserException("User with the given credentials does not exists"); } else { $user = Model_User::findBy(array("username" => $username, "password" => $password)); $_SESSION['user'] = $user; } }
<?php /* *Test link *http://localhost/~matteo/web-lmul-rangers/api-user-exists.php?username=33windowlicker&password=12345678 */ require_once './global.php'; extract(GenericHelper::gatherGetData()); if (Model_User::userExists($username, $password)) { http_response_code(200); } else { http_response_code(400); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value doesn't exist already as user name * * @param string $value * @return boolean */ public function isValid($value) { $value = (string) $value; $this->_setValue($value); $mdlUser = new Model_User(); if (!$mdlUser->userExists($value, $this->getExclude())) { return true; } $this->_error(self::EXISTS); return false; }
<?php require_once './global.php'; require_once './helpers/unsecure.php'; extract(GenericHelper::gatherPostData()); if (isset($username) && isset($password) && Model_User::userExists($username, $password)) { Model_User::login($username, $password); $rdr_to = GenericHelper::getRedirectTo(); if (isset($rdr_to)) { header("Location: {$rdr_to}"); die; } header("Location: loginpage.php"); } else { header("Location: index.php?err=login-unsuccessful#login"); die; }