public function check() { if (!UsersLogin::isLogined()) { $this->user = null; } $needAuth = empty($this->user); if ($needAuth) { $authDataPresent = !empty($this->login) || !empty($this->password); try { if ($authDataPresent || UsersLogin::isLogined()) { if ($authDataPresent) { UsersLogin::login($this->login, $this->password); } } $this->user = UsersLogin::getCurrentUser(); $this->processUser(); } catch (ForbiddenException $e) { $this->authProc(); return false; } catch (\NotFoundException $e) { $this->authProc(); return false; } } return true; }
public function setUp() { parent::setUp(); Restorator::restore(); Helper::setupUsers([['login' => self::RootLogin, 'password' => self::Password, 'rights' => [\CMSAuth::AdministratorRoleName => true]]]); \UsersLogin::login(self::RootLogin, self::Password); }
public function testIsVisible() { \UsersLogin::login(self::GuestUser, Helper::DefaultPassword); $item = new MenuItem(); $this->assertFalse($item->isVisible()); \UsersLogin::login(self::AdminUser, Helper::DefaultPassword); $this->assertTrue($item->isVisible()); }
/** * @expectedException \ForbiddenException */ public function testPermissionRequired() { TestsHelper::dbFixture(USERS_TABLE, array(array('login' => 'login', 'password' => passwordColumn::hash('testtest')))); TestsHelper::dbFixture(\ACL_GRANT_TABLE, array()); // \UsersLogin::login('login', 'testtest'); $operation = new ApiOperation(); $operation->exec(); }
public function testLogout() { \UsersLogin::login(self::Login, self::Password); $this->AssertTrue(\UsersLogin::isLogined()); $api = new Logout(); $api->exec(); $this->AssertFalse(\UsersLogin::isLogined()); // }
public function testCallApiOperationWithGrants() { TestsHelper::dbFixture(\UserAccount::getTableName(), array(array('login' => 'test', 'password' => passwordColumn::hash('testtest')))); $user = \UserAccount::getById(1); \ACL::create(TestApiWithACLOperation::RightName); \ACL::grant(TestApiWithACLOperation::RightName, $user->obj_rights->getEntity()); \UsersLogin::login('test', 'testtest'); $method = new TestApiWithACLOperation(); $this->assertTrue($method->exec()); }
public function testAddCustomListener() { \UsersLogin::login('root', self::PASSWORD); \EventController::addRuntimeEventListener(Search::EventName, function ($request) { $result = new SearchResultModel(); $result->title = 'world!'; $results = [$result]; return $results; }); $api = new Search(['request' => 'hello?']); $response = $api->exec(); $this->assertEquals('world!', $response['items'][0]->title->getValue()); }
public static function signup($login, $password, $email, $aData) { self::validateLogin($login); self::validateEmail($email); // Проверка данных EventController::callEvent('users_registration_check_data', $login, $password, $email, $aData); // Проверка существования логина и почты self::checkLoginOrEmailExists($login, $email); $register = new SystemRegister('Applications/users/front-end/'); // Если требуется подтвержденте if ($register->account_confirmation->value) { // Код подтверждения $aData['confirmation_code'] = self::getConfirmationCode(); } // $aData['login'] = $login; $aData['email'] = $email; $user = new UserAccount($aData); $user->obj_password->setValue($password); $user->insert(); // Добавлени в базу $aData['id'] = $user->id->getValue(); $aData['password'] = $password; // Вызов события EventController::callEvent('users_registration_after_signup', $aData, $user); // // Если требуется подтверждение if ($register->account_confirmation->value) { // Высылка письма self::sendEmailConfirmation($aData); } else { UsersLogin::login($login, $password); } if ($register->account_registration_success_email->value) { // Высылка письма self::sendEmailRegistration($aData); } return $aData['id']; }
use Extasy\Columns\Password as passwordColumn; $register = new \SystemRegister('/System/'); try { $register->delete('Audit'); } catch (\Exception $e) { } Restorator::restore(); \SystemRegisterSample::createCache(); TestsHelper::dbFixture(ACL_TABLE, array()); ACL::create(ApiOperation::RightName); // user record TestsHelper::dbFixture(USERS_TABLE, array(array('login' => 'login', 'password' => passwordColumn::hash('testtest')), array('login' => 'guest', 'password' => passwordColumn::hash('testtest')))); // grant user permission $user = UserAccount::getByLogin('login'); ACL::grant(ApiOperation::RightName, $user->obj_rights->getEntity()); \UsersLogin::login('login', 'testtest'); // base logs TestsHelper::dbFixture(Log::getTableName(), array(array('name' => 'Log1', 'critical' => 0, 'enable_logging' => 1), array('name' => 'Log2', 'critical' => 1, 'enable_logging' => 1))); // base records // - [different by user_id] // - [different by date] // - [different by content] TestsHelper::dbFixture(Record::getTableName(), array(array('log_id' => 1, 'date' => '2001-01-01 00:00:00', 'short' => 'short log', 'full' => 'full_log', 'user_id' => 1, 'user_login' => 'login'), array('log_id' => 2, 'date' => '2001-01-02 00:00:00', 'short' => 'short log', 'full' => 'full_log', 'user_id' => 1, 'user_login' => 'login'), array('log_id' => 1, 'date' => '2001-01-03 00:00:00', 'short' => 'short log', 'full' => 'full_log'))); // Create custom config if it exists $schemaName = 'Audit.CriticalEventName'; try { $config = \CConfig::getSchema($schemaName); $config->delete(); } catch (\Exception $e) { } finally { $config = \CConfig::createSchema($schemaName);
protected function action() { \UsersLogin::login($this->getParam('login'), $this->getParam('password')); return true; }