Ejemplo n.º 1
0
 /**
  * @access   public
  * @return   Form
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public static function getForm()
 {
     if (static::$singleTonForm === NULL) {
         static::$singleTonForm = Form::factory('singletons');
     }
     return static::$singleTonForm;
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /** @noinspection PhpMissingParentCallCommonInspection */
 public function actionDefault()
 {
     // create pass recovery form
     $oForm = Form::factory('password_recovery');
     $emailField = Form\Field\Text::factory('email', $oForm)->setRequired()->setLabel('E-mail');
     $oForm->addField($emailField);
     $oForm->addField(Form\Field\Captcha::factory('captcha', $oForm));
     // if form is valid
     if ($oForm->isSubmittedAndValid()) {
         $sEmail = $oForm->getField('email')->getValueFirst();
         // find user with particular e-mail
         $query = DB::query('SELECT u FROM \\Model\\User u WHERE u.email = :email');
         $query->param('email', $sEmail);
         $oResult = $query->single();
         /* @var $oResult User */
         if ($oResult instanceof User) {
             $this->sendRecoveryCode($oResult);
             $sMessage = __("Message has been sent on your e-mail address. Click on the link from it's content to recover password to your account.");
             Session::flash(Router::getCurrentUrl(), $sMessage);
         }
     }
     // return view
     return View::factory('user/frontend/recovery/default')->bind('oForm', $oForm);
 }
Ejemplo n.º 4
0
 /**
  * Contructor. The search engine form is generated in here.
  *
  * @access    public
  * @param     ModelCore $oModel
  * @since     1.0.0-alpha
  * @version   1.0.0-alpha
  */
 public function __construct(ModelCore $oModel)
 {
     $this->oModel = $oModel;
     $sModelClass = $oModel->getClass();
     $aQueryParams = Router::getQueryStringParams();
     $aDefaults = [];
     $sFormName = 'search_engine_for_' . str_replace('\\', '_', strtolower($sModelClass));
     if (count($aQueryParams) > 0) {
         foreach ($aQueryParams as $sKey => $sValue) {
             $aDefaults[$sKey] = ['und' => [0 => $sValue]];
         }
     }
     $oForm = Form::factory($sFormName, $aDefaults)->setView($this->getFormView())->setFieldsNameWithPrefix(FALSE)->removeCsrfToken();
     $this->setForm($oForm);
 }