我将getRememberToken,setRememberToken,getRememberTokenName添加到User模型,将“remember_token”列添加到用户DB,运行composer update。
结果:没有错误,使用remember me选项登录与之前相同 - DB中的“remember_token”仍然为null。
+我在retrieveByToken()
updateRememberToken()
和Illuminate\Auth\UserProviderInterface
出了什么问题?
我做了什么或没做过什么?作曲家出于某种原因没有采用“laravel / framework”:“4.2。*”应该如此? v4.2没有修复记住我的问题?应该以某种方式修改Auth::attempt()
以生成并将数据放入remember_token中? Auth::logout()
没有触及remember_token(我把随机数据放在注销后仍然相同,无论是否记住我都可以登录)
在哪里挖?
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $fillable = ['name','email','password','temp_password','code','status', 'remember_token'];
/**
* 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;
}
public function scopeCode($query, $code)
{
return $query->whereCode($code);
}
public function scopeEmail($query, $email)
{
return $query->whereEmail($email);
}
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
}
答案 0 :(得分:0)
这是Laravel开发的User
模型:
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* 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');
protected $fillable = array('email', 'password');
}
这里需要注意的一些事情:
UserTrait
,另一种来自RemindableTrait
。composer.json
中,您需要将minimum-stability
设置为dev
,然后设置php composer.phar update
(或者,如果您遇到我常常遇到的内存错误,{{1} })。请注意,rm -rf vendor/ && php composer.phar install
目前不适用于上述用户模型,因为自beta
版本发布后RemindableTrait
实际上已被移动;所以我推荐BETA1
分支,直到dev
。4.2.0-BETA2
版本为4.2.0-BETA1
,但laravel/framework
没有4.2.*
版本。因此,如果您尝试(就像我一样,相当长一段时间,徒劳无功)到laravel/laravel
,即使4.2 beta已经出来,您现在仍会继续获得create-project laravel/laravel --stability=beta
。这一切都非常令人困惑。最后,不要忘记您的用户架构(4.1.*
处的存根):
php artisan auth:reminders-table
您的提醒控制器(存档于<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('password');
$table->string('remember_token', 100)->nullable();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
):
php artisan auth:reminders-controller
答案 1 :(得分:0)
答案 2 :(得分:0)
我正在使用Laravel 4.2;我的登录视图中有name="rememberme"
的输入,控制器中包含以下代码:
if(Auth::attempt($logindata, Input::has('rememberme')))
{
return Redirect::intended('/');
}
效果很好;一旦我登录,我的会话就不会结束,直到我明确注销。
答案 3 :(得分:0)
Laravel 4.2记住我的步骤:
1-用于检查登录的主用户表必须在架构中具有rememberToken()
Schema::create('Users',function($table)
{
$table->increments('id');
$table->string('email');
$table->string('password');
$table->bigInteger('organizer_id');
$table->boolean('status');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
2-查看:复选框让我记住,就像我有
一样{{Form::label('remember','Remember Me')}}
3-登录控制器:
if (\Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password') ), (Input::get('remember')==1 ? true : false)))
{
return Redirect::to('_admin/home')->with('message', 'You are now logged in!');
} else {
return \Redirect::back()
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
(Input::get('remember')==1 ? true : false)
这行代码应该适合记住我