Rushabh Mehta | ce1d527 | 2013-01-09 16:39:27 +0530 | [diff] [blame] | 1 | # ERPNext: Copyright 2013 Web Notes Technologies Pvt Ltd |
| 2 | # GNU General Public License. See "license.txt" |
| 3 | |
Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 4 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 5 | from __future__ import unicode_literals |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 6 | import webnotes |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 7 | import home |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 8 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 9 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 10 | def on_login_post_session(login_manager): |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 11 | """ |
| 12 | called after login |
| 13 | update login_from and delete parallel sessions |
| 14 | """ |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 15 | # Clear previous sessions i.e. logout previous log-in attempts |
Rushabh Mehta | 686022f | 2012-12-12 15:25:51 +0530 | [diff] [blame] | 16 | allow_multiple_sessions = ['demo@erpnext.com', 'Administrator', 'Guest'] |
| 17 | if webnotes.session['user'] not in allow_multiple_sessions: |
| 18 | from webnotes.sessions import clear_sessions |
| 19 | clear_sessions(webnotes.session.user, keep_current=True) |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 20 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 21 | # check if account is expired |
| 22 | check_if_expired() |
| 23 | |
Nabin Hait | 8bbc5a2 | 2012-11-05 18:58:15 +0530 | [diff] [blame] | 24 | if webnotes.session['user'] not in ('Guest', 'demo@erpnext.com'): |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 25 | # create feed |
| 26 | from webnotes.utils import nowtime |
Rushabh Mehta | 91ba346 | 2012-07-13 14:54:40 +0530 | [diff] [blame] | 27 | from webnotes.profile import get_user_fullname |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 28 | home.make_feed('Login', 'Profile', login_manager.user, login_manager.user, |
Anand Doshi | aea8204 | 2012-10-15 15:30:56 +0530 | [diff] [blame] | 29 | '%s logged in at %s' % (get_user_fullname(login_manager.user), nowtime()), |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 30 | login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') |
| 31 | |
Rushabh Mehta | 533bc77 | 2012-02-15 09:35:42 +0100 | [diff] [blame] | 32 | |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 33 | def comment_added(doc): |
| 34 | """add comment to feed""" |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 35 | home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, |
| 36 | '<i>"' + doc.comment + '"</i>', '#6B24B3') |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 37 | |
| 38 | def boot_session(bootinfo): |
| 39 | """boot session - send website info if guest""" |
| 40 | import webnotes |
| 41 | import webnotes.model.doc |
| 42 | |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 43 | bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or '' |
Rushabh Mehta | 30e3f15 | 2012-05-01 14:07:41 +0530 | [diff] [blame] | 44 | bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings') |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 45 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 46 | if webnotes.session['user']=='Guest': |
Rushabh Mehta | f35992f | 2012-02-07 10:39:17 +0530 | [diff] [blame] | 47 | bootinfo['website_menus'] = webnotes.conn.sql("""select label, url, custom_page, |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 48 | parent_label, parentfield |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 49 | from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1) |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 50 | bootinfo['startup_code'] = \ |
Rushabh Mehta | a4be4d3 | 2012-04-30 14:22:02 +0530 | [diff] [blame] | 51 | webnotes.conn.get_value('Website Settings', None, 'startup_code') |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 52 | else: |
| 53 | bootinfo['letter_heads'] = get_letter_heads() |
| 54 | |
Rushabh Mehta | aa999df | 2012-02-27 12:54:04 +0530 | [diff] [blame] | 55 | import webnotes.model.doctype |
| 56 | bootinfo['docs'] += webnotes.model.doctype.get('Event') |
Anand Doshi | 92da889 | 2012-03-15 11:50:26 +0530 | [diff] [blame] | 57 | bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria') |
Rushabh Mehta | 35c017a | 2012-11-30 10:57:28 +0530 | [diff] [blame] | 58 | bootinfo['notification_settings'] = webnotes.doc("Notification Control", |
| 59 | "Notification Control").get_values() |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 60 | |
| 61 | bootinfo['modules_list'] = webnotes.conn.get_global('modules_list') |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 62 | |
| 63 | # if no company, show a dialog box to create a new company |
| 64 | bootinfo['setup_complete'] = webnotes.conn.sql("""select name from |
| 65 | tabCompany limit 1""") and 'Yes' or 'No' |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 66 | |
| 67 | # load subscription info |
| 68 | import conf |
Rushabh Mehta | 4156523 | 2012-09-17 19:10:36 +0530 | [diff] [blame] | 69 | for key in ['max_users', 'expires_on', 'max_space', 'status', 'developer_mode']: |
Anand Doshi | 08c0869 | 2012-06-08 16:07:01 +0530 | [diff] [blame] | 70 | if hasattr(conf, key): bootinfo[key] = getattr(conf, key) |
Rushabh Mehta | aa999df | 2012-02-27 12:54:04 +0530 | [diff] [blame] | 71 | |
Anand Doshi | df74d30 | 2012-05-10 19:19:31 +0530 | [diff] [blame] | 72 | company = webnotes.conn.sql("select name, default_currency from `tabCompany`", as_dict=1) |
| 73 | company_dict = {} |
| 74 | for c in company: |
| 75 | company_dict.setdefault(c['name'], {}).update(c) |
| 76 | |
| 77 | bootinfo['company'] = company_dict |
Rushabh Mehta | 4156523 | 2012-09-17 19:10:36 +0530 | [diff] [blame] | 78 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 79 | def get_letter_heads(): |
| 80 | """load letter heads with startup""" |
| 81 | import webnotes |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 82 | ret = webnotes.conn.sql("""select name, content from `tabLetter Head` |
| 83 | where ifnull(disabled,0)=0""") |
Rushabh Mehta | 4b1fe05 | 2012-01-25 15:06:28 +0530 | [diff] [blame] | 84 | return dict(ret) |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 85 | |
Anand Doshi | 737c2f9 | 2012-02-14 16:16:13 +0530 | [diff] [blame] | 86 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 87 | def check_if_expired(): |
| 88 | """check if account is expired. If expired, do not allow login""" |
| 89 | import conf |
| 90 | # check if expires_on is specified |
| 91 | if not hasattr(conf, 'expires_on'): return |
| 92 | |
| 93 | # check if expired |
| 94 | from datetime import datetime, date |
| 95 | expires_on = datetime.strptime(conf.expires_on, '%Y-%m-%d').date() |
| 96 | if date.today() <= expires_on: return |
| 97 | |
| 98 | # if expired, stop user from logging in |
| 99 | from webnotes.utils import formatdate |
Anand Doshi | dcb6c2c | 2012-09-28 16:09:49 +0530 | [diff] [blame] | 100 | msg = """Oops! Your subscription expired on <b>%s</b>.<br>""" % formatdate(conf.expires_on) |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 101 | |
Rushabh Mehta | d1b2afc | 2012-12-12 15:58:46 +0530 | [diff] [blame] | 102 | if 'System Manager' in webnotes.user.get_roles(): |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 103 | msg += """Just drop in a mail at <b>support@erpnext.com</b> and |
| 104 | we will guide you to get your account re-activated.""" |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 105 | else: |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 106 | msg += """Just ask your System Manager to drop in a mail at <b>support@erpnext.com</b> and |
| 107 | we will guide him to get your account re-activated.""" |
| 108 | |
| 109 | webnotes.msgprint(msg) |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 110 | |
| 111 | webnotes.response['message'] = 'Account Expired' |
Rushabh Mehta | 30cb5c2 | 2012-04-27 18:39:56 +0530 | [diff] [blame] | 112 | raise webnotes.AuthenticationError |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 113 | |
| 114 | #### website |
| 115 | |
| 116 | def get_web_script(): |
| 117 | """returns web startup script""" |
Rushabh Mehta | 5f1d57e | 2012-12-27 14:05:02 +0530 | [diff] [blame] | 118 | return webnotes.conn.get_value('Website Script', None, 'javascript') or '' |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 119 | |
| 120 | def get_web_style(): |
| 121 | """returns web css""" |
| 122 | return webnotes.conn.get_value('Style Settings', None, 'custom_css') or '' |
| 123 | |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 124 | def get_web_header(page_name): |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 125 | """get website header""" |
| 126 | from website.utils import get_header |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 127 | return get_header(page_name) |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 128 | |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 129 | def get_web_footer(page_name): |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 130 | """get website footer""" |
| 131 | from website.utils import get_footer |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 132 | return get_footer(page_name) |