diff --git a/app/Http/Controllers/RegisterController.php b/app/Http/Controllers/RegisterController.php new file mode 100644 index 0000000..decfa45 --- /dev/null +++ b/app/Http/Controllers/RegisterController.php @@ -0,0 +1,33 @@ +validate([ + 'name' => ['required'], + 'username' => ['required', 'max:255', 'min:4', 'unique:users,username'], + 'email' => ['required', 'email', 'max:255', 'unique:users,email'], + 'password' => ['required'] + ]); + $attribute['password'] = bcrypt($attribute['password']); + $attribute['username'] = ucwords($attribute['username']); + $user = User::create($attribute); + + Auth::login($user); + + session()->flash('success', 'Your account has been created'); + return redirect('/'); + } +} diff --git a/app/Http/Controllers/SessionsController.php b/app/Http/Controllers/SessionsController.php new file mode 100644 index 0000000..e0e526b --- /dev/null +++ b/app/Http/Controllers/SessionsController.php @@ -0,0 +1,31 @@ +validate([ + 'email' => ['required', 'email'], + 'password' => ['required'] + ]); + if (Auth::attempt($attributes)) { + return redirect('/')->with('success', 'Welcome Back!'); + } + return back()->withInput() + ->withErrors(['email' => 'credentials could not be verified']); + } + public function destroy() + { + Auth::logout(); + return redirect('/')->with('success', 'Goodbye'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index cb6737d..12f935c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,11 +17,7 @@ class User extends Authenticatable * * @var string[] */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; + protected $guarded = []; /** * The attributes that should be hidden for serialization. diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 3bd3c81..affd6da 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider * * @var string */ - public const HOME = '/home'; + public const HOME = '/'; /** * The controller namespace for the application. diff --git a/resources/views/components/layout.blade.php b/resources/views/components/layout.blade.php index ab0f55f..96e3e29 100644 --- a/resources/views/components/layout.blade.php +++ b/resources/views/components/layout.blade.php @@ -16,16 +16,24 @@ -
{{ session('success') }}
+