sarga/packages/Webkul/User/src/Http/Controllers/ForgetPasswordController.php

94 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Webkul\User\Http\Controllers;
2020-06-17 10:56:22 +00:00
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Facades\Password;
class ForgetPasswordController extends Controller
{
2020-06-17 10:56:22 +00:00
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.
*
2020-01-23 05:31:04 +00:00
* @return \Illuminate\View\View
*/
public function create()
2020-06-24 13:27:46 +00:00
{
if (auth()->guard('admin')->check()) {
return redirect()->route('admin.dashboard.index');
} else {
if (strpos(url()->previous(), 'admin') !== false) {
$intendedUrl = url()->previous();
} else {
$intendedUrl = route('admin.dashboard.index');
}
session()->put('url.intended', $intendedUrl);
return view($this->_config['view']);
}
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
2020-01-23 05:31:04 +00:00
try {
$this->validate(request(), [
2020-03-04 06:32:53 +00:00
'email' => 'required|email',
2020-01-23 05:31:04 +00:00
]);
2020-01-23 05:31:04 +00:00
$response = $this->broker()->sendResetLink(
request(['email'])
);
2020-01-23 05:31:04 +00:00
if ($response == Password::RESET_LINK_SENT) {
2020-09-04 13:37:04 +00:00
session()->flash('success', trans('customer::app.forget_password.reset_link_sent'));
2020-01-23 05:31:04 +00:00
return back();
}
2020-01-23 05:31:04 +00:00
return back()
->withInput(request(['email']))
2020-03-04 06:32:53 +00:00
->withErrors([
2020-09-04 13:37:04 +00:00
'email' => trans('customer::app.forget_password.email_not_exist'),
2020-03-04 06:32:53 +00:00
]);
2020-01-23 05:31:04 +00:00
} catch(\Exception $e) {
session()->flash('error', trans($e->getMessage()));
2020-01-23 05:31:04 +00:00
return redirect()->back();
}
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker()
{
return Password::broker('admins');
}
}