【发布时间】:2014-07-05 20:46:05
【问题描述】:
在我把问题带到这里之前,我真的尝试自己调试我的问题,但我真的找不到我的 laravel 身份验证问题的解决方案,尽管这似乎是一个常见问题。
我的身份验证不会登录。它总是返回 false,我不明白为什么。
我在这里阅读了其他一些问题,他们的解决方案并没有解决我的特殊情况。
- 我的用户模型实现了 UserInterface 和 Remindable Interface。
- 我的密码在创建到数据库时经过哈希处理。
- 我的数据库中的密码字段是 varchar 100,这应该足以散列密码。
- 我正在登录的用户已在数据库中创建并激活。
非常感谢您提供任何见解。
用户模型
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $fillable = array('email', 'username', 'password', 'password_temp', 'code', 'active');
public $timestamps = false;
protected $softDelete = false;
/**
* 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 = '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;
}
}
账户控制人
class AccountController extends BaseController {
public function getLogin() {
return View::make('account.login');
}
public function postLogin() {
$validator = Validator::make(Input::all(),
array(
'email' => 'required',
'password' => 'required'
)
);
if($validator->fails()) {
return Redirect::route('login')
->withErrors($validator);
} else {
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1
));
if($auth) {
return Redirect::route('Create-Account');
}
}
return Redirect::route('login')
->with('global', 'There was a problem logging you in. Please check your credentials and try again.');
}
public function getCreate() {
return View::make('account.create');
}
public function getviewReturn() {
return View::make('account.return');
}
public function postCreate() {
$validator = Validator::make(Input::all(),
array(
'email' => 'required|max:50|email|unique:Users',
'username' => 'required|max:15|min:4|unique:Users',
'password' => 'required|min:6',
'password2' => 'required|same:password'
)
);
if ($validator->fails()) {
return Redirect::route('Post-Create-Account')
->withErrors($validator)
->withInput();
}
else {
$email = Input::get('email');
$username = Input::get('username');
$password = Input::get('email');
$code = str_random(60);
$user = User::create(array(
'email' => $email,
'username' => $username,
'password' => Hash::make($password),
'code' => $code,
'active' => 0));
});
return Redirect::to('account/return')
路线
Route::group(array('before' => 'guest'), function() {
Route::group(array('before' => 'csrf'), function() {
Route::post('/account/create', array(
'as' => 'Post-Create-Account',
'uses' => 'AccountController@postCreate'
));
Route::post('/account/login', array(
'as' => 'postlogin',
'uses' => 'AccountController@postLogin'
));
});
Route::get('/account/login', array(
'as' => 'login',
'uses' => 'AccountController@getLogin'
));
Route::get('/account/create', array(
'as' => 'Create-Account',
'uses' => 'AccountController@getCreate'
));
Route::get('/account/activate/{code}', array(
'as' => 'Activate-Account',
'uses' => 'AccountController@getActivate'
【问题讨论】:
标签: php authentication login laravel