/**
  * @param \KodiCMS\Users\Model\User $user
  *
  * @return void
  */
 public function authenticated($user)
 {
     // Update the number of logins
     $user->logins = DB::raw('logins + 1');
     // Set the last login date
     $user->last_login = time();
     $user->update();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     User::truncate();
     \DB::table('user_meta')->truncate();
     \DB::table('role_user')->truncate();
     $roles = Role::pluck('id')->all();
     $maxRolesToAttach = count($roles) > 4 ? 4 : count($roles);
     $faker = \Faker\Factory::create();
     $totalUsers = 5;
     $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'name' => 'admin', 'locale' => 'ru']);
     $user->roles()->sync($roles);
     $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'name' => 'admin_en', 'locale' => 'en']);
     $user->roles()->sync([1, 2, 3]);
     $usedEmails = $usedUsernames = [];
     for ($i = 0; $i < $totalUsers; $i++) {
         do {
             $email = strtolower($faker->email);
         } while (in_array($email, $usedEmails));
         $usedEmails[] = $email;
         do {
             $username = strtolower($faker->userName);
         } while (in_array($username, $usedUsernames));
         $usedUsernames[] = $username;
         $user = User::create(['email' => $email, 'password' => 'password', 'name' => $username, 'locale' => $faker->randomElement(['ru', 'en'])]);
         $user->roles()->attach($faker->randomElements($roles, rand(1, $maxRolesToAttach)));
     }
 }
 /**
  * @return User
  * @throws ReflinkException
  */
 public function getUser()
 {
     if (is_null($user = User::where('email', $this->email)->first())) {
         throw new ReflinkException(trans(Password::INVALID_USER));
     }
     return $user;
 }
 public function getCreate()
 {
     WYSIWYG::loadAll(WYSIWYG::TYPE_HTML);
     $to = $this->request->get('to');
     $toId = User::find($to);
     $this->setTitle(trans('users::message.title.create'));
     $this->setContent('messages.add', ['to' => !is_null($toId) ? $toId->id : NULL, 'userId' => $this->currentUser->id]);
 }
 public function getLike()
 {
     $query = $this->getRequiredParameter('query');
     $in = (array) $this->getParameter('in', ['username']);
     $users = User::select();
     foreach ($in as $field) {
         $users->orWhere($field, 'like', "{$query}%");
     }
     $this->setContent($users->get());
 }
 public function boot()
 {
     User::observe(new UserObserver());
     UserRole::observe(new RoleObserver());
     Event::listen('view.navbar.right.after', function () {
         echo view('users::parts.navbar');
     });
     Event::listen('view.menu.before', function () {
         echo view('users::parts.navigation');
     });
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 public function create(array $data)
 {
     $user = User::create(array_only($data, ['username', 'password', 'email', 'locale']));
     if (isset($data['user_roles'])) {
         $roles = $data['user_roles'];
         if (!is_array($roles)) {
             $roles = explode(',', $roles);
         }
         $user->roles()->attach($roles);
     }
     return $user;
 }
示例#8
0
 /**
  * @param DocumentInterface $document
  *
  * @return array
  */
 public function getUserList(DocumentInterface $document)
 {
     $query = UserModel::query();
     if ($this->isUnique()) {
         $usedIds = \DB::table($this->getSection()->getSectionTableName())->select($this->getDBKey())->whereNotNull($this->getDBKey())->where($this->getDBKey(), '!=', 0)->where($this->getSection()->getDocumentPrimaryKey(), '!=', $document->getKey())->lists($this->getDBKey());
         if (!empty($usedIds)) {
             $query->whereNotIn('id', $usedIds);
         }
     }
     $list = $query->get()->lists('username', 'id')->all();
     return [0 => 'Not set'] + $list;
 }
 public function boot()
 {
     Event::listen('view.navbar.right.before', function () {
         echo view('notifications::navbar')->render();
     });
     User::addRelation('notifications', function (User $model) {
         return $model->belongsToMany(Notification::class, 'notifications_users', 'user_id');
     });
     User::addRelation('newNotifications', function (User $model) {
         return $model->notifications()->wherePivot('is_read', 0);
     });
 }
 /**
  * @param DispatcherContract $events
  */
 public function boot(DispatcherContract $events)
 {
     $events->listen(UserRolesChanged::class, UserRolesChangedNotification::class);
     User::observe(new UserObserver());
     Role::observe(new RoleObserver());
     Event::listen('view.navbar.right.after', function () {
         echo view('users::parts.navbar')->render();
     });
     Event::listen('view.menu', function ($navigation) {
         echo view('users::parts.navigation')->render();
     }, 999);
     $this->registerPermissions();
 }
示例#11
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param integer $id
  * @param  array $data
  * @return User
  */
 public function update($id, array $data)
 {
     $user = User::findOrFail($id);
     if (array_key_exists('password', $data) and empty($data['password'])) {
         unset($data['password']);
     }
     $user->update(array_only($data, ['username', 'password', 'email', 'locale']));
     if (isset($data['user_roles'])) {
         $roles = $data['user_roles'];
         if (!is_array($roles)) {
             $roles = explode(',', $roles);
         }
         $user->roles()->sync($roles);
     }
     return $user;
 }
 /**
  * Создание администратора.
  */
 public function createAdmin(array $config)
 {
     // Delete seeder admin users
     User::where('email', 'like', '*****@*****.**')->delete();
     $user = User::create(['email' => array_get($config, 'email'), 'password' => array_get($config, 'password'), 'username' => array_get($config, 'username'), 'locale' => array_get($config, 'locale', 'en')]);
     $user->roles()->sync([1, 2, 3]);
 }
 /**
  * @param User $user
  *
  * @return array
  */
 public function getNew(User $user)
 {
     return $user->newNotifications()->get()->lists('type');
 }
 /**
  * @param integer|null $id
  * @return User
  * @throws HttpResponseException
  */
 protected function getUser($id = NULL)
 {
     if (is_null($id)) {
         return $this->currentUser;
     }
     try {
         return User::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         $this->throwFailException($this->smartRedirect()->withErrors(trans('users::core.messages.user.not_found')));
     }
 }
 /**
  * @param User $user
  *
  * @return mixed
  */
 public function findAllByUser(User $user)
 {
     return $user->tokens()->get();
 }
示例#16
0
 /**
  * @param \KodiCMS\Users\Model\User $model
  * @return bool
  */
 public function deleted($model)
 {
     // Удаление связанных ролей
     $model->roles()->sync([]);
 }
示例#17
0
 /**
  * Загрузка прав доступа для пользователя
  *
  * @param User $user
  */
 protected static function setPermissions(User $user)
 {
     static::$permissions[$user->id] = array_flip($user->getAllowedPermissions());
 }
 /**
  * @param \Request $request
  * @param User $user
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function authenticated($request, $user)
 {
     $user->updateLastLogin();
     $user->authenticated();
     return redirect()->intended($this->redirectPath());
 }