Cleanup SPA Code - That will be a separate project

pull/3/head
Hasin Hayder 3 years ago
parent 650277b7fc
commit 0f99d28a81

@ -1,58 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
class LoginSPAController extends Controller {
public function login(Request $request) {
$credentials = $request->validate([
'email' => ['required', 'email'],
'password' => ['required'],
]);
if (Auth::attempt($credentials)) {
$request->session()->regenerate();
return redirect()->route('home');
}
return back()->withErrors([
'email' => 'Invalid Credentials',
])->onlyInput('email');
}
public function register(Request $request) {
$creds = $request->validate([
'email' => 'required|email',
'password' => 'required'
]);
$user = User::where('email', $creds['email'])->first();
if (!$user) {
User::create([
'name' => $request->name,
'email' => $creds['email'],
'password' => Hash::make($creds['password'])
]);
}
return $this->login($request);
}
public function logout(Request $request) {
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/');
}
function loginForm() {
if (Auth::check()) {
return redirect('/');
}
return view('login');
}
}

@ -1,22 +1,2 @@
const { default: axios } = require('axios');
require('./bootstrap');
const app = {
init(){
//do something
},
login(){
axios.get('/sanctum/csrf-cookie').then(response => {
axios.post('/login',{
'email':'email@example.com',
'password':'ThisIsABadPassword'
}).then(response=>{
location.href='/'
})
});
}
}
window.app = app
app.init()

@ -7,7 +7,7 @@ window._ = require('lodash');
*/
window.axios = require('axios');
window.axios.defaults.withCredentials = true;
// window.axios.defaults.withCredentials = true;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/**

@ -1,86 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Login</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="container mx-auto">
<div class="flex max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-lg dark:bg-gray-800 lg:max-w-4xl">
<div class="hidden bg-cover lg:block lg:w-1/2" style="background-image:url('https://images.unsplash.com/photo-1606660265514-358ebbadc80d?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1575&q=80')"></div>
<div class="w-full px-6 py-8 md:px-8 lg:w-1/2">
<h2 class="text-2xl font-semibold text-center text-gray-700 dark:text-white">Brand</h2>
<p class="text-xl text-center text-gray-600 dark:text-gray-200">Welcome back!</p>
{{-- <a href="#" class="flex items-center justify-center mt-4 text-gray-600 transition-colors duration-200 transform border rounded-lg dark:border-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-600">
<div class="px-4 py-2">
<svg class="w-6 h-6" viewBox="0 0 40 40">
<path d="M36.3425 16.7358H35V16.6667H20V23.3333H29.4192C28.045 27.2142 24.3525 30 20 30C14.4775 30 10 25.5225 10 20C10 14.4775 14.4775 9.99999 20 9.99999C22.5492 9.99999 24.8683 10.9617 26.6342 12.5325L31.3483 7.81833C28.3717 5.04416 24.39 3.33333 20 3.33333C10.7958 3.33333 3.33335 10.7958 3.33335 20C3.33335 29.2042 10.7958 36.6667 20 36.6667C29.2042 36.6667 36.6667 29.2042 36.6667 20C36.6667 18.8825 36.5517 17.7917 36.3425 16.7358Z" fill="#FFC107" />
<path d="M5.25497 12.2425L10.7308 16.2583C12.2125 12.59 15.8008 9.99999 20 9.99999C22.5491 9.99999 24.8683 10.9617 26.6341 12.5325L31.3483 7.81833C28.3716 5.04416 24.39 3.33333 20 3.33333C13.5983 3.33333 8.04663 6.94749 5.25497 12.2425Z" fill="#FF3D00" />
<path d="M20 36.6667C24.305 36.6667 28.2167 35.0192 31.1742 32.34L26.0159 27.975C24.3425 29.2425 22.2625 30 20 30C15.665 30 11.9842 27.2359 10.5975 23.3784L5.16254 27.5659C7.92087 32.9634 13.5225 36.6667 20 36.6667Z" fill="#4CAF50" />
<path d="M36.3425 16.7358H35V16.6667H20V23.3333H29.4192C28.7592 25.1975 27.56 26.805 26.0133 27.9758C26.0142 27.975 26.015 27.975 26.0158 27.9742L31.1742 32.3392C30.8092 32.6708 36.6667 28.3333 36.6667 20C36.6667 18.8825 36.5517 17.7917 36.3425 16.7358Z" fill="#1976D2" />
</svg>
</div>
<span class="w-5/6 px-4 py-3 font-bold text-center">Sign in with Google</span>
</a> --}}
<form action="/register" method="POST">
@csrf
<div class="flex items-center justify-between mt-4">
<span class="w-1/5 border-b dark:border-gray-600 lg:w-1/4"></span>
<a href="#" class="text-xs text-center text-gray-500 uppercase dark:text-gray-400 hover:underline">Login / Register</a>
<span class="w-1/5 border-b dark:border-gray-400 lg:w-1/4"></span>
</div>
<div class="mt-4">
<label class="block mb-2 text-sm font-medium text-gray-600 dark:text-gray-200" for="LoggingEmailAddress">Name</label>
<input value="Hasin" id="name" name="name" class="block w-full px-4 py-2 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-400 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring focus:ring-blue-300">
</div>
<div class="mt-4">
<label class="block mb-2 text-sm font-medium text-gray-600 dark:text-gray-200" for="LoggingEmailAddress">Email Address</label>
<input value="me@hasin.me" id="LoggingEmailAddress" name="email" class="block w-full px-4 py-2 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-400 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring focus:ring-blue-300" type="email">
</div>
<div class="mt-4">
<div class="flex justify-between">
<label class="block mb-2 text-sm font-medium text-gray-600 dark:text-gray-200" for="loggingPassword">Password</label>
<a href="#" class="text-xs text-gray-500 dark:text-gray-300 hover:underline"></a>
</div>
<input value="abcd" id="loggingPassword" name="password" class="block w-full px-4 py-2 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-400 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring focus:ring-blue-300" type="password">
</div>
<div class="mt-8">
<button class="w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none focus:bg-gray-600">
Login
</button>
</div>
<div class="flex items-center justify-between mt-4">
<span class="w-1/5 border-b dark:border-gray-600 md:w-1/4"></span>
<a href="#" class="text-xs text-gray-500 uppercase dark:text-gray-400 hover:underline">or sign up</a>
<span class="w-1/5 border-b dark:border-gray-600 md:w-1/4"></span>
</div>
</form>
{{-- <button onclick="app.login()">Login With Axios</button> --}}
</div>
</div>
</div>
</body>
<script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
</html>

@ -25,14 +25,12 @@
@if (Route::has('login'))
<div class="hidden fixed top-0 right-0 px-6 py-4 sm:block">
@auth
<a href="{{ url('/') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Home</a>
<a href="{{ url('/logout') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Logout</a>
<a href="{{ url('/home') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Home</a>
@else
<a href="{{ route('login') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Log in</a>
@if (Route::has('register'))
<a href="{{ route('register') }}"
class="ml-4 text-sm text-gray-700 dark:text-gray-500 underline">Register</a>
<a href="{{ route('register') }}" class="ml-4 text-sm text-gray-700 dark:text-gray-500 underline">Register</a>
@endif
@endauth
</div>
@ -46,11 +44,6 @@
</g>
</svg>
</div>
@if (Auth::check())
<div class="flex justify-center pt-8 sm:justify-start sm:pt-0">
<h1 class="pt-8 text-lg leading-7 font-semibold text-gray-600 dark:text-gray-400">Welcome, {{Auth::user()->name}}</h1>
</div>
@endif
<div class="mt-8 bg-white dark:bg-gray-800 overflow-hidden shadow sm:rounded-lg">
<div class="grid grid-cols-1 md:grid-cols-2">

@ -1,7 +1,6 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LoginSPAController;
/*
|--------------------------------------------------------------------------
@ -16,9 +15,4 @@ use App\Http\Controllers\LoginSPAController;
Route::get('/', function () {
return view('welcome');
})->name('home');
Route::post('/register',[LoginSPAController::class,'register']);
Route::post('/login',[LoginSPAController::class,'login']);
Route::get('/logout',[LoginSPAController::class,'logout'])->name('logout');
Route::get('/login',[LoginSPAController::class,'loginForm'])->name('login');
});

Loading…
Cancel
Save