From 405a1ee7fa5dea9cd3ae0afa9469b7a0a2c5e460 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sun, 28 Jun 2020 12:14:35 +0700 Subject: [PATCH] Register and forgot password --- app/Http/Controllers/SecurityController.php | 54 +++++++++ resources/views/forgot.blade.php | 103 +++++++++++++++++ resources/views/login.blade.php | 8 +- resources/views/register.blade.php | 117 ++++++++++++++++++++ routes/web.php | 3 + 5 files changed, 282 insertions(+), 3 deletions(-) create mode 100755 resources/views/forgot.blade.php create mode 100755 resources/views/register.blade.php diff --git a/app/Http/Controllers/SecurityController.php b/app/Http/Controllers/SecurityController.php index c2f5731..db9ff96 100755 --- a/app/Http/Controllers/SecurityController.php +++ b/app/Http/Controllers/SecurityController.php @@ -25,6 +25,24 @@ class SecurityController extends Controller } } + public function viewForgotPassword(Request $request) + { + if (!$request->session()->has('user')) { + return view('forgot'); + } else { + return redirect('home'); + } + } + + public function viewRegister(Request $request) + { + if (!$request->session()->has('user')) { + return view('register'); + } else { + return redirect('home'); + } + } + public function formLogin(Request $request) { $request->validate([ @@ -54,6 +72,42 @@ class SecurityController extends Controller } } + public function formRegister(Request $request) + { + $request->validate([ + "name" => "required", + "email" => "required", + "password" => "required", + "password_confirm" => "required", + ]); + $user = \App\User::where("email", $request->input("email"))->first(); + if ($user != null) { + return response()->json([ + "message" => "User with email " . $user->email . " is exist", + ], 400); + } else { + if ($request->input('password') != $request->input('password_confirm')) { + return response()->json([ + "message" => "Confirm password is different with provided password", + ], 400); + } else { + $user = new \App\User(); + $user->name = $request->input("name"); + $user->email = $request->input("email"); + $user->password = Hash::make($request->input("password")); + if ($user->save()) { + return response()->json([ + "message" => "Register success, now you can login...", + ], 200); + } else { + return response()->json([ + "message" => "Failed to register new user", + ], 400); + } + } + } + } + public function formLogout(Request $request) { $request->session()->flush(); diff --git a/resources/views/forgot.blade.php b/resources/views/forgot.blade.php new file mode 100755 index 0000000..4ef2a0a --- /dev/null +++ b/resources/views/forgot.blade.php @@ -0,0 +1,103 @@ + + + + + + + Todo + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + diff --git a/resources/views/login.blade.php b/resources/views/login.blade.php index 751911d..cf5f4a8 100755 --- a/resources/views/login.blade.php +++ b/resources/views/login.blade.php @@ -50,7 +50,9 @@
-
+
+ Version 1.0.0 +
@@ -64,8 +66,8 @@
- I forgot my password
- Register a new membership + Forgot Password
+ Register
diff --git a/resources/views/register.blade.php b/resources/views/register.blade.php new file mode 100755 index 0000000..970919b --- /dev/null +++ b/resources/views/register.blade.php @@ -0,0 +1,117 @@ + + + + + + + Todo + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + diff --git a/routes/web.php b/routes/web.php index dd639a5..57307ee 100755 --- a/routes/web.php +++ b/routes/web.php @@ -15,6 +15,8 @@ use Illuminate\Support\Facades\Route; Route::get('/', "SecurityController@initSystem"); Route::get('/login', "SecurityController@viewLogin")->name('login'); +Route::get('/forgot/password', "SecurityController@viewForgotPassword"); +Route::get('/register', "SecurityController@viewRegister"); Route::middleware('auth.web')->group(function () { Route::get('/home', "TodoController@viewHome"); @@ -41,4 +43,5 @@ Route::middleware('auth.web')->group(function () { }); Route::post('/web/login', "SecurityController@formLogin"); +Route::post('/web/register', "SecurityController@formRegister"); Route::get('/web/logout', "SecurityController@formLogout");