Example #1
0
 public static function __callStatic($method, $parameters)
 {
     $sentryUserProvider = Sentry::getUserProvider();
     if (method_exists($sentryUserProvider, $method)) {
         return call_user_func_array(array($sentryUserProvider, $method), $parameters);
     }
     return parent::__callStatic($method, $parameters);
 }
Example #2
0
 public static function boot()
 {
     parent::boot();
     //删除时先删除相关文档、单页
     self::deleting(function (User $user) {
         Article::where('uid', '=', $user->id)->delete();
         Page::where('uid', '=', $user->id)->delete();
     });
 }
Example #3
0
 public static function boot()
 {
     parent::boot();
     self::updated(function ($user) {
         /*
          * Update the locale (since its stored in a session variable we need to update it)
          * when changed in profile or use just logged in.
          */
         if (user() and user()->id == $user->id) {
             Session::forget('locale');
         }
     });
 }
Example #4
0
 public function __call($method, $parameters)
 {
     $class_name = class_basename($this);
     #i: Convert array to dot notation
     $config = implode('.', ['relations', $class_name, $method]);
     #i: Relation method resolver
     if (Config::has($config)) {
         $function = Config::get($config);
         return $function($this);
     }
     #i: No relation found, return the call to parent (Eloquent) to handle it.
     return parent::__call($method, $parameters);
 }
Example #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $create = $this->option('create');
     $delete = $this->option('delete');
     if (!empty($create)) {
         $name = $this->ask('Enter the name of the user:');
         while (empty($name)) {
             $name = $this->ask('Enter the name of the user:');
         }
         $password = $this->secret('Enter the password for the user:');
         while (empty($password) || strlen($password) < 5) {
             $this->info('Make sure the password is longer than 5 characters');
             $password = $this->secret('Enter the password for the user:');
         }
         $pwConfirm = $this->secret('Re-enter the password to confirm:');
         while ($pwConfirm != $password) {
             $pwConfirm = $this->secret('The passwords did not match, re-enter the password to confirm:');
         }
         // Create 'everyone' user and group
         Sentry::getUserProvider()->create(array('email' => $name, 'password' => $pwConfirm, 'first_name' => $name, 'last_name' => '', 'activated' => 1));
         $newUser = Sentry::getUserProvider()->findByLogin($name);
         $adminGroup = Sentry::getGroupProvider()->findByName('superadmin');
         $newUser->addGroup($adminGroup);
         $this->info('The user ' . $name . ' has been created and activated.');
     } else {
         if (!empty($delete)) {
             $name = $this->ask('Enter the name of the user you want to delete.');
             while (empty($name)) {
                 $name = $this->ask('Enter the name of the user you want to delete.');
             }
             $user = User::where(['email' => $name])->first();
             if (empty($user)) {
                 $this->error('No user with the name ' . $name . ' has been found.');
             } else {
                 if ($this->confirm('The user ' . $name . ' has been found, are you sure you want do delete? [yes|no]')) {
                     $user->delete();
                 } else {
                     $this->info('The user ' . $name . ' has not been removed.');
                 }
             }
         } else {
             // Get all of the users
             $users = User::all(['email'])->toArray();
             foreach ($users as $user) {
                 if ($user['email'] != 'everyone') {
                     $this->info($user['email']);
                 }
             }
         }
     }
 }
Example #6
0
 /**
  * Create a new Eloquent model instance.
  *
  * @param  array  $attributes
  * @return void
  */
 public function __construct(array $attributes = array())
 {
     $this->{$this->getKeyName()} = (string) $this->generateNewId();
     parent::__construct($attributes);
 }
Example #7
0
 public function testSettingLoginAttribute()
 {
     $originalAttribute = User::getLoginAttribute();
     User::setLoginAttribute('foo');
     $this->assertEquals('foo', User::getLoginAttribute());
     user::setLoginAttribute($originalAttribute);
 }
Example #8
0
 /**
  *
  */
 protected function performInsert(\Illuminate\Database\Eloquent\Builder $query, array $options = array())
 {
     $this->attributes['uid'] = md5(uniqid(mt_rand(), true));
     parent::performInsert($query, $options);
 }
Example #9
0
 /**
  * Removes the user from the given group.
  *
  * @param \Cartalyst\Sentry\Groups\GroupInterface $group
  *
  * @return bool
  */
 public function removeGroup(GroupInterface $group)
 {
     RevisionRepository::create(['revisionable_type' => get_class($this), 'revisionable_id' => $this->getKey(), 'key' => 'removed_group', 'old_value' => null, 'new_value' => $group->getName(), 'user_id' => Credentials::getUser()->id]);
     return parent::removeGroup($group);
 }
 /**
  * Close mockery.
  *
  * @return void
  */
 public function tearDown()
 {
     m::close();
     User::unsetHasher();
 }
Example #11
0
 public function recordLogin()
 {
     $oLogin = new Login();
     $this->logins()->save($oLogin);
     return parent::recordLogin();
 }
Example #12
0
 /**
  * Adds the array of groups to the specified user.
  *
  * @param \Cartalyst\Sentry\Users\Eloquent\User $user
  * @param array                                 $groups
  *
  * @return bool
  */
 private function addGroupsToUser($user, array $groups = [])
 {
     if (count($groups) > 0) {
         foreach ($groups as $group) {
             try {
                 $group = Sentry::findGroupByName($group);
                 $user->addGroup($group);
             } catch (GroupNotFoundException $e) {
             }
         }
         return true;
     }
     return false;
 }
Example #13
0
 /**
  * Get the attributes that should be converted to dates.
  *
  * @return array
  */
 public function getDates()
 {
     return array_merge(parent::getDates(), array('activated_at', 'last_login', 'last_active'));
 }
Example #14
0
 /**
  * Indicates if the model should soft delete.
  *
  * @var bool
  */
 public function __construct()
 {
     parent::__construct();
 }
 /**
  * Function to override default implementation of getMergedPermissions.
  * 
  * Here we try to merge morePermissions variable into the 
  *
  * @return void
  * @author 
  **/
 public function getMergedPermissions()
 {
     $result = parent::getMergedPermissions();
     $result = array_merge($result, $this->getMorePermissions());
     return $result;
 }
Example #16
0
 /**
  * Set the Sentry User Model Hasher to be the same as the configured Sentry Hasher
  */
 public static function boot()
 {
     parent::boot();
     static::setHasher(app()->make('sentry.hasher'));
 }
Example #17
0
 public static function boot()
 {
     parent::boot();
 }