Return To Last Url Entered After Successfull Login

i have function login on its sucessufull function control goes to dashboard/index , Suppose a user enter leads/index the page come back to login due i access rules defined , i just want that after successful login control goes to last url entered ie leads/index

thanks for your help

checkout the returnUrl option: