예제 #1
0
 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;
 }
예제 #2
0
 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);
 }
예제 #3
0
 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());
 }
예제 #4
0
파일: ApiTest.php 프로젝트: gudwin/extasy
 /**
  * @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();
 }
예제 #5
0
 public function testLogout()
 {
     \UsersLogin::login(self::Login, self::Password);
     $this->AssertTrue(\UsersLogin::isLogined());
     $api = new Logout();
     $api->exec();
     $this->AssertFalse(\UsersLogin::isLogined());
     //
 }
예제 #6
0
 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());
 }
예제 #7
0
 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());
 }
예제 #8
0
 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'];
 }
예제 #9
0
파일: fixtures.php 프로젝트: gudwin/extasy
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);
예제 #10
0
파일: Login.php 프로젝트: gudwin/extasy
 protected function action()
 {
     \UsersLogin::login($this->getParam('login'), $this->getParam('password'));
     return true;
 }