GithubHelp home page GithubHelp logo

dimahali / isauth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spiderwebtr/isauth

0.0 0.0 0.0 8 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.

PHP 30.32% JavaScript 69.68%

isauth's Introduction

isAuth

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.

Installation

Require this package with composer.

composer require spiderwebtr/isauth

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,

Create assets

Run the command to create the js file.

php artisan vendor:publish --tag=public --force

Include JQuery and Sweet Alert

You can download the js files or just use cdn.

<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>

Last Step

Add this code to the footer in your blade. user object provides information in login modal.

<script src="/assets/SpiderWebtr/isAuth/isAuth.js"></script>
<script>
    let user={
        name:"{{$user->name}}",
        email:"{{$user->email}}",
        photo:"{{$user->getFirstMediaUrl("image","thumb")}}" //edit this up to your system or just remove this line.
    };
    let auth=defineIsAuth(user);
</script>
<style>
    .swal-icon--custom>img{
        max-height: 250px;
        border-radius: 50%;
    }
</style>

Extras

Translation and Customization

If you require a field other than email address to authenticate this can be passed in an optional settings object as the second parameter. This settings object can also be used to override the default text used for labels and user feedback messages.

The field authenticated against will use the default email. If your project uses username to login, change it with username.

<script>
    let user={
        name:"{{$user->name}}",
        username:"{{$user->username}}",
        photo:"{{$user->getFirstMediaUrl("image","thumb")}}" //edit this up to your system or just remove this line.
    };
    let auth=defineIsAuth(user,{
        texts:{ //change strings to your language
            placeholder:"Type Your Password",
            wrong:"Wrong Password",
            error:"Error",
            button:"Login"
        },
        loginField:"username" //your laravel login field
    });
</script>

isAuth Function

isAuth function takes a callback parameter so in your code you can call isAuth from the object you defined.

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 from version dev-master to 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).

isauth's People

Contributors

emredipi 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.