/**
  * Send email.
  * @param string $view mail template.
  * @param string $to destination email address.
  * @param array $params view parameters. Special parameter 'subject'
  * used for mail subject rest parameters passed to view.
  * @return boolean
  */
 public function mail($view, $to, array $params)
 {
     $views = ['html' => $view . '-html', 'text' => $view . '-text'];
     $subject = ArrayHelper::remove($params, 'subject');
     $compose = Yii::$app->mailer->compose($views, $params);
     if (!empty($subject)) {
         $compose->setSubject($subject);
     }
     $compose->setTo($to)->setFrom(Param::value('Site.adminEmail'));
     return $compose->send();
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->controller->goBack();
     }
     $model = new $this->modelClass();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->controller->goBack();
         } else {
             $this->controller->addFlash(Controller::FLASH_ERROR, Yii::t('app', 'Login to your account failed.'));
             $model->password = '';
         }
     }
     if (!Yii::$app->request->isPjax && Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     return $this->render(['model' => $model, 'disableUserRegister' => Param::value('User.disableUserRegister')]);
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (Param::value('User.disableUserRegister', false)) {
         throw new NotFoundHttpException();
     }
     if (!Yii::$app->user->isGuest) {
         return $this->controller->goBack();
     }
     $model = new $this->modelClass();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->register()) {
             $this->controller->addFlash('info', Yii::t('app', 'Registration successful. Now you can <a href="{login}">login</a>.', ['login' => Url::to(['user/login'])]));
             return $this->controller->goHome();
         }
     }
     if (!Yii::$app->request->isPjax && Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     return $this->render(['model' => $model]);
 }
Beispiel #4
0
 /**
  * Assign default role to user.
  * @param User $user
  * @return boolean
  */
 protected function assignDefaultRole(User $user)
 {
     $auth = Yii::$app->authManager;
     $roleName = Param::value('User.defaultRole');
     if (!$roleName) {
         return false;
     }
     if (!($role = $auth->getRole($roleName))) {
         Yii::warning('Cannot find role: ' . $roleName);
         return false;
     }
     $auth->assign($role, $user->id);
     return true;
 }
Beispiel #5
0
<?php

/**
 * Don't edit this file.
 * Put your modifications to APPROOT_DIR . '/config.php'
 */
$config = ['id' => 'admin', 'name' => 'Admin Template', 'bootstrap' => ['log'], 'components' => ['cache' => ['class' => 'yii\\caching\\FileCache'], 'user' => ['identityClass' => 'app\\models\\User', 'enableAutoLogin' => true, 'loginUrl' => ['user/login']], 'formatter' => ['class' => 'app\\base\\Formatter'], 'errorHandler' => ['errorAction' => 'site/error'], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer', 'useFileTransport' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['login' => 'user/login', 'register' => 'user/register', 'logout' => 'user/logout', 'users' => 'user/index', 'user/<id:[0-9]+>' => 'user/profile']], 'menu' => ['class' => 'app\\components\\Menu', 'title' => ['main-nav' => 'Main navigation'], 'items' => ['main-nav' => [['label' => 'Administer', 'icon' => 'fa fa-user-secret', 'url' => '#', 'items' => [['label' => 'Users', 'icon' => 'fa fa-circle-o', 'url' => ['/user/index'], 'roles' => ['viewAnyUser']], ['label' => 'Settings', 'icon' => 'fa fa-circle-o', 'url' => ['/site/settings'], 'roles' => function () {
    return \app\components\Param::getSectionPermissions();
}]], 'roles' => function () {
    $roles = \app\components\Param::getSectionPermissions();
    $roles[] = 'viewAnyUser';
    return $roles;
}], ['label' => 'Development', 'icon' => 'fa fa-building-o', 'url' => '#', 'items' => [['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii/default/index']], ['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug/default/index']]], 'guest' => false, 'visible' => YII_DEBUG], ['label' => 'Login', 'icon' => 'fa fa-sign-in', 'url' => ['/user/login'], 'guest' => true], ['label' => 'Register', 'icon' => 'fa fa-user-plus', 'url' => ['/user/register'], 'guest' => true, 'visible' => function () {
    return !\app\components\Param::value('User.disableUserRegister');
}], ['label' => 'Logout', 'icon' => 'fa fa-sign-out', 'url' => ['/user/logout'], 'guest' => false]]]]], 'params' => [], 'modules' => []];
return yii\helpers\ArrayHelper::merge(require APPROOT_DIR . '/app/config/common.php', $config);
Beispiel #6
0
/** @var $tab string current active tab */
$this->title = Yii::t('app', 'User Profile');
if (Yii::$app->user->can('viewAnyUser')) {
    $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']];
}
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="row">
    
    <div class="col-md-3">
        <?php 
Box::begin(['box' => Box::BOX_PRIMARY, 'bodyOptions' => ['class' => 'box-profile']]);
?>
            <?php 
echo Html::img(Param::value('User.noAvatarImage'), ['class' => 'profile-user-img img-responsive img-circle']);
?>
            <h3 class="profile-username text-center">
                <?php 
echo Html::encode($model->name);
?>
            </h3>
            <p class="text-muted text-center">
                <?php 
echo Yii::t('app', 'Member since {date}', ['date' => Yii::$app->formatter->asDate(Yii::$app->user->identity->created_at)]);
?>
            </p>
            <?php 
echo ItemList::widget(['items' => [['title' => 'ID', 'value' => $model->getUser()->id], ['title' => Yii::t('app', 'Status'), 'value' => UserHelper::status($model->getUser())], ['title' => Yii::t('app', 'Last login'), 'value' => Yii::$app->formatter->asRelativeTime($model->getUser()->logged_at)]]]);
?>
        <?php 
Beispiel #7
0
 /**
  * Check current user's permission for section.
  * @param string $section
  * @return boolean
  */
 protected function checkSectionAccess($section = '')
 {
     $permissions = Param::getSectionPermissions($section);
     foreach ($permissions as $permName) {
         if (Yii::$app->user->can($permName)) {
             return true;
         }
     }
     return false;
 }
Beispiel #8
0
    ?>
                <li class="dropdown user user-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <?php 
    echo Html::img(Param::value('User.noAvatarImage'), ['class' => 'user-image']);
    ?>
                        <span class="hidden-xs"><?php 
    echo Html::encode(Yii::$app->user->identity->name);
    ?>
</span>
                    </a>
                    <ul class="dropdown-menu">
                        <!-- User image -->
                        <li class="user-header">
                            <?php 
    echo Html::img(Param::value('User.noAvatarImage'), ['class' => 'img-circle']);
    ?>
                            <p>
                                <?php 
    echo Html::encode(Yii::$app->user->identity->name);
    ?>
                                <small><?php 
    echo Yii::t('app', 'Member since {date}', ['date' => Yii::$app->formatter->asDate(Yii::$app->user->identity->created_at)]);
    ?>
</small>
                            </p>
                        </li>
                        <!-- Menu Body -->
                        <li class="user-body">
                            <div class="col-xs-4 text-center">
                                <a href="#">Followers</a>
 /**
  * Add or remove roles to User.defaultRole parameter.
  * @param boolean $uninstall remove roles instead adding.
  */
 protected function addRolesToDefaultRoleList($uninstall = false)
 {
     if (!($roles = ArrayHelper::getValue($this->rbac, 'roles'))) {
         return;
     }
     if (!($config = Param::getConfig('User.defaultRole'))) {
         return;
     }
     foreach ($roles as $roleName => $ignore) {
         $options = $config->options;
         if ($uninstall && isset($options[$roleName])) {
             unset($options[$roleName]);
         } elseif (!$uninstall && !isset($options[$roleName])) {
             $options[$roleName] = $roleName;
         }
         $config->options = $options;
     }
     $config->save();
 }
Beispiel #10
0
 /**
  * Finds user by password reset token.
  * 
  * Expire of reset token adjusted by 'passwordResetTokenExpire' 
  * configuration parameter:
  * ```php
  *  'params' => [
  *      'passwordResetTokenExpire' => 3600, // 1 hour.
  *  ],
  * ```
  * 
  * @param string $token
  * @return User|null
  */
 public static function findByResetToken($token)
 {
     $expire = Param::value('User.passwordResetTokenExpire', 3600);
     // Is token expired ?
     $list = explode('_', $token);
     $time = (int) end($list);
     if ($time + $expire < time()) {
         return null;
     }
     return static::findOne(['reset_token' => $token, 'status' => self::STATUS_ENABLED]);
 }