Giter VIP home page Giter VIP logo

larsjanssen6 / underconstruction Goto Github PK

View Code? Open in Web Editor NEW
566.0 11.0 70.0 3.06 MB

This Laravel 8 package makes it possible for you to set your website in "Under Construction" mode. Only users with the correct 4 (or more) digit code can access your site. :fire: :boom: :fire:

License: MIT License

PHP 4.24% JavaScript 93.11% Vue 2.40% Blade 0.25%
construction underconstruction php7 vuejs2 construction-mode customizable middleware javascript webpack laravel-mix

underconstruction's Introduction

Laravel Under Construction schermafbeelding 2017-09-27 om 23 08 12

StyleCI Packagist Total Downloads

Buy Me A Coffee

This Laravel package makes it possible to set your website in "Under Construction" mode. Only users with the correct 4 digit code can access your site. This package can for example be useful to show your website to a specific client. Everything works out of the box, and it's fully customizable.

If you appreciate my work please give this repo a star or buy me a coffee ^ 🤗.

underconstruction

Installation

Begin by installing this package through Composer (Laravel 6, 7, 8, 9 and 10 compatible!).

composer require larsjanssen6/underconstruction

The \LarsJanssen\UnderConstruction\UnderConstruction::class middleware must be registered in the kernel:

//app/Http/Kernel.php

protected $routeMiddleware = [
  // ...
  'under-construction' => \LarsJanssen\UnderConstruction\UnderConstruction::class,
];

Defaults

Publish the default configuration file.

php artisan vendor:publish

# Or...

php artisan vendor:publish --provider="LarsJanssen\UnderConstruction\UnderConstructionServiceProvider"

This package is fully customizable. This is the content of the published config file under-construction.php:

<?php

return [

    /*
     * Activate under construction mode.
     */
    'enabled' => env('UNDER_CONSTRUCTION_ENABLED', true),

    /*
     * Hash for the current pin code
     */
    'hash' => env('UNDER_CONSTRUCTION_HASH', null),

    /*
     * Under construction title.
     */
    'title' => 'Under Construction',

    /*
     * Custom Route Prefix
     * */
    'route-prefix' => env('UNDER_CONSTRUCTION_ROUTE_PREFIX','under'),

    /*
     * Custom Endpoint if you don't want to use 'construction'
     * e.g. if you change to 'checkpoint', the route prefix
     * above will be appended giving you 'under/checkpoint'
     * */
    'custom-endpoint' => env('UNDER_CONSTRUCTION_CUSTOM_ENDPOINT','construction'),


    /*
     * Back button translation.
     */
    'back-button' => 'back',

    /*
    * Show button translation.
    */
    'show-button' => 'show',

    /*
     * Hide button translation.
     */
    'hide-button' => 'hide',

    /*
     * Show loader.
     */
    'show-loader' => true,

    /*
     * Redirect url after a successful login.
     */
    'redirect-url' => '/',

    /*
     * Enable throttle (max login attempts).
     */
    'throttle' => true,

        /*
        |--------------------------------------------------------------------------
        | Throttle settings (only when throttle is true)
        |--------------------------------------------------------------------------
        |
        */

        /*
        * Set the amount of digits (max 6).
        */
        'total_digits' => 4,

        /*
         * Set the maximum number of attempts to allow.
         */
        'max_attempts' => 3,

        /*
         * Show attempts left.
         */
        'show_attempts_left' => true,

        /*
         * Attempts left message.
         */
        'attempts_message' => 'Attempts left: %i',

        /*
         * Too many attempts message.
         */
        'seconds_message' => 'Too many attempts please try again in %i seconds.',

        /*
         * Set the number of minutes to disable login.
         */
        'decay_minutes' => 5,

        /*
         * Prevent the site from being indexed by Robots when locked
         */
        'lock_robots' => true,
];

Usage

You'll have to set a 4 digit code (you can change this up to 6 in config file). You can do that by running this custom artisan command (in this example the code is 1234 ,you can obviously set another code). It will generate a hash that will be stored in your .env file.

php artisan code:set 1234

You can set routes to be in "Under Construction" mode by using the under-construction-middleware on them.

Route::group(['middleware' => 'under-construction'], function () {
    Route::get('/live-site', function() {
        echo 'content!';
    });
});

Changelog

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

I would love to hear your ideas to improve my codeing style and conventions. Feel free to contribute.

Security

If you discover any security related issues, please email [email protected]. You can also make an issue.

Credits

About me

I'm Lars Janssen from The Netherlands and like to work on web projects. You can follow me on Twitter.

License

The MIT License (MIT). Please see License File for more information.

❤️ Open-Source Software - Give ⭐️

We have included the awesome symfony/thanks composer package as a dev dependency. Let your OS package maintainers know you appreciate them by starring the packages you use. Simply run composer thanks after installing this package. (And not to worry, since it's a dev-dependency it won't be installed in your live environment.)

underconstruction's People

Contributors

anandmainali avatar bjbaardse avatar bomshteyn avatar dependabot[bot] avatar f-liva avatar jpuck avatar korri avatar larsjanssen6 avatar lex111 avatar lkloon123 avatar mickacz avatar mikebronner avatar mr-feek avatar owen-oj avatar paneidos avatar scrutinizer-auto-fixer avatar shroudedcode avatar siwalikm avatar stylecibot avatar teohxuen avatar vesper8 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  avatar  avatar

underconstruction's Issues

When setting the code for the first time, the check won't work

Hi,

when setting the code initially (= .env key did not exist previously), it won't work, if the generated hash contains $ signs.
The reason is, that the string is written to the .env files with the $ escaped.

Example for APP_KEY=base64:aPAE16A9nSnU1rYuYP3VO0PsqJCthiPf65LiDJ9Jy9Y=:

php artisan code:set 1234 produces the hash $2y$10$1m1s5937qMF6IAJmPdu4DOdSd4j3NxNS1KZGVH.eNZ41LrBCYx0vO

But the entry in the .env files reads as:
UNDER_CONSTRUCTION_HASH=\$2y\$10\$zUkU2HgW7VeE2NttFx8wqe3kpanunYOh9joUlJTScSjv.Jx/JF9Di (note the escaped $ signs)

When calling the code:set command a second time, the hash is correctly written into the .env file

NEW Too many redirects

Hello thanks for your code!
I face the ERR_TOO_MANY_REDIRECTS.
I tried to fix it with the #64 solution but with no luck.
Note that i have localization in active.

In attached files you will find my web.php code
web.txt

Tell me if you need anymore information.
Thanks for your time!!

Laravel 5.6

Found this on LaraNews and would love to use it, but it doesn’t support 5.6 yet. Could you please add that?

Disable selectable button labels

Awesome package, I just love it @larsjanssen6! The only thing I don't like, is the fact that the buttons' labels can be selected, and it stays selected, even when unintentionally selected. For the record, I'm on a MacBook Pro, using the built-in trackpad. See below.
Screen Shot 2020-03-18 at 22 24 52
This annoying thing happens very often, when I'm clicking any of the buttons. Is there any way that you can update the package, so that the buttons' label elements have attached the CSS declarations below?
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;

Thanks a lot.

The payload is invalid

Hi. I installed this package. Look like awesome. but dont work when login. This problem seemed:

"message": "The payload is invalid.",
"exception": "Illuminate\Contracts\Encryption\DecryptException",
"file": "E:\OSPanel\domains\localhost\mrsadiq\vendor\laravel\framework\src\Illuminate\Encryption\Encrypter.php",
"line": 195,

multiple valid codes / different codes for different routes

building further on the usability of this package.. I am wondering what are your thoughts on how feasible it would be to add multiple valid codes, or associate certain codes with certain routes

the reason is, I use this package in my project for two reasons, for the intended reason to wall off 'in development' portions of the site for clients, but also to protect admin areas. And I would ideally prefer to use different codes so I can keep my admin area protected while giving access to certain front-end portions for the clients to see

I'd be willing to submit a PR for this but would like to hear your thoughts on what you think the best way to accomplish this would be?

thanks for your consideration!

Invalid code

It keeps saying im entering an invalid code. I ran:

php artisan code:set 1234

result: Code: "1234" is set successfully.

but it keeps getting red when entering the code.

addition of custom prefix has broken access to routes that are more than one level deep

Previoulsy when I would try to goto example.com/log-viewer/logs it would send me to example.com/under/construction, I would enter the pin and it would send me back to example.com/log-viewer/logs

This still works if I try to goto example.com/log-viewer

But if I try to go to a route that's two level deeps.. such as example.com/log-viewer/logs or example.com/horizon/dashboard

Then it will redirect me to example.com/log-viewer/under/construction

completely broken.. was working fine before

vue standalone version (vue-only)

I really love this package and use it extensively. More and more however my front-ends are vue-only and I only use Laravel as a rest api.

I find myself craving for this package's functionality in my vue-only projects. It would be cool to release a vue-only that isn't dependant on php/laravel.

I don't think it should be very hard to do but maybe I'm missing something? What are your thoughts?

Too many redirect

Too many redirects "ERR_TOO_MANY_REDIRECTS".

I'm guessing it is because even '/under/construction' is also hitting the RedirectResponse('/under/construction') in the handle method.

code not working in local env.

As in title. It works great on remote server.
The same code on my W10 + Laragon 3.2 virtual server does not approve the correct PIN.

Any suggestions?

BTW - great package

what would cause it to constantly forget that i'm "authorized" ?

For over a year now I've used this package for means that it was probably not intended for. I use it to secure my access to things like Laravel Horizon, Laravel Telescole and Laravel Log Viewer.

It works.. but it constantly.. and randomly it seems, forgets that I'm authorized shows me the screen again. For example I'll access Laravel Horizon.. I'll get to browse around for 20 seconds and then everything will stop working, and upon refreshing the page I'll be asked to enter the PIN again.

But sometimes it lets me browse for longer.. why is this happening? Is it because the session is not being persisted and as soon as Laravel Horizon attempts to make API calls in the background, on the same route that is protected by your middleware, it triggers the security check to re-occur?

I know this is out of scope, but I would appreciate your feedback on why this is happening and how to stop it from happening, so that I only have to enter the PIN once.. at least for a while.. like a few hours

Thanks in advance!

Add public demo

I think it's a good idea to have a demo so that others can take a look before installing the package.
Thanks for this cool package 🥇

Pin incorrect after following instructions.

I have run the following after installing and I can see the hash being saved in my .env

php artisan code:set 1234

I get the following response back when trying the password which 401's. I disabled the throttle in the config.

{"too_many_attempts":false,"attempts_left":false}

My composer.json

"require": {
        "php": ">=7.1.3",
        "algolia/algoliasearch-client-php": "^1.17",
        "fideloper/proxy": "~3.3",
        "gloudemans/shoppingcart": "^2.1",
        "intervention/image": "^2.3",
        "laravel/cashier": "~7.0",
        "laravel/framework": "5.5.*",
        "laravel/scout": "^3.0",
        "laravel/tinker": "~1.0",
        "larsjanssen6/underconstruction": "^5.5",
        "maatwebsite/excel": "~2.1.0",
        "maknz/slack": "^1.7",
        "needim/noty": "^3.1",
        "roumen/sitemap": "2.6.*",
        "spatie/laravel-cookie-consent": "^1.2",
        "spatie/laravel-medialibrary": "3.0.0",
        "unisharp/laravel-filemanager": "^1.8",
        "uxweb/sweet-alert": "~1.1",
        "webpatser/laravel-uuid": "2.*"
},

Dynamic redirect-url

Hi,

It is possible to set a dynamic url like the previous requested url?

Examples:
requested url: http://localhost/user
underconstruction package url: http://localhost/under/construction
redirect-url: http://localhost/user

Thanks for reply.

gitignore

Also add .gitignore file and add .idea and vendor in there.

Url Not Found Issue After Installation

First You Did great work. I did fresh install your package when added the middleware its redirect me and gives me 404 URL not found an error you can see in the below screenshot.

Screenshot 2020-02-22 at 3 09 30 PM

error installing on Laravel 5.5

getting this error right now

Problem 1
    - Installation request for larsjanssen6/underconstruction ^1.2 -> satisfiable by larsjanssen6/underconstruction[1.2].
    - Conclusion: remove laravel/framework v5.5.31
    - Conclusion: don't install laravel/framework v5.5.31
    - larsjanssen6/underconstruction 1.2 requires illuminate/support ~5.6.0 -> satisfiable by illuminate/support[5.6.x-dev, v5.6.0, v5.6.1, v5.6.2], laravel/framework[5.6.x-dev, v5.6.0, v5.6.1, v5.6.2].
    - Can only install one of: laravel/framework[5.6.x-dev, v5.5.31].
    - Can only install one of: laravel/framework[v5.6.0, v5.5.31].
    - Can only install one of: laravel/framework[v5.6.1, v5.5.31].
    - Can only install one of: laravel/framework[v5.6.2, v5.5.31].
    - don't install illuminate/support 5.6.x-dev|don't install laravel/framework v5.5.31
    - don't install illuminate/support v5.6.0|don't install laravel/framework v5.5.31
    - don't install illuminate/support v5.6.1|don't install laravel/framework v5.5.31
    - don't install illuminate/support v5.6.2|don't install laravel/framework v5.5.31
    - Installation request for laravel/framework (locked at v5.5.31) -> satisfiable by laravel/framework[v5.5.31].

I thought maybe I had to run composer update first so I did, still getting the same error however

Problem 1
    - Installation request for larsjanssen6/underconstruction ^1.2 -> satisfiable by larsjanssen6/underconstruction[1.2].
    - Conclusion: remove laravel/framework v5.5.34
    - Conclusion: don't install laravel/framework v5.5.34
    - larsjanssen6/underconstruction 1.2 requires illuminate/support ~5.6.0 -> satisfiable by illuminate/support[5.6.x-dev, v5.6.0, v5.6.1, v5.6.2], laravel/framework[5.6.x-dev, v5.6.0, v5.6.1, v5.6.2].
    - Can only install one of: laravel/framework[5.6.x-dev, v5.5.34].
    - Can only install one of: laravel/framework[v5.6.0, v5.5.34].
    - Can only install one of: laravel/framework[v5.6.1, v5.5.34].
    - Can only install one of: laravel/framework[v5.6.2, v5.5.34].
    - don't install illuminate/support 5.6.x-dev|don't install laravel/framework v5.5.34
    - don't install illuminate/support v5.6.0|don't install laravel/framework v5.5.34
    - don't install illuminate/support v5.6.1|don't install laravel/framework v5.5.34
    - don't install illuminate/support v5.6.2|don't install laravel/framework v5.5.34
    - Installation request for laravel/framework (locked at v5.5.34) -> satisfiable by laravel/framework[v5.5.34].

How to disable the package?

As locally the package doesn't work properly, I decided to disable it.

  1. There is no unset command to do that
  2. The entry in config file 'enabled' => false, solved the problem. Still, a command would be a good thing. Should I create a PR?

L6 support

Hi,

any plans to add L6.0 support?

thanks

upload project errors -laravel 5.5

hay
the underconstruction package its work normally and useing pin correct but when upload to live hosting cpanel
the same pin not working ???
say the pin its incorrect whenever on local working normally with the same project and pin

Use link from config file instead of hardcoded

Hi,

Right now in my under construction package I use this link /under/construction.

It would be awesome if the user could determine this link by it self. The user has to set this link in config.php.

Please update my tests aswel.

Thanks a lot.

[Question] Pin Code Length

Hoi,

Love the idea of this package.
Is there a reason why the package only supports a pin code of 4 numbers and not 6 for example?

I am curious as to why it has been restricted to a specific amount of numbers.
I would be willing to make a PR to adjust it so that the user can self decide the length.

Add tests with Laravel dusk

Hi,

I'm using Vue.js and Laravel in this package. I would like to implement some tests with Laravel dusk. Right now I can't test some things.

For example:

  • After a successful login test the redirect url. (Right now I cannot do this because I make a post request with axios to check the code and then I redirect)

  • When user has disabled throttle in config.php file, no attempt messages should be visible.

  • When the hide button is clicked no numbers should be visible.

  • When the wrong code is entered the class wrong_code should be visible.

  • When the correct code is entered the class success_code should be visible.

Would be awesome to implement this in my package!

https://laravel.com/docs/5.5/dusk

Obviously you could add/improve my tests that I have right now.

Thanks a lot!

404 on http//mysite/under/js

Hi,
I don't know why but this morning one of my site under production don't want to show anything on the login page.
When i go to the website i have white page with no error in the debugbar. There is a 404 for this request url https://www.mysite.com/under/js
Very strange beacause yesterday everything was ok.

For the same site in local/dev no problem.

I cleared session, cache, view, route and config. Desinstall/reinstall all the package but nothing.

Did you have this probleme before ?

Redirect URL Suggestions

Hi, the redirect URL after success is even better if it is dynamically passed in.

Thank you for your contribution.

Cannot redirect to visit url after passing

composer require garygreen/pretty-routes

app/Http/Kernel.php

protected $routeMiddleware = [
	'under.construction' => \LarsJanssen\UnderConstruction\UnderConstruction::class,
]

config/pretty-route.php

return [
	'url'           => 'backend/routes',
	'middlewares'   => ['under.construction'],
]

request : https://dev.test/backend/routes

redirect: https://dev.test/

After verification, it jumps to the root address.

Is it possible to automatically record the current access address and jump to the address of the record after verification?

Thank you for your project!

Cannot Install on Laravel 8.34.0

Good day!

I've tried installing this package on Laravel v8.34.0
I'm able to use this package on other versions, except for the one above.

Here's the screenshot for reference.
image

make changes on the pin

Hi there,

Is there away for us to change the way the code being shown. Maybe make it smaller?

Logout or exit to pin code page

Great package!

I am using this package, implemented in my shopping list web-application, made in Laravel 5.8.

Everything is working very well, but I want to manually logout/exit from the application when I click a button. What route/method should I call?

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.