sarga/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php

87 lines
2.1 KiB
PHP
Executable File

<?php
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Facades\Password;
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->_config = request('_config');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
*/
public function create()
{
return view($this->_config['view']);
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
try {
$this->validate(request(), [
'email' => 'required|email',
]);
$response = $this->broker()->sendResetLink(
request(['email'])
);
if ($response == Password::RESET_LINK_SENT) {
session()->flash('success', trans('customer::app.forget_password.reset_link_sent'));
return back();
}
return back()
->withInput(request(['email']))
->withErrors([
'email' => trans('customer::app.forget_password.email_not_exist'),
]);
} catch (\Swift_RfcComplianceException $e) {
session()->flash('success', trans('customer::app.forget_password.reset_link_sent'));
return redirect()->back();
} catch (\Exception $e) {
report($e);
session()->flash('error', trans($e->getMessage()));
return redirect()->back();
}
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker()
{
return Password::broker('customers');
}
}