public function callback() { // initialize openid $openid = new \PSX\OpenId($this->http, $this->config['psx_url'], $this->store); if ($openid->verify() === true) { $identity = $openid->getIdentifier(); if (!empty($identity)) { // check whether user is already registered $data = $openid->getData(); $con = new Condition(array('identity', '=', sha1($this->config['amun_salt'] . $openid->getIdentifier()))); $userId = $this->hm->getTable('AmunService\\User\\Account')->getField('id', $con); if (empty($userId)) { // user doesnt exist so register a new user check whether // registration is enabled if (!$this->registry['login.registration_enabled']) { throw new Exception('Registration is disabled'); } // get data for account $acc = $this->getAccountData($data); if (empty($acc)) { throw new Exception('No user informations provided'); } if (empty($acc['name'])) { throw new Exception('No username provided'); } $name = $this->normalizeName($acc['name']); // create user account $security = new Security($this->registry); $handler = $this->hm->getHandler('AmunService\\User\\Account', $this->user); $account = $handler->getRecord(); $account->setGroupId($this->registry['core.default_user_group']); $account->setStatus(Account\Record::NORMAL); $account->setIdentity($identity); $account->setName($name); $account->setPw($security->generatePw()); $account->setGender($acc['gender']); $account->setTimezone($acc['timezone']); $account = $handler->create($account); $userId = $account->id; // if the id is not set the account was probably added to // the approval table if (!empty($userId)) { $this->setUserId($userId); } else { throw new Exception('Could not create account'); } } else { $this->setUserId($userId); } // redirect header('Location: ' . $this->config['psx_url']); exit; } else { throw new Exception('Invalid identity'); } } else { throw new Exception('Authentication failed'); } }