Skip to content

Commit

Permalink
Login and Logout
Browse files Browse the repository at this point in the history
  • Loading branch information
3omarbadr committed Apr 22, 2022
1 parent 3d25b71 commit dd2ab9d
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 23 deletions.
17 changes: 9 additions & 8 deletions app/Http/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ public function create()
*/
public function store(Request $request)
{
$attributes = request()->validate([
'name' => ['required','max:255'],
'username' => ['required','min:3','max:255','unique:users,username'],
'email' => ['required','email','max:255', 'unique:users,email'],
'password' => ['required','min:7','max:255'],
$attributes = request()->validate([
'name' => ['required', 'max:255'],
'username' => ['required', 'min:3', 'max:255', 'unique:users,username'],
'email' => ['required', 'email', 'max:255', 'unique:users,email'],
'password' => ['required', 'min:7', 'max:255'],
]);

User::create($attributes);
$user = User::create($attributes);

return redirect('/')->with('success', 'Your account hase been created successfully.');
;
auth()->login($user);

return redirect('/')->with('success', 'Your account hase been created successfully.');;
}

/**
Expand Down
86 changes: 86 additions & 0 deletions app/Http/Controllers/SessionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SessionsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy()
{
auth()->logout();

return redirect('/')->with('success', 'Goodbye!');
}
}
2 changes: 1 addition & 1 deletion app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
public const HOME = '/home';
public const HOME = '/';

/**
* The controller namespace for the application.
Expand Down
23 changes: 16 additions & 7 deletions resources/views/components/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@
</a>
</div>

<div class="mt-8 md:mt-0">
<a href="/" class="text-xs font-bold uppercase">Home Page</a>
<div class="mt-8 md:mt-0 flex items-center">
@guest
<a href="/register" class="text-xs font-bold uppercase">Register</a>
<a href="/login" class="ml-6 text-xs font-bold uppercase">Log In</a>
@else
<span class="text-xs font-bold uppercase">Welcome {{auth()->user()->name}}</span>

<form method="POST" action="/logout" class="text-xs font-semibold text-blue-500 ml-6">
@csrf
<button type="submit">Log Out</button>
</form>
@endguest

<a href="#" class="bg-blue-500 ml-3 rounded-full text-xs font-semibold text-white uppercase py-3 px-5">
Subscribe for Updates
Expand All @@ -37,7 +47,7 @@
</nav>

{{$slot}}

<footer class="bg-gray-100 border border-black border-opacity-5 rounded-xl text-center py-16 px-10 mt-16">
<img src="/images/lary-newsletter-icon.svg" alt="" class="mx-auto -mb-6" style="width: 145px;">
<h5 class="text-3xl">Stay in touch with the latest posts</h5>
Expand All @@ -53,12 +63,11 @@
</label>

<input id="email" type="text" placeholder="Your email address"
class="lg:bg-transparent py-2 lg:py-0 pl-4 focus-within:outline-none">
class="lg:bg-transparent py-2 lg:py-0 pl-4 focus-within:outline-none">
</div>

<button type="submit"
class="transition-colors duration-300 bg-blue-500 hover:bg-blue-600 mt-4 lg:mt-0 lg:ml-3 rounded-full text-xs font-semibold text-white uppercase py-3 px-8"
>
class="transition-colors duration-300 bg-blue-500 hover:bg-blue-600 mt-4 lg:mt-0 lg:ml-3 rounded-full text-xs font-semibold text-white uppercase py-3 px-8">
Subscribe
</button>
</form>
Expand All @@ -67,4 +76,4 @@ class="transition-colors duration-300 bg-blue-500 hover:bg-blue-600 mt-4 lg:mt-0
</footer>
</section>
<x-flash />
</body>
</body>
15 changes: 8 additions & 7 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

use App\Models\Post;
use App\Models\User;
use App\Models\Category;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\RegisterController;
use App\Http\Controllers\SessionsController;


Route::get('/', [PostController::class , 'index'])->name('home');
Route::get('/', [PostController::class, 'index'])->name('home');
Route::get('posts/{post:slug}', [PostController::class, 'show']);

Route::get('register', [RegisterController::class , 'create'])->name('home');
Route::post('register', [RegisterController::class , 'store'])->name('home');

Route::middleware('guest')->group(function () {
Route::get('register', [RegisterController::class, 'create']);
Route::post('register', [RegisterController::class, 'store']);
});

Route::post('logout', [SessionsController::class, 'destroy']);

0 comments on commit dd2ab9d

Please sign in to comment.