Exemplo n.º 1
0
 /**
  * ACTION - User login.
  *
  * @access   public
  * @return   View
  * @since    1.0.2, 2013-12-07
  * @version  1.0.7-dev, 2015-05-04
  */
 public function actionLogin()
 {
     $this->setTitle(Core::getAppName() . ' - ' . __('Login form'));
     $this->addBreadCrumb(__('Login form'));
     $oLoggedUser = Model\User::getLoggedUser();
     if ($oLoggedUser instanceof Model\User) {
         Route::factory('user_profile')->redirectTo(['id' => $oLoggedUser->getId()]);
     }
     $failedLogins = \User\LoginFail::getCachedData();
     if ($failedLogins > 4) {
         return View::factory('base/alert')->set('sType', 'danger')->set('sMsg', __('to.many.incorrect.logins'));
     }
     $oLoginForm = Form::factory('login');
     $oLoginForm->addField(Form\Field\Text::factory('login', $oLoginForm));
     $oLoginForm->addField(Form\Field\Password::factory('password', $oLoginForm));
     if ($oLoginForm->isSubmittedAndValid()) {
         $sUsername = $oLoginForm->get('login');
         $sPassword = $oLoginForm->get('password');
         $sEncryptedPassword = Helper\Encrypter::factory()->encrypt($sUsername, $sPassword);
         $oUser = DB::query("SELECT u FROM \\Model\\User u WHERE u.login = :login AND u.password = :pass")->param('login', $sUsername)->param('pass', $sEncryptedPassword)->single();
         if ($oUser instanceof Model\User) {
             Session::set('username', $sUsername);
             Session::set('uid', (int) $oUser->getId());
             $oUser->setLoginDateNOW();
             DB::flush();
             # Get role permissions for particular user and set them in session
             \UserPermissions::reset();
             Route::factory(Router::getCurrentRouteName())->redirectTo();
         } else {
             $currentUrl = Router::currentUrl();
             $alert = __('You have entered wrong username or password. Try again.');
             \User\LoginFail::addLoginFail();
             Session::flash($currentUrl, $alert, 'danger');
         }
     }
     $oLoginForm->addToSuffix(View::factory('user/frontend/login_links')->render());
     return View::factory('base/form')->bind('oForm', $oLoginForm);
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @access     public
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function __construct()
 {
     // renew logged user permissions (only for those users, which already have some permissions)
     if (!is_null(Session::get('uid')) && !is_null(Session::get('perm'))) {
         \UserPermissions::reset();
     }
     // set default page title and description (based on app config "base")
     $this->setTitle(Config::get('base.app_name'));
     $this->setDescription(Config::get('base.app_description'));
     $this->setBodyBasicClasses();
     // initalize basic views
     $this->oViewMain = View::factory($this->sViewMain);
     $this->oViewBody = View::factory($this->sViewBody);
     $this->oViewBodyContent = View::factory($this->sViewBodyContent);
     $this->oViewBodyFooter = View::factory($this->sViewBodyFooter);
     $this->oViewBodyHeader = View::factory($this->sViewBodyHeader);
     $this->oViewHead = View::factory($this->sViewHead);
     $this->oView = View::factory($this->sView);
     $this->oViewBreadcrumbs = View::factory($this->sViewBreadcrumbs);
     $this->oViewSystemMessages = View::factory($this->sViewSystemMessages);
     // relate views with each other
     $this->oViewMain->bind('oHead', $this->oViewHead);
     $this->oViewMain->bind('oBody', $this->oViewBody);
     $this->oViewMain->bind('sBodyClasses', $this->sBodyClasses);
     $this->oViewBody->bind('sTitle', $this->sTitle);
     $this->oViewBody->bind('oHeader', $this->oViewBodyHeader);
     $this->oViewBody->bind('oContent', $this->oViewBodyContent);
     $this->oViewBody->bind('oFooter', $this->oViewBodyFooter);
     $this->oViewBodyContent->bind('oContent', $this->oView);
     $this->oViewBodyContent->bind('oController', $this);
     $this->oViewBodyContent->bind('oBreadcrumbs', $this->oViewBreadcrumbs);
     $this->oViewBodyContent->bind('oSystemMessages', $this->oViewSystemMessages);
     $this->oViewBreadcrumbs->bind('aBreadcrumbs', $this->aBreadcrumbs);
     $this->oViewSystemMessages->bind('aSystemMessages', $this->aSystemMessages);
     $this->oViewHead->bind('sTitle', $this->sTitle);
     $this->oViewHead->bind('aCss', $this->css);
     $this->oViewHead->bind('aJs', $this->js);
     $this->oViewHead->bind('aMeta', $this->aMeta);
     // set default meta
     $this->findDefaultMeta();
     // Create log about Controller initalization
     Log::insert('Main controller class initialized!');
 }