Giter VIP home page Giter VIP logo

laravel_custom_auth_with_bootstrap's Introduction

Custom Auth

This is a simple laravel, blade and Bootstrap app that implement a custom user authentication without needing starter kit like laravel Breeze.

Key Feature

  • Authentication
  • Redirects
  • Route groups
  • Validation
  • sessions
  • Database Migration

Technologies

Sample Code

Product Route

Route::get('/', [AuthController::class, 'index'])->name('welcome');

Route::get('login', [AuthController::class, 'login'])->name('login');
Route::post('login', [AuthController::class, 'loginPost'])->name('login.post');


Route::get('register', [AuthController::class, 'register'])->name('register');
Route::post('register', [AuthController::class, 'registerPost'])->name('register.post');

Route::get('logout', [AuthController::class, 'logOut'])->name('logout');


Route::middleware(['auth'])->group(function () {
    Route::get('profile', function () {
        return 'Profile resource';
    })->name('profile');

Auth Controller Resource

public function index()
    {
        return View('welcome_to_custom_auth');
    }
    public function login()
    {
        if (Auth::check()) {
            return redirect(route('welcome'));
        }
        return View('login');
    }

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

        $credentials = $request->only('email', 'password');

        if (Auth::attempt($credentials)) {
            return redirect()->intended(route('welcome'))->with('success', 'You are welcome.');
        }

        return redirect(route('login'))->with('error', 'Login details are not valid');
    }


    public function register()
    {
        if (Auth::check()) {
            return redirect(route('welcome'));
        }
        return View('register');
    }

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

        $data = [
            'name' => $request->username,
            'email' => $request->email,
            'password' => Hash::make($request->password),
        ];

        $user = User::Create($data);

        if (!$user) {
            return redirect(route('register'))->with('error', 'Sorry Something went wrong!');
        }
        return redirect(route('login'))->with('success', 'welcome!');
    }

    public function logOut()
    {
        Session::flush();
        Auth::logout();

        return redirect(route('login'));
    }

Screen shots

home Login Register

laravel_custom_auth_with_bootstrap's People

Contributors

musingabrian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.