示例#1
0
 /**
  * Default action with registration form.
  *
  * @access     public
  * @return     View
  * @since      1.0.0
  * @version    2.1.0-dev
  */
 public function actionDefault()
 {
     // if user is logged, redirect to main page
     if (UserModel::isLogged()) {
         Route::factory('home')->redirectTo();
     }
     $this->setTitle(__('Register Your account'));
     $this->setKeywords(__('register account,login,email,password'));
     /* @var $oConfig ModelFormConfig */
     $oConfig = ModelFormConfig::factory();
     $oConfig->noReload();
     $oConfig->setFieldsRestriction(['login', 'email', 'password']);
     $oUser = new UserModel();
     $oModelForm = $oUser->form('register', $oConfig);
     /* @var $oModelForm \ModelForm\User */
     $oForm = $oModelForm->generate();
     // if form is submitted and is valid
     if ($oForm->isSubmittedAndValid()) {
         $this->sendActivationCode($oForm->get('password_confirm'), $oUser);
         $sMessage = __('Your account has been registered successfully. Activation link has been sent to your mailbox. Click it to make the final activation.');
         Session::flash(Router::getCurrentUrl(), $sMessage);
     }
     // return registration View
     return View::factory('user/frontend/register')->bind('oForm', $oForm);
 }
示例#2
0
 /**
  * Get logged user permissions.
  *
  * @static
  * @access     public
  * @return  array
  * @since      1.0.0, 2015-01-10
  * @version    1.0.0, 2015-01-10
  */
 public static function getPerms()
 {
     if (static::$aPermissions === NULL) {
         static::$aPermissions = Session::get('permissions');
     }
     return static::$aPermissions;
 }
示例#3
0
文件: Items.php 项目: ktrzos/plethora
 /**
  * Remove particular menu item after form submit (if form data is valid).
  *
  * @access     protected
  * @since      1.2.0-dev
  * @version    1.2.0-dev
  */
 protected function alterDelete()
 {
     $item = $this->getModel();
     /* @var $item \Model\Menu\Item */
     $item->remove();
     DB::flush();
     $controller = Router::getParam('controller');
     $id = $item->getMenu()->getId();
     $url = Route::backendUrl($controller, 'list', $id);
     Session::flash($url, __('Menu item has been deleted successfully.'));
 }
示例#4
0
文件: I18n.php 项目: ktrzos/plethora
 /**
  * ACTION which is used to clear all languages cache.
  *
  * @access     public
  * @since      1.2.0-dev
  * @version    1.2.0-dev
  */
 public function actionReloadCache()
 {
     try {
         I18nTools\Core::reloadCache();
         $msg = __('Cache has been successfully reloaded.');
         $msgType = 'success';
     } catch (Exception\Fatal\I18n $e) {
         $msg = '<b>Error occured while reloading translation cache:</b> <br />' . $e->getMessage();
         $msgType = 'danger';
     }
     $sURL = Route::factory('backend')->url(['controller' => 'i18n', 'action' => 'index']);
     Session::flash($sURL, $msg, $msgType);
 }
示例#5
0
 /**
  * Default action for database updating.
  *
  * @access   public
  * @return   View
  * @since    2014-08-17
  * @version  1.2.0-dev
  */
 public function actionDefault()
 {
     $this->addToTitle('Database updating module');
     // create update form
     $oForm = new Form('db_update');
     $oForm->setSubmitValue(__('make update'));
     // check if update button has been clicked
     if ($oForm->isSubmittedAndValid()) {
         $sUpdateOutput = static::makeUpdateNoExec();
         Cache::set($sUpdateOutput, 'output', 'dbupdate');
         Session::flash(Router::getCurrentUrl(), __('Database updated successfully.'));
     }
     // return View
     return View::factory('db_update/backend/default')->bind('oForm', $oForm);
 }
示例#6
0
文件: User.php 项目: ktrzos/plethora
 /**
  * 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);
 }
示例#7
0
文件: User.php 项目: ktrzos/plethora
 /**
  * Get currently logged user.
  *
  * @static
  * @access   public
  * @return   User
  * @since    2.0.2, 2013-12-25
  * @version  2.1.2-dev
  */
 public static function getLoggedUser()
 {
     if (static::$loggedUser === NULL && Session::get('uid') !== NULL) {
         static::$loggedUser = DB::find('\\Model\\User', Session::get('uid'));
     }
     return static::$loggedUser;
 }
示例#8
0
<?php

/* @version 1.0.1, 2014-11-27 */
/* @var $oUser \Model\User */
?>

<?php 
if (\Plethora\Router::getParam('id') == \Plethora\Session::get('uid')) {
    ?>
    <p style="text-align: center;">
        <a href="<?php 
    echo \Plethora\Route::factory('user_profile_edit')->url();
    ?>
" title="<?php 
    echo __('Edit profile');
    ?>
">
            [ <?php 
    echo __('Edit profile');
    ?>
 ]
        </a>
    </p>
<?php 
}
?>

<div class="user_profile">
    <table>
        <tbody>
        <tr>
示例#9
0
 /**
  * Action to set new password after e-mail validation.
  *
  * @access   public
  * @return   View
  * @since    1.0.0, 2015-02-17
  * @version  2.1.0-dev
  */
 public function actionNewPassword()
 {
     // fill up breadcrumbs title and other
     $this->addBreadCrumb(__('New password'));
     // get code from $_GET
     $sCode = Router::getParam('code');
     // get recovery code from DB
     $oRecoveryCode = DB::query("SELECT c FROM \\Model\\User\\RecoveryCode c WHERE c.code = :code")->param('code', $sCode)->single();
     /* @var $oResult User\RecoveryCode */
     // check if code exists
     if ($oRecoveryCode instanceof User\RecoveryCode) {
         $this->addToTitle(' - ' . __('New password'));
         // get user
         $oUser = $oRecoveryCode->getUser();
         // generate form for account access recovery
         $oConfig = ModelCore\ModelFormConfig::factory()->noReload()->setFieldsRestriction(['password'])->setMessage(__('Your password has been successfully changed to the new one.'))->setAction(Route::factory('password_recovery')->url());
         // get form
         $oModelForm = $oUser->form('new_password', $oConfig);
         $oForm = $oModelForm->generate();
         // check if form is valid
         if ($oForm->isSubmittedAndValid()) {
             $oRecoveryCode->remove();
             Session::flash(Route::factory('password_recovery')->url(), __('Password has been changed successfully.'));
         }
         $oForm->addToPrefix(View::factory('user/frontend/recovery/new_pass_prefix')->render());
         // return view
         return View::factory('base/form')->bind('oForm', $oForm);
     } else {
         $this->addToTitle(' - ' . __('Error occured'));
         return View::factory('user/frontend/recovery/wrong_code');
     }
 }
示例#10
0
 /**
  * Get data about failed login operations from cache.
  *
  * @static
  * @access  private
  * @return  integer
  * @since   2.1.2-dev
  * @version 2.1.2-dev
  */
 public static function getCachedData()
 {
     $ip = Session::get('ip');
     $cacheData = Cache::get($ip, static::$cacheName);
     return $cacheData;
 }
示例#11
0
文件: flash.php 项目: ktrzos/plethora
<?php

/**
 * @author         Krzysztof Trzos
 * @package        base
 * @subpackage     views
 * @since          1.0.0-alpha
 * @version        1.0.0-alpha
 */
?>

<?php 
$sFlash = \Plethora\Session::get('flash');
?>

<?php 
if (!is_null($sFlash)) {
    ?>
    <?php 
    $aUnserializedFlash = unserialize($sFlash);
    ?>

    <div class="alert alert-<?php 
    echo $aUnserializedFlash['type'];
    ?>
">
        <p><?php 
    echo $aUnserializedFlash['content'];
    ?>
</p>
    </div>
示例#12
0
 /**
  * Save new Model data. Method created for "public" uses, when needed to
  * make a save in, for example, controller.
  *
  * @access   protected
  * @param    Form $oForm
  * @throws   Exception
  * @throws   Exception\Fatal
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function makeSaveProtected(Form &$oForm)
 {
     $oConfig = $this->getConfig();
     try {
         $this->beforeSave($oForm);
         $this->getModel()->save();
         DB::flush();
         if ($oConfig == NULL || $oConfig->isReloading() === TRUE) {
             $sUrl = $oConfig->getAction() === NULL ? $oForm->getAttribute('action') : $oConfig->getAction();
             $sComm = $oConfig->getMessage() === NULL ? __('Form data submitted.') : $oConfig->getMessage();
             Session::flash($sUrl, $sComm);
         }
     } catch (Exception $e) {
         if (Config::get('base.mode') == 'development') {
             throw $e;
         } else {
             throw new Exception\Fatal(__('Error occured while saving data in database.'));
         }
     }
 }
示例#13
0
 /**
  * Remove particular entity after form submit and if form is valid.
  *
  * @access     protected
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 protected function alterDelete()
 {
     $this->getModel()->remove();
     DB::flush();
     $sController = Router::getParam('controller');
     $sID = Router::getParam('id', NULL);
     $sExtra = Router::getParam('extra', NULL);
     $sURL = Route::factoryBackendURL($sController, 'list', $sID, $sExtra);
     Session::flash($sURL, __('Entry has been deleted successfully.'));
 }
示例#14
0
 /**
  * Create response for particular Controller.
  *
  * @access   public
  * @param    View $oContent
  * @return   Response
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function createResponse(View $oContent = NULL)
 {
     if (is_null($oContent)) {
         $oContent = $this->{Router::getActionName()}();
         $this->afterAction();
     }
     $sContent = '';
     if ($oContent !== NULL) {
         $this->oView->bind('oContent', $oContent);
         // developers toolbar - CSS
         if (Router::hasModule('dev_toolbar') && \UserPermissions::hasPerm('dev_toolbar')) {
             $this->addJs('/themes/_common/js/dev_toolbar.js');
             $this->addCss('/themes/backend/css/dev_toolbar.css');
             $this->addBodyClass('dev_toolbar');
         }
         // render page View
         $sContent = $this->oViewMain->render();
         // add last benchmark
         Benchmark::mark('end');
         // developers toolbar
         if (Router::hasModule('dev_toolbar') && \UserPermissions::hasPerm('dev_toolbar')) {
             $sToolbar = \DevToolbar\Toolbar::factory()->render();
             $sContent = str_replace('</body>', $sToolbar . '</body>', $sContent);
         }
     }
     // create response
     $oResponse = new Response();
     $oResponse->setContent($sContent);
     // clear temp data after response creation
     Session::clearTempData();
     // return response
     return $oResponse;
 }
示例#15
0
文件: Form.php 项目: ktrzos/plethora
 /**
  * Get (generate) token for this form.
  *
  * @access   public
  * @return   string
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function getFormToken()
 {
     $sFormID = $this->getFormID();
     $aFormTokens = Session::get('form_tokens');
     if (!isset($aFormTokens[$sFormID]) || !is_array($aFormTokens[$sFormID]) || $aFormTokens[$sFormID][1] < time()) {
         $sToken = base64_encode(openssl_random_pseudo_bytes(16));
         $aFormTokens[$sFormID] = [$sToken, time() + 3600];
         Session::set('form_tokens', $aFormTokens);
     } else {
         $sToken = $aFormTokens[$sFormID][0];
     }
     return $sToken;
 }