Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
296 additions
and 129 deletions.
- +63 −0 src/Illuminate/Auth/Console/RemindersControllerCommand.php
- +73 −0 src/Illuminate/Auth/Console/stubs/controller.stub
- +80 −74 src/Illuminate/Auth/Reminders/PasswordBroker.php
- +9 −1 src/Illuminate/Auth/Reminders/ReminderServiceProvider.php
- +4 −1 src/Illuminate/Foundation/changes.json
- +35 −0 src/Illuminate/Support/Facades/Password.php
- +32 −53 tests/Auth/AuthPasswordBrokerTest.php
@@ -0,0 +1,63 @@ | ||
<?php namespace Illuminate\Auth\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Filesystem\Filesystem; | ||
|
||
class RemindersControllerCommand extends Command { | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'auth:reminders-controller'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a stub password reminder controller'; | ||
|
||
/** | ||
* The filesystem instance. | ||
* | ||
* @var \Illuminate\Filesystem\Filesystem | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* Create a new reminder table command instance. | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
* @return void | ||
*/ | ||
public function __construct(Filesystem $files) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->files = $files; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function fire() | ||
{ | ||
$destination = $this->laravel['path'].'/controllers/RemindersController.php'; | ||
|
||
if ( ! $this->files->exists($destination)) | ||
{ | ||
$this->files->copy(__DIR__.'/stubs/controller.stub', $destination); | ||
|
||
$this->info('Password reminders controller created successfully!'); | ||
} | ||
else | ||
{ | ||
$this->error('Password reminders controller already exists!'); | ||
} | ||
} | ||
|
||
} |
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
class RemindersController extends Controller { | ||
|
||
/** | ||
* Display the password reminder view. | ||
* | ||
* @return Response | ||
*/ | ||
public function getRemind() | ||
{ | ||
return View::make('password.remind'); | ||
} | ||
|
||
/** | ||
* Handle a POST request to remind a user of their password. | ||
* | ||
* @return Response | ||
*/ | ||
public function postRemind() | ||
{ | ||
switch (Password::remind(Input::only('email'))) | ||
{ | ||
case Password::INVALID_USER: | ||
return Redirect::back()->with('error', 'User not found.'); | ||
|
||
case Password::REMINDER_SENT: | ||
return Redirect::back()->with('status', 'Password reminder sent!'); | ||
} | ||
} | ||
|
||
/** | ||
* Display the password reset view for the given token. | ||
* | ||
* @param string $token | ||
* @return Response | ||
*/ | ||
public function getReset($token) | ||
{ | ||
return View::make('password.reset')->with('token', $token); | ||
} | ||
|
||
/** | ||
* Handle a POST request to reset a user's password. | ||
* | ||
* @return Response | ||
*/ | ||
public function postReset() | ||
{ | ||
$credentials = Input::only( | ||
'email', 'password', 'password_confirmation', 'token' | ||
); | ||
|
||
$response = Password::reset($credentials, function($user, $password) | ||
{ | ||
$user->password = Hash::make($password); | ||
|
||
$user->save(); | ||
}); | ||
|
||
switch ($response) | ||
{ | ||
case Password::INVALID_PASSWORD: | ||
case Password::INVALID_TOKEN: | ||
case Password::INVALID_USER: | ||
return Redirect::back()->with('error', Lang::get($response)); | ||
|
||
case Password::PASSWORD_RESET: | ||
return Redirect::to('/'); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.