GithubHelp home page GithubHelp logo

spiderwebtr / isauth Goto Github PK

View Code? Open in Web Editor NEW
133.0 9.0 18.0 55 KB

This package provides control to check if user session dead before submit forms. If the session is dead, a modal will reveal and ask password to re-login.

License: MIT License

PHP 37.00% JavaScript 55.65% Blade 7.35%
isauth login-modal

isauth's Introduction

isAuth

alt text alt text alt text alt text alt text

This package provides control to check if user session dead before submit forms. If the session is dead, a modal will reveal and ask password to re-login.

1- Installation

Require this package with composer.

composer require spiderwebtr/isauth

1.2- Laravel < 5.5

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

spiderwebtr\isauth\isAuthServiceProvider::class,

2- Create assets and config file

Run the command to create the js and config files.

php artisan vendor:publish --provider="spiderwebtr\isauth\isAuthServiceProvider" --force --tag="public" --tag="config"

3- Edit config/isAuth.php

Under config folder, you'll see isAuth config file. Edit the fields for customizations.

return [
    "middleware"=>['web'], //for laravel routes (web,api...)
    "options"=>[
        "loginField"=>"email", //If your project uses username to login, change it with "username".
        "texts"=>[ //translate
            "placeholder"=>"Type Your Password",
            "wrong"=>"Wrong Password",
            "error"=>"Error",
            "button"=>"Login"
        ]
    ],
];

4- Include JQuery,Sweet Alert and @isAuthAssets in your footer

You can download the js files or just use cdn. @isAuthAssets will call isAuth.js and define auth object with your config.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
@isAuthAssets([
    "user"=>auth()->user(),
    "photo"=>$user->avatar //(not required) if you use avatar in your user system, pass the url of your user's avatar to "photo" key, if you don't use avatar, you can remove the key in array
])

Extras

๐Ÿ”ฅ isAuth function

isAuth function takes a callback parameter so in your code you can call isAuth to check the session before doing your js stuff.

auth.isAuth(function(){
    //do something 
});

Login modal will reveal if the session is dead. When you re-login, your code will work with callback.

Contributors

Feedback

If you give me some feedback I will be happy. You can show your satisfaction with star. โญ

Update Guide

  • v1.1 - If you downloaded the package in development version (dev-master), please remove it apply Installation Guide from this readme file (require,Create assets,Last Step).
  • v1.2 - Delete the js codes in footer, then start from step 2

isauth's People

Contributors

emredipi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

isauth's Issues

Remove jQuery dependency

Looks like a cool package :)

Would you be okay with accepting a PR removing the jQuery dependency? I don't think it's necessary, as Sweet Alert don't depend on it?

Keep up the good work!

remove laravel-medialibrary from examples

Hi. the example you have uses Spatie's Laravel-MediaLibrary ( getFirstMediaUrl() ).

As this is not actually required by your code, you could use the $user->avatar (insert model's key for your user's profile image)

...then include the current laravel-medialibrary example as a helpful alternative for those use it.

Unable to install package in Laravel v5.2 and in Laravel v5.5

Hi,

I've tried to install the package in Laravel version v5.2 and v5.5 and in both, everytime the method boot is called in the "isAuthServiceProvider", the following error is returned:

In Facade.php line 221:
  Call to undefined method Illuminate\View\Compilers\BladeCompiler::include()

Have you had any issues with this before?

Thanks for your time!

publish to public/vendor

Hi,
Just to follow the guidelines used of Laravel and others, would you please consider publishing your assets to public/vendor/spiderwebtr/ (lowercase) rather then to public/assets/SpiderWebtr

ty.

Guard options

Looking forward to testing this out, but I would need an option to use "guard", for example: Auth::guard('admin')->check()

sweetalert2 support?

Hello.
Is a code update planned for support of SweetAlert2? (with no "icon" option, Swal.fire instead of swal(), etc.)
Thank you.

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.