Sentry2 user model extension

I am using the Sentry2 package in my laravel 4 application ( http://docs.cartalyst.com/sentry-2/ ).

I am creating a new user model that extends the Sentry2 user model:

<?php namespace App\Models; use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class User extends \Cartalyst\Sentry\Users\Eloquent\User implements UserInterface, RemindableInterface { /** * The database table used by the model. * * @var string */ protected $table = 'users'; /** * The attributes excluded from the model JSON form. * * @var array */ protected $hidden = array('password'); /** * Get the unique identifier for the user. * * @return mixed */ public function getAuthIdentifier() { return $this->getKey(); } /** * Get the password for the user. * * @return string */ public function getAuthPassword() { return $this->password; } /** * Get the e-mail address where password reminders are sent. * * @return string */ public function getReminderEmail() { return $this->email; } } 

when I execute the following code, I have an exception.

 $adminUser = User::create(array( 'email' => ' admin@admin.com ', 'password' => "admin", 'first_name' => 'Admin', 'last_name' => 'Admin', 'activated' => 1, )); 

Mistake:

  [RuntimeException] A hasher has not been provided for the user. 
+1
laravel laravel-4
source share
4 answers

I need to update the clock package configuration file:

 'users' => array( /* |-------------------------------------------------------------------------- | Model |-------------------------------------------------------------------------- | | When using the "eloquent" driver, we need to know which | Eloquent models should be used throughout Sentry. | */ 'model' => '\App\Models\User', /* |-------------------------------------------------------------------------- | Login Attribute |-------------------------------------------------------------------------- | | If you're the "eloquent" driver and extending the base Eloquent model, | we allow you to globally override the login attribute without even | subclassing the model, simply by specifying the attribute below. | */ 'login_attribute' => 'email', ), 

and use the Sentry::getUserProvider()->create() method

  $adminUser = Sentry::getUserProvider()->create( array( 'email' => ' admin@admin.com ', 'password' => "admin", 'first_name' => 'Admin', 'last_name' => 'Admin', 'activated' => 1, ) ); 
+2
source share

If you want to create your object from the Brightness mass alignment, you can add the Hasher manually. For example:

 $user->setHasher(new Cartalyst\Sentry\Hashing\NativeHasher); 

Or, to be persistent, you can add the boot method to the User object as follows:

 class User extends \Cartalyst\Sentry\Users\Eloquent\User implements UserInterface, RemindableInterface { // ... public static function boot() { self::$hasher = new Cartalyst\Sentry\Hashing\NativeHasher; } // ... } 
+3
source share

what will he tell you, you should use a hash and salt your password therefore

 $adminUser = User::create(array( 'email' => ' admin@admin.com ', 'password' => Hash::make('admin'), 'first_name' => 'Admin', 'last_name' => 'Admin', 'activated' => 1, 

));

0
source share

I expanded the Sentry user model like you, and the same error is returned, then I find the idea in https://github.com/cartalyst/sentry/issues/163 , and then tried to go through a new instance of NativeHasher; I'm not sure if this is correct, but in the first test the user was saved correctly:

 $user = new User; $user->setHasher(new Cartalyst\Sentry\Hashing\NativeHasher); $user->first_name = "Name"; $user->last_name = "Last"; $user->password = 'admin'; $user->email = " email@gmail.com "; $user->save(); 
0
source share

All Articles