Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 1 | import webnotes |
Anand Doshi | 90f6e55 | 2012-01-16 14:13:39 +0530 | [diff] [blame] | 2 | import webnotes.defs |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 3 | from webnotes.utils import cint |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 4 | import home |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 5 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 6 | def on_login(login_manager): |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 7 | """ |
| 8 | called from login manager, before login |
| 9 | """ |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 10 | if login_manager.user not in ('Guest', None, ''): |
| 11 | try: |
Rushabh Mehta | 88ba7b8 | 2012-01-18 06:18:52 +0100 | [diff] [blame] | 12 | import server_tools.gateway_utils |
| 13 | server_tools.gateway_utils.check_login(login_manager.user) |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 14 | except ImportError: |
| 15 | pass |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 16 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 17 | def on_login_post_session(login_manager): |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 18 | """ |
| 19 | called after login |
| 20 | update login_from and delete parallel sessions |
| 21 | """ |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 22 | # Clear previous sessions i.e. logout previous log-in attempts |
Rushabh Mehta | d31bf62 | 2012-01-19 15:09:49 +0530 | [diff] [blame] | 23 | exception_list = ['demo@webnotestech.com', 'Administrator', 'Guest'] |
Anand Doshi | 9fdee38 | 2012-01-03 11:26:00 +0530 | [diff] [blame] | 24 | if webnotes.session['user'] not in exception_list: |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 25 | sid_list = webnotes.conn.sql(""" |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 26 | DELETE FROM `tabSessions` |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 27 | WHERE |
| 28 | user=%s AND |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 29 | sid!=%s""", \ |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 30 | (webnotes.session['user'], webnotes.session['sid']), as_list=1) |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 31 | |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 32 | if webnotes.session['user'] not in ('Guest'): |
| 33 | # create feed |
| 34 | from webnotes.utils import nowtime |
| 35 | home.make_feed('Login', 'Profile', login_manager.user, login_manager.user, |
| 36 | '%s logged in at %s' % (login_manager.user_fullname, nowtime()), |
| 37 | login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') |
| 38 | |
| 39 | def comment_added(doc): |
| 40 | """add comment to feed""" |
| 41 | import json |
| 42 | home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, |
| 43 | '<i>"' + doc.comment + '"</i>', '#6B24B3') |
| 44 | |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 45 | def doclist_all(doc, method): |
| 46 | """doclist trigger called from webnotes.model.doclist on any event""" |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 47 | home.update_feed(doc, method) |
| 48 | |
| 49 | def boot_session(bootinfo): |
| 50 | """boot session - send website info if guest""" |
| 51 | import webnotes |
| 52 | import webnotes.model.doc |
| 53 | |
| 54 | if webnotes.session['user']=='Guest': |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 55 | bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings') |
Rushabh Mehta | f35992f | 2012-02-07 10:39:17 +0530 | [diff] [blame] | 56 | bootinfo['website_menus'] = webnotes.conn.sql("""select label, url, custom_page, |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 57 | parent_label, parentfield |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 58 | from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1) |
| 59 | bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or '' |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 60 | else: |
| 61 | bootinfo['letter_heads'] = get_letter_heads() |
| 62 | |
| 63 | def get_letter_heads(): |
| 64 | """load letter heads with startup""" |
| 65 | import webnotes |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 66 | ret = webnotes.conn.sql("""select name, content from `tabLetter Head` |
| 67 | where ifnull(disabled,0)=0""") |
Rushabh Mehta | 4b1fe05 | 2012-01-25 15:06:28 +0530 | [diff] [blame] | 68 | return dict(ret) |