public function create($data) { // Action used for POST requests if (isset($data['userName'], $data['password']) == false) { throw new \Exception("Required data has not been provided to the method."); return; } $request = $this->getRequest(); $credentials = new Credentials(); $credentials->setUserName($data['userName'])->setPassword($data['password'])->setIpAddress($request->getServer('REMOTE_ADDR')); $authenticateService = $this->getServiceLocator()->get('Auth\\Service\\Authenticate'); $credentials = $authenticateService->login($credentials); $userName = $credentials[0]['username']; return new JsonModel(array('data' => array('id' => $credentials))); }
/** * @param CredentialsDto $credentials * @return mixed * @throws \Exception */ public function login(CredentialsDto $credentials) { /* Check that all required credentials are set */ if ($credentials->getIpAddress() == "" || $credentials->getUserName() == "" || $credentials->getPassword() == "") { throw new \InvalidArgumentException("Required credentials have not been defined"); } $identityModel = $this->getIdentity()->getIdentityByCredentials($credentials->getUserName()); if (empty($identityModel)) { throw new \Exception("Invalid Username/Password"); } if ($identityModel[0]['password'] != $this->hashPassword($credentials->getPassword())) { throw new \Exception("Username and/or password does not match."); } return $identityModel; }