Ad

Octobercms Onstart Flash Message

- 1 answer

I'm using the User plugin and I wanted to know how can I flash messages to the user when they login (new session) and logout.

Tried using this when a client logs in, but it doesn't make sense as it will always show up when the page is refreshed.

<p data-control="flash-message" data-interval="5" class="success">
    {{message}}
</p>

Thanks

Ad

Answer

Use the hooks/events

rainlab.user.login: The user has successfully signed in.

rainlab.user.logout: The user has successfully signed out.

  1. Create a new Plugin with the builder

  2. in the plugin.php write in the boot function:

    Event::listen('rainlab.user.login', function($user) {
     Flash::success(Successfully Logged in)
    });
    Event::listen('rainlab.user.logout', function($user) {
     Flash::success(Successfully Logged out)
    });
  1. dont change the vendor code because is a bad practice.

more to the events https://octobercms.com/docs/services/events

and to the list of the user events https://github.com/rainlab/user-plugin#events

Ad
source: stackoverflow.com
Ad