eOSP2/app/Http/Controllers/resetPasswordController.php

47 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\User;
use Mail;
class resetPasswordController extends Controller
{
public function create()
{
return view('forgottenPassword');
}
public function reset()
{
$this->validate(request(), [
'email' => 'required|email',
],
[
'required' => ':attribute jest wymagany.',
'email' => 'Niepoprawny adres e-mail.'
]);
$request = request();
$user = DB::table('users')->where('email', '=', $request->email)
->first();
if($user){
$password = str_random(10);
User::where('email', '=', $request->email)
2020-01-31 03:13:13 +01:00
->update(['password' => Hash::make($password)]);
Mail::send('emails.passwordReset', compact('password'), function($message) {
$message->to(Input::get('email'))->subject('Zmiana hasła');
});
}
return redirect()->to('/login')->with('success','Jeśli podany adres email jest poprawny, nowe hasło zostało wysłane');
}
}