Esempio n. 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]);
     }
 }
 function register($googleUser)
 {
     $user = new User();
     $date = DateUtil::getDateTime();
     $user->email = $googleUser->email;
     $user->firstName = $googleUser->given_name;
     $user->lastName = $googleUser->family_name;
     $user->newsletter = 0;
     $user->registeredAt = $date;
     $user->status = User::STATUS_ACTIVE;
     $user->generateVerifyToken();
     $user->generateAuthKey();
     $user->save();
     return $user;
 }
Esempio n. 3
0
 /**
  * The method delete existing user.
  * @param User $user
  * @return boolean
  */
 public static function delete($user)
 {
     // Find existing user
     $userToDelete = User::findById($user->id);
     // Delete User
     $userToDelete->delete();
     return true;
 }
Esempio n. 4
0
 /**
  * @return array - list of site Users
  */
 public function getUsers()
 {
     return $this->hasMany(User::className(), ['id' => 'memberId'])->viaTable(CoreTables::TABLE_SITE_MEMBER, ['siteId' => 'id']);
 }
Esempio n. 5
0
 public static function getPaginationByPermissionSlug($permissionSlug)
 {
     $permissionTable = CoreTables::TABLE_PERMISSION;
     return self::getPagination(['conditions' => ["{$permissionTable}.slug" => $permissionSlug], 'query' => User::findWithSiteMemberPermission()]);
 }
Esempio n. 6
0
 /**
  * @return User
  */
 public function getNotifier()
 {
     return $this->hasOne(User::className(), ['id' => 'notifierId']);
 }
Esempio n. 7
0
 /**
  * The method create user avatar if it does not exist or save existing avatar.
  * @param User $user
  * @param CmgFile $avatar
  * @return User - updated User
  */
 public function updateAvatar($user, $avatar)
 {
     // Find existing user
     $userToUpdate = User::findById($user->id);
     // Save Avatar
     FileService::saveImage($avatar, ['model' => $userToUpdate, 'attribute' => 'avatarId']);
     // Update User
     $userToUpdate->update();
     // Return updated User
     return $userToUpdate;
 }
Esempio n. 8
0
 /**
  * @return User - who modified the model
  */
 public function getModifier()
 {
     return $this->hasOne(User::className(), ['id' => 'modifiedBy']);
 }