Skip to content

Commit

Permalink
add login functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
danivideda committed Dec 1, 2020
1 parent 00ff857 commit 0a36315
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 14 deletions.
23 changes: 21 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
Expand All @@ -16,11 +17,29 @@ public function showTeacherLoginForm() {
}

public function loginStudent(Request $request) {
//
$this->validate($request, [
'email' => 'required|email',
'password' => 'required'
]);

if (!Auth::guard('student')->attempt($request->only('email', 'password'))) {
return back()->with('status', 'Invalid login details');
}

return redirect()->route('student.dashboard');
}

public function loginTeacher(Request $request) {
//
$this->validate($request, [
'email' => 'required|email',
'password' => 'required'
]);

if (!Auth::guard('teacher')->attempt($request->only('email', 'password'))) {
return back()->with('status', 'Invalid login details');
}

return redirect()->route('teacher.dashboard');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@
<p class="text-black font-extrabold text-center text-3xl inline mx-9 "> | </p>
<a class="text-gray-600 font-extrabold text-center text-3xl inline mx-9" href="{{ route('register.student') }}"> SIGN UP </a>
</div>
<div class="bg-white py-16 px-20">
<form action="" method="post">
<div class="bg-white pb-16 pt-5 px-20">
<div>
<p class="pt-2 text-black">Currently loging in as <span class="font-bold text-black">Student</span>.</p>
<p class="pb-4 text-gray-500 text-sm"> or login as Teacher <a class="underline" href="{{route('login.teacher')}}">here</a></p>
@if (session('status'))
<div class="bg-red-400 p-4 rounded-lg mb-6 text-white text-center">
{{ session('status') }}
</div>
@endif
</div>
<form action="{{ route('login.student') }}" method="POST">
@csrf
<div class="mb-4">
<label for="email" class="sr-only">Email</label>
<label for="email" class="uppercase tracking-wide text-gray text-xs font-bold">Email</label>
<input type="text" name="email" id="email" placeholder="Email"
class="bg-gray-100 border-2 w-full p-4 rounded-lg @error('email') border-red-500 @enderror" value="{{ old('email') }}">

Expand All @@ -29,7 +38,7 @@ class="bg-gray-100 border-2 w-full p-4 rounded-lg @error('email') border-red-500
</div>

<div class="mb-4">
<label for="password" class="sr-only">Password</label>
<label for="password" class="uppercase tracking-wide text-gray text-xs font-bold">Password</label>
<input type="password" name="password" id="password" placeholder="Password"
class="bg-gray-100 border-2 w-full p-4 rounded-lg @error('password') border-red-500 @enderror" value="">

Expand Down
60 changes: 60 additions & 0 deletions resources/views/auth/login-teacher.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@extends('layouts.app')

@section('content')

<section class="bg-gradient-to-r from-blue-300 to-green-400 pt-12 pb-16 md:pt-8 px-8 h-screen" id="login">
<div class="container mx-auto flex flex-wrap flex-col md:flex-row items-center px-10">
<div class="w-full xl:w-7/12 py-6 overflow-y-hidden">
<img class="w-5/6 lg:mr-0" src="http://www.pngall.com/wp-content/uploads/5/Learning-PNG-Free-Download.png">
</div>
<div class="flex flex-col w-full xl:w-5/12 justify-center overflow-y-hidden">
<div class="bg-blue-500 px-4 py-8">
<span class="text-black font-extrabold text-center text-3xl inline mx-9"> LOGIN </span>
<p class="text-black font-extrabold text-center text-3xl inline mx-9 "> | </p>
<a class="text-gray-600 font-extrabold text-center text-3xl inline mx-9" href="{{ route('register.teacher') }}"> SIGN UP </a>
</div>
<div class="bg-white pb-16 pt-5 px-20">
<div>
<p class="pt-2 text-black">Currently loging in as <span class="font-bold text-black">Teacher</span>.</p>
<p class="pb-4 text-gray-500 text-sm"> or login as Student <a class="underline" href="{{route('login.student')}}">here</a></p>
@if (session('status'))
<div class="bg-red-400 p-4 rounded-lg mb-6 text-white text-center">
{{ session('status') }}
</div>
@endif
</div>
<form action="{{ route('login.teacher') }}" method="POST">
@csrf
<div class="mb-4">
<label for="email" class="uppercase tracking-wide text-gray text-xs font-bold">Email</label>
<input type="text" name="email" id="email" placeholder="Email"
class="bg-gray-100 border-2 w-full p-4 rounded-lg @error('email') border-red-500 @enderror" value="{{ old('email') }}">

@error('email')
<div class="text-red-500 mt-2 text-sm">
{{ $message }}
</div>
@enderror
</div>

<div class="mb-4">
<label for="password" class="uppercase tracking-wide text-gray text-xs font-bold">Password</label>
<input type="password" name="password" id="password" placeholder="Password"
class="bg-gray-100 border-2 w-full p-4 rounded-lg @error('password') border-red-500 @enderror" value="">

@error('password')
<div class="text-red-500 mt-2 text-sm">
{{ $message }}
</div>
@enderror
</div>
<div>
<button type="submit" class="bg-pink-600 text-white px-4 py-3 rounded font-medium w-full">Login</button>
</div>
</form>
</div>
</div>
</div>
</section>

@endsection
2 changes: 1 addition & 1 deletion resources/views/auth/register-student.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<div class="flex flex-col w-full xl:w-5/12 justify-center overflow-y-hidden">
<div class="bg-blue-500 px-4 py-8">
<a class="text-gray-600 font-extrabold text-center text-3xl inline mx-9" href="/login"> LOGIN </a>
<a class="text-gray-600 font-extrabold text-center text-3xl inline mx-9" href="{{ route('login.student') }}"> LOGIN </a>
<p class="text-black font-extrabold text-center text-3xl inline mx-9 "> | </p>
<span class="text-blck font-extrabold text-center text-3xl inline mx-9"> SIGN UP </span>
</div>
Expand Down
8 changes: 4 additions & 4 deletions resources/views/auth/register-teacher.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
</div>
<div class="flex flex-col w-full xl:w-5/12 justify-center overflow-y-hidden">
<div class="bg-blue-500 px-4 py-8">
<a class="text-gray-600 font-extrabold text-center text-3xl inline mx-9" href="/login"> LOGIN </a>
<a class="text-gray-600 font-extrabold text-center text-3xl inline mx-9" href="{{ route('login.teacher') }}"> LOGIN </a>
<p class="text-black font-extrabold text-center text-3xl inline mx-9 "> | </p>
<a class="text-blck font-extrabold text-center text-3xl inline mx-9" href="/signup"> SIGN UP </a>
<span class="text-blck font-extrabold text-center text-3xl inline mx-9"> SIGN UP </span>
</div>
<div class="bg-white pt-2 pb-8 px-20">
<div>
<p class="pt-2 text-black">Currently signing up as <span class="font-bold text-black">Teacher</span>.</p>
<p class="pb-4 text-gray-500 text-sm"> or sign up as Student <a class="underline" href="{{route('register.student')}}">here</a></p>
</div>
<form action="" method="post">
<form action="{{ route('register.teacher') }}" method="POST">
@csrf
<div class="mb-4">
<label for="name" class="uppercase tracking-wide text-gray text-xs font-bold">Nama Lengkap</label>
<input type="text" name="name" id="name" placeholder="Nama"
class="bg-gray-100 border-2 w-full p-4 rounded-lg mt-3 @error('name') border-red-500 @enderror" value="{{ old('name') }}">
class="bg-gray-100 border-2 w-full p-4 rounded-lg @error('name') border-red-500 @enderror" value="{{ old('name') }}">

@error('name')
<div class="text-red-500 mt-2 text-sm">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/layouts/teacherhome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
<div class="bg-gray-100 pt-7">
@yield('maincontent')
</div>

<div class="h-screen bg-white pt-6">
<div class="mb-6 text-black text-base text-center">
<a href="#">{{ auth()->guard('student')->user()->name }}</a>
<a href="#">{{ auth()->guard('teacher')->user()->name }}</a>
<button class="px-1 pb-1 bg-red-500 text-white rounded hover:bg-red-600 ml-6">
<a href="#" class="text-xs">Logout</a>
</button>
Expand Down
5 changes: 4 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
})->name('home');

Route::get('/student/login', [LoginController::class, 'showStudentLoginForm'])->name('login.student');
Route::post('/student/login', [LoginController::class, 'loginStudent'])->name('login.student');

Route::get('/teacher/login', [LoginController::class, 'showTeacherLoginForm'])->name('login.teacher');
Route::post('/teacher/login', [LoginController::class, 'loginTeacher'])->name('login.teacher');

Route::get('/student/register', [RegisterController::class, 'showStudentRegisterForm'])->name('register.student');
Route::post('/student/register', [RegisterController::class, 'registerStudent']);
Expand Down Expand Up @@ -72,4 +75,4 @@
});
Route::get('/teacher/review', function () {
return view('teacher.course.review');
});
});

0 comments on commit 0a36315

Please sign in to comment.