diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php index 1d4d495..ab20b2b 100644 --- a/skolehjem/app/Http/Controllers/UserController.php +++ b/skolehjem/app/Http/Controllers/UserController.php @@ -233,11 +233,32 @@ class UserController extends Controller $user = User::query()->where('email', '=', $request->email)->first(); if($user == null){ - return redirect()->back(); + return redirect()->back()->with('errornosuchuser', '

Denne email findes ikke i systemet!

'); } //Send email - //TODO: Implement mail. + $email = $user->email; + $pswd = ""; + + //Generate password + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $n = 6; + $randomString = ''; + + for ($i = 0; $i < $n; $i++) { + $index = rand(0, strlen($characters) - 1); + $randomString .= $characters[$index]; + } + + $pswd = $randomString; + + $user->setPasswordAttribute($pswd); + $user->update(); + + $subject = "SDE Skolehjem reset password"; + $msg = "Din adgangskode er nu: " . $pswd; + + mail($email, $subject, $msg); return redirect()->route('users.login'); } diff --git a/skolehjem/resources/views/admin/users/forgot.blade.php b/skolehjem/resources/views/admin/users/forgot.blade.php index 286ff7b..20dc1fa 100644 --- a/skolehjem/resources/views/admin/users/forgot.blade.php +++ b/skolehjem/resources/views/admin/users/forgot.blade.php @@ -9,10 +9,11 @@
Syddansk Erhvervsskole
-
+ @csrf
+ {!! session()->get("errornosuchuser") !!} @endsection