Example #1
0
 public function actionCreate($roleType = null, $roleSlug = null)
 {
     $model = new User();
     $siteMember = new SiteMember();
     $model->setScenario('create');
     if (isset($roleSlug)) {
         $role = RoleService::findBySlug($roleSlug);
         $siteMember->roleId = $role->id;
     }
     if ($model->load(Yii::$app->request->post(), 'User') && $siteMember->load(Yii::$app->request->post(), 'SiteMember') && $model->validate()) {
         // Create User
         $user = UserService::create($model);
         // Add User to current Site
         $siteMember = SiteMemberService::create($model, $siteMember);
         if ($user && $siteMember) {
             // Load User Permissions
             $model->loadPermissions();
             // Send Account Mail
             Yii::$app->cmgCoreMailer->sendCreateUserMail($model);
             $this->redirect($this->returnUrl);
         }
     }
     if (isset($roleSlug)) {
         return $this->render('@cmsgears/module-core/admin/views/user/create', ['model' => $model, 'siteMember' => $siteMember]);
     } else {
         $roleMap = RoleService::getIdNameMapByType($roleType);
         return $this->render('@cmsgears/module-core/admin/views/user/create', ['sidebar' => $this->sidebar, 'model' => $model, 'siteMember' => $siteMember, 'roleMap' => $roleMap]);
     }
 }
 public static function create($user, $siteMember = null, $roleSlug = null)
 {
     // Find Current Site
     $site = Site::findByName(Yii::$app->cmgCore->getSiteName());
     if (!isset($siteMember)) {
         $siteMember = new SiteMember();
         if (isset($roleSlug)) {
             $role = RoleService::findBySlug($roleSlug);
             $siteMember->roleId = $role->id;
         } else {
             $role = RoleService::findBySlug(CoreGlobal::ROLE_USER);
             $siteMember->roleId = $role->id;
         }
     }
     $siteMember->siteId = $site->id;
     $siteMember->userId = $user->id;
     $siteMember->save();
     return $siteMember;
 }
Example #3
0
 /**
  * @return Site Member - assigned to User.
  */
 public function getSiteMember()
 {
     return $this->hasOne(SiteMember::className(), ['userId' => 'id']);
 }