First time login redirect

I want to redirect my members to profile edit page at first login.. i saw plugins available for 1.7.x 

but not available for 1.8.3 .. so is there any way so that i can redirect my new members to profile edit page for there first login...

  • Not sure if there is a plugin to actually do it but the coding is trivial:

    In a plugin's start.php file add the following:

    elgg_register_event_handler('login','user','check_first_login');

     

    function check_first_login($login_event, $user_type, $user) {

    if($user && $user->last_login == 0) {

    forward("PUT URL IN HERE");

    }

    }

    }

     

  • Thanks Trajan let me try it ....

  • for redirecting user to profile edit page... in forward("PUT URL IN HERE") I dont know how to give it as.. the url is like this "[base url]/profile/username/edit" for the username how should i get the input of the new user.. I am not a coder so i dont know wat url to put for redirecting users to profile edit page..

                         Thank you

  • for 1.8 i am using this code in my theme

    function check_first_login($login_event, $user_type, $user) {
    $user = elgg_get_logged_in_user_entity();
    if($user && $user->last_login == 0) {
    forward('profile/$user->username/edit/');
    }else if($user && $user->prev_last_login == 0) {
    forward('import');
    }else{
    forward('activity');
    }
    }

  • not sure what prev_last_login would be if anything. Last login (from guessing) holds a timestamp and updates every time a user logs in.

    @Satheesh...is prev_last_login working for you to send users to 'import'?

  • @trajan   i just checkd by changing ==0 to !=0

    it was working for me...

  • last_login is the last time he logged in..
    prev_last_login is the 'previous' (second) (also TS) to the last time he logged in ;-)
    so.. if last == 0 -> he's never logged in
    else if prev_last == 0 -> he's only logged in once
    else he's logged in >= 2x


  • In case any one looks at this.

    Trajan's solution does not work because Elgg's forward() function exits immediately upon setting the location header and so the rest of the code in the login() function is not executed. This (crucially) includes the code to set the last login time! So as a result, the first login action would get repeated over and over again each time the user logs in.

    I solved this by copying some of the lines from the login function to my first login function, including the bit that sets the last login time.

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.