Sentry2用户模型扩展 [英] Sentry2 user model extension
本文介绍了Sentry2用户模型扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在laravel 4应用程序中使用Sentry2软件包( http://docs.cartalyst.com /sentry-2/).
I'm using Sentry2 package in my laravel 4 application (http://docs.cartalyst.com/sentry-2/).
我创建了一个扩展Sentry2用户模型的新用户模型:
I create a new User model that extends 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's 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 follow code I have a exception.
$adminUser = User::create(array(
'email' => 'admin@admin.com',
'password' => "admin",
'first_name' => 'Admin',
'last_name' => 'Admin',
'activated' => 1,
));
错误:
[RuntimeException]
A hasher has not been provided for the user.
推荐答案
我需要更新岗哨包的配置文件:
I need to update the config file of sentry package:
'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',
),
并使用Sentry::getUserProvider()->create()
方法
$adminUser = Sentry::getUserProvider()->create(
array(
'email' => 'admin@admin.com',
'password' => "admin",
'first_name' => 'Admin',
'last_name' => 'Admin',
'activated' => 1,
)
);
这篇关于Sentry2用户模型扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文