⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Redirect on callback_update



die_for_rock_vn
  • profile picture
  • Member

Posted 22 November 2014 - 08:17 AM

I use ion_auth as user management. If an user change his password, the site will redirect to logout controller. But if he is admin and he changes password for another user, it doesn't need logout.

My code:

$crud->callback_update ( array (
$this,
'edit_user_callback' 
) );

Function edit_user_callback

function edit_user_callback($post_array, $primary_key = null) {
$email = $post_array ['email'];
$groups = $post_array ['groups'];

if ($post_array ['change_password'] == 0) {
$data = array (
'email' => $email 
);
} else {
$password = $post_array ['password'];
$data = array (
'email' => $email,
'password' => $password 
);
}
$this->ion_auth->update ( $primary_key, $data, $groups );
if (($primary_key == $this->ion_auth->get_user_id ()) && (isset ( $post_array ['password'] ))) {
   //need redirect here
redirect ( 'auth/logout' );
}
return true;
}

It doesn't redirect and stuck at edit page.

I already read www.grocerycrud.com/forums/topic/324-workaround-redirect-to-the-list-after-insertupdate-without-changing-the-core-functionality-of-gc/

but it doesn't help, I only need redirect if condition is true.

Could you please help me?

Thank.

 


Amit Shah
  • profile picture
  • Member

Posted 22 November 2014 - 09:34 AM

well.. u cannot do a url redirect from callback_update - because it rather is an ajax call and is supposed to return response string

rather - u can use something like this

$crud->set_lang_string('update_success_message',
         'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
         <script type="text/javascript">
         window.location = "'.site_url(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
         </script>
         <div style="display:none">
         '
);

Now here - u can restrict the redirect based on the type of user who is acting for the same. Hope this helps you out.

 

Happhy GCing :)


die_for_rock_vn
  • profile picture
  • Member

Posted 22 November 2014 - 16:53 PM

well.. u cannot do a url redirect from callback_update - because it rather is an ajax call and is supposed to return response string

rather - u can use something like this

$crud->set_lang_string('update_success_message',
         'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
         <script type="text/javascript">
         window.location = "'.site_url(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
         </script>
         <div style="display:none">
         '
);

Now here - u can restrict the redirect based on the type of user who is acting for the same. Hope this helps you out.

 

Happhy GCing :)

I've already read this workaround, but it redirects every update.

How to use this code with the condition that get on callback_update? I've tried many times but it didn't work.

I'm not a web developer so it's hard for me.

Could you please make a sample code?

Have a nice weekend.

Thank you.


Amit Shah
  • profile picture
  • Member

Posted 22 November 2014 - 18:57 PM

well.. in the controller - u will be able to retrieve the logged in user..

based on the user level .. set the workaround accordingly.. its that simple. it is all on the user levels if condition whether or not the user will be redirected or not