@rmehta. I was hoping you could personally answer this.
I’ve been digging into frappe/erpnext documentation for a few weeks now. I’ve been through most of your video tutorials. I have a dev server that I spun up, but I would like to forward my system users to pages respective to their tasks on login instead of /desk. I’ve been all over these forums attempting to use hooks in a custom application I am writing. I’ve attempted to utilize “role_home_page”, and this is not a surefire way to get the redirect to occur.
On login, my user will get an error saying the page is missing, but once they click “Home” they are forwarded to http://myserversip:8000. I’ve also attempted to create my own boot_session and on_session_creation hooks. These yield similar results of redirecting only after an error is given in the web view. So then I was digging through auth and login in the frappe framework. In auth, I found set_user_info which is called in post_login. I found that run_trigger_(‘on_login’) is called, so I created a hook for it to attempt to redirect the user on login. The issue with this is that set_user_info() happens at the end of the post_login definition, which means no matter what I do, the frappe set_user_info function will forward my user -no matter what- to /desk. So what I did is create a set_user_info of my own, added hooks for it, and called a run_trigger(‘on_after_login’) and coupled those with use of role_home_page in my hooks to force my redirects .
I’m attempting to complete the redirect without having to change any of the frappe files so I can continue to get updates without having to rewrite my changes every time.
Alas, I have two questions.
One: How can I complete a system user redirect without changing ANY FRAPPE CODE?
Two: If this is not possible, how would you recommend I go about it? This is my current solution, but it involves changing frappe code, and I don’t want to do that for this to work. See below:
def post_login(self):
self.run_trigger('on_login')
self.validate_ip_address()
self.validate_hour()
self.make_session()
self.set_user_info()
self.run_trigger('on_after_login')
This hooks up to my own set_user_info function for the redirection. This is what it looks like:
def on_after_login(login_manager):
set_user_info(login_manager)
def set_user_info(login_manager, resume=False):
login_manager.info = frappe.db.get_value("User", login_manager.user,
["user_type", "first_name", "last_name", "user_image"], as_dict=1)
if login_manager.info.user_type != "Website User" and not resume:
frappe.local.response["home_page"] = "/"
This solution works, but it requires me to add the run_trigger in auth.post_login. The other way I could do this in simply change frappe.local.response[“home_page”] = “/desk” to frappe.local.response[“home_page”] = “/”. Again, either one of these will require changes to auth and the frappe framework. If Erp were to accept or make this change in the framework, many people could make use of it, and we could continue our pulls as your team updates ErpNext/Frappe.