blob: 2a74eeb58d4934338c1a37141965eabb7bfef7ba [file] [log] [blame]
Rushabh Mehtace1d5272013-01-09 16:39:27 +05301# ERPNext: Copyright 2013 Web Notes Technologies Pvt Ltd
2# GNU General Public License. See "license.txt"
3
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05304
Anand Doshi486f9df2012-07-19 13:40:31 +05305from __future__ import unicode_literals
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05306import webnotes
Rushabh Mehta63d669f2012-02-03 12:56:12 +05307import home
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05308
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05309
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053010def on_login_post_session(login_manager):
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053011 """
12 called after login
13 update login_from and delete parallel sessions
14 """
Anand Doshib63a0072012-01-03 16:11:04 +053015 # Clear previous sessions i.e. logout previous log-in attempts
Rushabh Mehta686022f2012-12-12 15:25:51 +053016 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 Mehta49ebfb62012-01-20 15:32:18 +053020
Anand Doshi1ed4ef12012-04-27 15:30:23 +053021 # check if account is expired
22 check_if_expired()
23
Nabin Hait8bbc5a22012-11-05 18:58:15 +053024 if webnotes.session['user'] not in ('Guest', 'demo@erpnext.com'):
Rushabh Mehta63d669f2012-02-03 12:56:12 +053025 # create feed
26 from webnotes.utils import nowtime
Rushabh Mehta91ba3462012-07-13 14:54:40 +053027 from webnotes.profile import get_user_fullname
Rushabh Mehta028abd22013-01-31 11:20:10 +053028 webnotes.conn.begin()
Rushabh Mehta63d669f2012-02-03 12:56:12 +053029 home.make_feed('Login', 'Profile', login_manager.user, login_manager.user,
Anand Doshiaea82042012-10-15 15:30:56 +053030 '%s logged in at %s' % (get_user_fullname(login_manager.user), nowtime()),
Rushabh Mehta028abd22013-01-31 11:20:10 +053031 login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D')
32 webnotes.conn.commit()
Rushabh Mehta63d669f2012-02-03 12:56:12 +053033
Rushabh Mehta533bc772012-02-15 09:35:42 +010034
Rushabh Mehta63d669f2012-02-03 12:56:12 +053035def comment_added(doc):
36 """add comment to feed"""
Rushabh Mehta63d669f2012-02-03 12:56:12 +053037 home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
38 '<i>"' + doc.comment + '"</i>', '#6B24B3')
Rushabh Mehta865c00a2012-01-24 14:33:21 +053039
40def boot_session(bootinfo):
41 """boot session - send website info if guest"""
42 import webnotes
43 import webnotes.model.doc
44
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053045 bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or ''
Rushabh Mehta30e3f152012-05-01 14:07:41 +053046 bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings')
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053047
Rushabh Mehta865c00a2012-01-24 14:33:21 +053048 if webnotes.session['user']=='Guest':
Rushabh Mehtaf35992f2012-02-07 10:39:17 +053049 bootinfo['website_menus'] = webnotes.conn.sql("""select label, url, custom_page,
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053050 parent_label, parentfield
Rushabh Mehta7018b192012-02-02 13:42:28 +053051 from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1)
Rushabh Mehta389880d2012-04-27 18:39:14 +053052 bootinfo['startup_code'] = \
Rushabh Mehtaa4be4d32012-04-30 14:22:02 +053053 webnotes.conn.get_value('Website Settings', None, 'startup_code')
Rushabh Mehta865c00a2012-01-24 14:33:21 +053054 else:
55 bootinfo['letter_heads'] = get_letter_heads()
56
Rushabh Mehtaaa999df2012-02-27 12:54:04 +053057 import webnotes.model.doctype
58 bootinfo['docs'] += webnotes.model.doctype.get('Event')
Anand Doshi92da8892012-03-15 11:50:26 +053059 bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria')
Rushabh Mehta35c017a2012-11-30 10:57:28 +053060 bootinfo['notification_settings'] = webnotes.doc("Notification Control",
61 "Notification Control").get_values()
Rushabh Mehta17da7642012-02-28 18:56:56 +053062
63 bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')
Rushabh Mehta12852e72012-02-29 15:11:06 +053064
65 # if no company, show a dialog box to create a new company
66 bootinfo['setup_complete'] = webnotes.conn.sql("""select name from
67 tabCompany limit 1""") and 'Yes' or 'No'
Anand Doshi1ed4ef12012-04-27 15:30:23 +053068
69 # load subscription info
70 import conf
Rushabh Mehta41565232012-09-17 19:10:36 +053071 for key in ['max_users', 'expires_on', 'max_space', 'status', 'developer_mode']:
Anand Doshi08c08692012-06-08 16:07:01 +053072 if hasattr(conf, key): bootinfo[key] = getattr(conf, key)
Rushabh Mehtaaa999df2012-02-27 12:54:04 +053073
Rushabh Mehta08da1a02013-01-29 17:53:29 +053074 bootinfo['docs'] += webnotes.conn.sql("select name, default_currency from `tabCompany`",
75 as_dict=1, update={"doctype":":Company"})
76
Rushabh Mehta865c00a2012-01-24 14:33:21 +053077def get_letter_heads():
78 """load letter heads with startup"""
79 import webnotes
Rushabh Mehta63d669f2012-02-03 12:56:12 +053080 ret = webnotes.conn.sql("""select name, content from `tabLetter Head`
81 where ifnull(disabled,0)=0""")
Rushabh Mehta4b1fe052012-01-25 15:06:28 +053082 return dict(ret)
Anand Doshi1ed4ef12012-04-27 15:30:23 +053083
Anand Doshi737c2f92012-02-14 16:16:13 +053084
Anand Doshi1ed4ef12012-04-27 15:30:23 +053085def check_if_expired():
86 """check if account is expired. If expired, do not allow login"""
87 import conf
88 # check if expires_on is specified
89 if not hasattr(conf, 'expires_on'): return
90
91 # check if expired
92 from datetime import datetime, date
93 expires_on = datetime.strptime(conf.expires_on, '%Y-%m-%d').date()
94 if date.today() <= expires_on: return
95
96 # if expired, stop user from logging in
97 from webnotes.utils import formatdate
Anand Doshidcb6c2c2012-09-28 16:09:49 +053098 msg = """Oops! Your subscription expired on <b>%s</b>.<br>""" % formatdate(conf.expires_on)
Anand Doshi62091db2012-09-28 16:06:06 +053099
Rushabh Mehtad1b2afc2012-12-12 15:58:46 +0530100 if 'System Manager' in webnotes.user.get_roles():
Anand Doshi62091db2012-09-28 16:06:06 +0530101 msg += """Just drop in a mail at <b>support@erpnext.com</b> and
102 we will guide you to get your account re-activated."""
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530103 else:
Anand Doshi62091db2012-09-28 16:06:06 +0530104 msg += """Just ask your System Manager to drop in a mail at <b>support@erpnext.com</b> and
105 we will guide him to get your account re-activated."""
106
107 webnotes.msgprint(msg)
Anand Doshi1ed4ef12012-04-27 15:30:23 +0530108
109 webnotes.response['message'] = 'Account Expired'
Rushabh Mehta30cb5c22012-04-27 18:39:56 +0530110 raise webnotes.AuthenticationError
Rushabh Mehtaa9209432012-05-07 18:00:57 +0530111
112#### website
113
114def get_web_script():
115 """returns web startup script"""
Rushabh Mehta5f1d57e2012-12-27 14:05:02 +0530116 return webnotes.conn.get_value('Website Script', None, 'javascript') or ''
Rushabh Mehtaa9209432012-05-07 18:00:57 +0530117
118def get_web_style():
119 """returns web css"""
120 return webnotes.conn.get_value('Style Settings', None, 'custom_css') or ''
121
Rushabh Mehta458ca8e2012-05-09 10:17:08 +0530122def get_web_header(page_name):
Rushabh Mehtaa9209432012-05-07 18:00:57 +0530123 """get website header"""
124 from website.utils import get_header
Rushabh Mehta458ca8e2012-05-09 10:17:08 +0530125 return get_header(page_name)
Rushabh Mehtaa9209432012-05-07 18:00:57 +0530126
Rushabh Mehta458ca8e2012-05-09 10:17:08 +0530127def get_web_footer(page_name):
Rushabh Mehtaa9209432012-05-07 18:00:57 +0530128 """get website footer"""
129 from website.utils import get_footer
Rushabh Mehta458ca8e2012-05-09 10:17:08 +0530130 return get_footer(page_name)