-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\User; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class RegisterController extends Controller | ||
{ | ||
|
||
public function create() | ||
{ | ||
return view('register.create'); | ||
} | ||
|
||
public function store() | ||
{ | ||
$attribute = request()->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('/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\View\ViewName; | ||
|
||
class SessionsController extends Controller | ||
{ | ||
public function create() | ||
{ | ||
return view('sessions.create'); | ||
} | ||
public function store() | ||
{ | ||
$attributes = request()->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<x-layout> | ||
<section class="px-6 py-8"> | ||
<main class="max-w-lg mx-auto mt-10 bg-gray-100 p-6 rounded-xl"> | ||
<h1 class="text-center font-bold text-xl">Register!</h1> | ||
<form action="/register" method="post"> | ||
@csrf | ||
<div class="mb-6"> | ||
<label class="block mb-2 uppercase font-bold text-xs text-gray-700 mt-5" for="username">Username</label> | ||
<input class="border border-gray-400 p-2 w-full" type="text" name="username" id="username" value="{{old('username')}}"> | ||
@error('username') | ||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p> | ||
@enderror | ||
</div> | ||
<div class="mb-6"> | ||
<label class="block mb-2 uppercase font-bold text-xs text-gray-700 mt-5" for="name">Name</label> | ||
<input class="border border-gray-400 p-2 w-full" type="text" name="name" id="name" value="{{old('name')}}"> | ||
</div> | ||
<div class="mb-6"> | ||
<label class="block mb-2 uppercase font-bold text-xs text-gray-700 mt-5" for="email">Email</label> | ||
<input class="border border-gray-400 p-2 w-full" type="email" name="email" id="email" value="{{old('email')}}"> | ||
</div> | ||
<div class="mb-6"> | ||
<label class="block mb-2 uppercase font-bold text-xs text-gray-700 mt-5" for="password">Password</label> | ||
<input class="border border-gray-400 p-2 w-full" type="password" name="password" id="password"> | ||
</div> | ||
|
||
<div class="mb-6"> | ||
<button class="text-center bg-blue-400 text-white rounded py-2 px-4 hover:bg-blue-500" type="submit">Submit</button> | ||
</div> | ||
</form> | ||
</main> | ||
</section> | ||
</x-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<x-layout> | ||
<section class="px-6 py-8"> | ||
<main class="max-w-lg mx-auto mt-10 bg-gray-100 p-6 rounded-xl"> | ||
<h1 class="text-center font-bold text-xl">Log in!</h1> | ||
<form action="/login" method="post"> | ||
@csrf | ||
<div class="mb-6"> | ||
<label class="block mb-2 uppercase font-bold text-xs text-gray-700 mt-5" for="email">Email</label> | ||
<input class="border border-gray-400 p-2 w-full" type="email" name="email" id="email" value="{{old('email')}}"> | ||
@error('email') | ||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p> | ||
@enderror | ||
</div> | ||
<div class="mb-6"> | ||
<label class="block mb-2 uppercase font-bold text-xs text-gray-700 mt-5" for="password">Password</label> | ||
<input class="border border-gray-400 p-2 w-full" type="password" name="password" id="password"> | ||
@error('password') | ||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p> | ||
@enderror | ||
</div> | ||
|
||
<div class="mb-6"> | ||
<button class="text-center bg-blue-400 text-white rounded py-2 px-4 hover:bg-blue-500" type="submit">Log in</button> | ||
</div> | ||
</form> | ||
</main> | ||
</section> | ||
</x-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters