This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Vojta Svoboda
Vojta Svoboda

I need to know if User changed default password or not, because I want to show "Please change default password right now!". Default password is always 'test123'. So I want extend RainLab\User\Models\User class, and add method (bool) isPasswordChanged().

function isPasswordChanged() { // create Crypt and compare it with $user->password }

What is the best practise? I watched this video https://vimeo.com/108040919, but it is only about overriding 'backend configuration'. I try to listening on Event::listen('rainlab.user.login'), but it doesn't work at all. Btw where I can find list of all User predefined events?

Sandip Shinde
Sandip Shinde

Hello Vojta,

Have you found any solution for this? I wanted to listen user signin and signout event...

Please share if you found any solution.

Thanks!

Last updated

Vojta Svoboda
Vojta Svoboda

Yes I created pull request, you can send 'thumbs up' to comments below issue :)

https://github.com/rainlab/user-plugin/pull/111

Sandip Shinde
Sandip Shinde

Thanks for quick response!

Will I have to modify existing components/Account.php file to add a Event::fire?

Bcoz, it will override these changes if I update October CMS.

Please confirm!

Flynsarmy
Flynsarmy

An alternative would be to create a new plugin and add a component that extends rainlab's account component, adding your required functionality. Something like:

<?php namespace Your\Plugin\Components;

use Lang;
use Auth;
use Mail;
use Flash;
use Input;
use Redirect;
use Validator;
use ValidationException;
use ApplicationException;
use Cms\Classes\Page;
use Cms\Classes\ComponentBase;
use RainLab\User\Models\Settings as UserSettings;
use Exception;

class Account extends \RainLab\User\Components
{
    /**
     * Sign in the user
     */
    public function onSignin()
    {
        /*
         * Validate input
         */
        $data = post();
        $rules = [];

        $rules['login'] = $this->loginAttribute() == UserSettings::LOGIN_USERNAME
            ? 'required|between:2,64'
            : 'required|email|between:2,64';

        $rules['password'] = 'required|min:2';

        if (!array_key_exists('login', $data)) {
            $data['login'] = post('username', post('email'));
        }

        $validation = Validator::make($data, $rules);
        if ($validation->fails()) {
            throw new ValidationException($validation);
        }

        /*
         * Authenticate user
         */
        $user = Auth::authenticate([
            'login' => array_get($data, 'login'),
            'password' => array_get($data, 'password')
        ], true);

        // your code here

        /*
         * Redirect to the intended page after successful sign in
         */
        $redirectUrl = $this->pageUrl($this->property('redirect'));

        if ($redirectUrl = post('redirect', $redirectUrl))
            return Redirect::intended($redirectUrl);
    }
}
Sandip Shinde
Sandip Shinde

I created new component under my plugin, but it does not get called after user login.

Will I have to make any additional changes to get my component called?

Also, I have to listen to backend user login and logout event.

Thanks in advance!

chris10207
chris10207

im facing the same kind of requirement, i need to know when the user has activated his account so that some custom code can run after, like updating some statistics or sending an email to the admin, etc...

firing event from the rainlab user account component sound a good approach, overriding the account component is another one i guess but i didnt test it yet.

Vojta Svoboda
Vojta Svoboda

In last version you can use three predefined Events, see https://github.com/rainlab/user-plugin/blob/master/README.md#events

It's:

  • rainlab.user.login
  • rainlab.user.deactivate
  • rainlab.user.reactivate
Event::listen('rainlab.user.login', function($user) {
    // User has logged in
});

For create/update/delete User model you can use Eloquent events:

Event::listen('eloquent.created: RainLab\User\Models\User', function($model) {
     // User created
});

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.