dayed/auth2

Laravel 4 - 多身份验证带密码重置功能

v1 2014-07-01 04:31 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:36:44 UTC


README

##Laravel 4 多身份验证带密码重置功能

安装

打开您的 composer.json 文件,并添加新的必需包。

"pingpong/auth2": "dev-master" 

接下来,打开终端并运行。

composer update 

在 composer 更新后,在 app/config/app.php 中添加新的服务提供者。

'Pingpong\Auth2\Auth2ServiceProvider'

打开您的终端并运行

php artisan config:publish pingpong/auth2

完成。

配置文件

  return array(
  
  	// example 
  	'admin'	=>	array(
  		'driver' 	=> 'eloquent',
  		'model' 	=> 'Admin',
  		'table' 	=> 'admins',
  		'view' 		=> 'emails.auth.reminder'
  	),		
  
  );

示例

认证

Auth2::admin()->attempt($credentials, $remember);

if(Auth2::admin()->check())
{
  // code
}

Auth2::admin()->get(); //it's same with Auth::user() , for get credentials

Auth2::admin()->logout();

密码重置

密码提醒

  /**
   * Handle a POST request to remind a user of their password.
   *
   * @return Response
   */
  public function postRemind()
  {
  	$response = Password2::admin()->remind(Input::only('email'), function($message)
  	{
  	    $message->subject('Password Reminder');
  	});

  	switch ($response)
  	{
  		case 'reminders.user':
  			return Redirect::back()->with('error', Lang::get($response));

  		case 'reminders.sent':
  			return Redirect::back()->with('status', Lang::get($response));
  	}
  }

密码重置

	
  /**
   * Handle a POST request to reset a user's password.
   *
   * @return Response
   */
  public function postReset()
  {
  		$credentials = Input::only(
  		'email', 'password', 'password_confirmation', 'token'
  	);

  	$response = Password2::admin()->reset($credentials, function($user, $password)
  	{
  		$user->password = Hash::make($password);

  		$user->save();
  	});

  	switch ($response)
  	{
  		case 'reminders.password':
  		case 'reminders.token':
  		case 'reminders.user':
  			return Redirect::back()->with('error', Lang::get($response));

  		case 'reminders.reset':
  			return Redirect::to('admin');
  	}
  }