Lindelwa
Lindelwa

Reputation: 27

Octobercms onstart flash message

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

Upvotes: 0

Views: 894

Answers (1)

Peter Haberkorn
Peter Haberkorn

Reputation: 259

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

Upvotes: 1

Related Questions