blob: d9fb4511a83403d24f67ec7b82eb25df1ab95277 [file] [log] [blame]
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05301import webnotes
Anand Doshi90f6e552012-01-16 14:13:39 +05302import webnotes.defs
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05303from webnotes.utils import cint
4
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05305def on_login(login_manager):
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +05306 """
7 called from login manager, before login
8 """
9 try:
Rushabh Mehta88ba7b82012-01-18 06:18:52 +010010 if login_manager.user not in ('Guest', None, ''):
11 import server_tools.gateway_utils
12 server_tools.gateway_utils.check_login(login_manager.user)
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053013 except ImportError:
14 pass
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053015
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053016
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053017def on_login_post_session(login_manager):
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053018 """
19 called after login
20 update login_from and delete parallel sessions
21 """
Anand Doshib63a0072012-01-03 16:11:04 +053022 # Clear previous sessions i.e. logout previous log-in attempts
Rushabh Mehtad31bf622012-01-19 15:09:49 +053023 exception_list = ['demo@webnotestech.com', 'Administrator', 'Guest']
Anand Doshi9fdee382012-01-03 11:26:00 +053024 if webnotes.session['user'] not in exception_list:
Anand Doshib63a0072012-01-03 16:11:04 +053025 sid_list = webnotes.conn.sql("""
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053026 DELETE FROM `tabSessions`
Anand Doshib63a0072012-01-03 16:11:04 +053027 WHERE
28 user=%s AND
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053029 sid!=%s""", \
Anand Doshib63a0072012-01-03 16:11:04 +053030 (webnotes.session['user'], webnotes.session['sid']), as_list=1)
Rushabh Mehta49ebfb62012-01-20 15:32:18 +053031
32def doclist_all(doc, method):
33 """doclist trigger called from webnotes.model.doclist on any event"""
34 import home
Rushabh Mehta865c00a2012-01-24 14:33:21 +053035 home.update_feed(doc, method)
36
37def boot_session(bootinfo):
38 """boot session - send website info if guest"""
39 import webnotes
40 import webnotes.model.doc
41
42 if webnotes.session['user']=='Guest':
Rushabh Mehta7018b192012-02-02 13:42:28 +053043 bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings')
44 bootinfo['website_menus'] = webnotes.conn.sql("""select label, std_page, custom_page,
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053045 parent_label, parentfield
Rushabh Mehta7018b192012-02-02 13:42:28 +053046 from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1)
47 bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or ''
Rushabh Mehta865c00a2012-01-24 14:33:21 +053048 else:
49 bootinfo['letter_heads'] = get_letter_heads()
50
51def get_letter_heads():
52 """load letter heads with startup"""
53 import webnotes
54 ret = webnotes.conn.sql("select name, content from `tabLetter Head` where ifnull(disabled,0)=0")
Rushabh Mehta4b1fe052012-01-25 15:06:28 +053055 return dict(ret)