Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | # ERPNext - web based ERP (http://erpnext.com) |
| 2 | # Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 17 | import webnotes |
| 18 | from webnotes.utils import cint |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 19 | import home |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 20 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 21 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 22 | def on_login_post_session(login_manager): |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 23 | """ |
| 24 | called after login |
| 25 | update login_from and delete parallel sessions |
| 26 | """ |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 27 | # Clear previous sessions i.e. logout previous log-in attempts |
Rushabh Mehta | d31bf62 | 2012-01-19 15:09:49 +0530 | [diff] [blame] | 28 | exception_list = ['demo@webnotestech.com', 'Administrator', 'Guest'] |
Anand Doshi | 9fdee38 | 2012-01-03 11:26:00 +0530 | [diff] [blame] | 29 | if webnotes.session['user'] not in exception_list: |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 30 | sid_list = webnotes.conn.sql(""" |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 31 | DELETE FROM `tabSessions` |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 32 | WHERE |
| 33 | user=%s AND |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 34 | sid!=%s""", \ |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 35 | (webnotes.session['user'], webnotes.session['sid']), as_list=1) |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 36 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 37 | # check if account is expired |
| 38 | check_if_expired() |
| 39 | |
| 40 | if webnotes.session['user'] not in ('Guest', 'demo@webnotestech.com'): |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 41 | # create feed |
| 42 | from webnotes.utils import nowtime |
| 43 | home.make_feed('Login', 'Profile', login_manager.user, login_manager.user, |
| 44 | '%s logged in at %s' % (login_manager.user_fullname, nowtime()), |
| 45 | login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') |
| 46 | |
Rushabh Mehta | 533bc77 | 2012-02-15 09:35:42 +0100 | [diff] [blame] | 47 | |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 48 | def comment_added(doc): |
| 49 | """add comment to feed""" |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 50 | home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, |
| 51 | '<i>"' + doc.comment + '"</i>', '#6B24B3') |
| 52 | |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 53 | def doclist_all(doc, method): |
| 54 | """doclist trigger called from webnotes.model.doclist on any event""" |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 55 | home.update_feed(doc, method) |
| 56 | |
| 57 | def boot_session(bootinfo): |
| 58 | """boot session - send website info if guest""" |
| 59 | import webnotes |
| 60 | import webnotes.model.doc |
| 61 | |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 62 | 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] | 63 | bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings') |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 64 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 65 | if webnotes.session['user']=='Guest': |
Rushabh Mehta | f35992f | 2012-02-07 10:39:17 +0530 | [diff] [blame] | 66 | bootinfo['website_menus'] = webnotes.conn.sql("""select label, url, custom_page, |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 67 | parent_label, parentfield |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 68 | 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] | 69 | bootinfo['startup_code'] = \ |
Rushabh Mehta | a4be4d3 | 2012-04-30 14:22:02 +0530 | [diff] [blame] | 70 | webnotes.conn.get_value('Website Settings', None, 'startup_code') |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 71 | else: |
| 72 | bootinfo['letter_heads'] = get_letter_heads() |
| 73 | |
Rushabh Mehta | aa999df | 2012-02-27 12:54:04 +0530 | [diff] [blame] | 74 | import webnotes.model.doctype |
| 75 | bootinfo['docs'] += webnotes.model.doctype.get('Event') |
Anand Doshi | 92da889 | 2012-03-15 11:50:26 +0530 | [diff] [blame] | 76 | bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria') |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 77 | |
| 78 | bootinfo['modules_list'] = webnotes.conn.get_global('modules_list') |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 79 | |
| 80 | # if no company, show a dialog box to create a new company |
| 81 | bootinfo['setup_complete'] = webnotes.conn.sql("""select name from |
| 82 | tabCompany limit 1""") and 'Yes' or 'No' |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 83 | |
| 84 | bootinfo['user_background'] = webnotes.conn.get_value("Profile", webnotes.session['user'], 'background_image') or '' |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 85 | |
| 86 | # load subscription info |
| 87 | import conf |
Anand Doshi | 08c0869 | 2012-06-08 16:07:01 +0530 | [diff] [blame] | 88 | for key in ['max_users', 'expires_on', 'max_space', 'status']: |
| 89 | if hasattr(conf, key): bootinfo[key] = getattr(conf, key) |
Rushabh Mehta | aa999df | 2012-02-27 12:54:04 +0530 | [diff] [blame] | 90 | |
Anand Doshi | df74d30 | 2012-05-10 19:19:31 +0530 | [diff] [blame] | 91 | company = webnotes.conn.sql("select name, default_currency from `tabCompany`", as_dict=1) |
| 92 | company_dict = {} |
| 93 | for c in company: |
| 94 | company_dict.setdefault(c['name'], {}).update(c) |
| 95 | |
| 96 | bootinfo['company'] = company_dict |
| 97 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 98 | def get_letter_heads(): |
| 99 | """load letter heads with startup""" |
| 100 | import webnotes |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 101 | ret = webnotes.conn.sql("""select name, content from `tabLetter Head` |
| 102 | where ifnull(disabled,0)=0""") |
Rushabh Mehta | 4b1fe05 | 2012-01-25 15:06:28 +0530 | [diff] [blame] | 103 | return dict(ret) |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 104 | |
Anand Doshi | 737c2f9 | 2012-02-14 16:16:13 +0530 | [diff] [blame] | 105 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 106 | def check_if_expired(): |
| 107 | """check if account is expired. If expired, do not allow login""" |
| 108 | import conf |
| 109 | # check if expires_on is specified |
| 110 | if not hasattr(conf, 'expires_on'): return |
| 111 | |
| 112 | # check if expired |
| 113 | from datetime import datetime, date |
| 114 | expires_on = datetime.strptime(conf.expires_on, '%Y-%m-%d').date() |
| 115 | if date.today() <= expires_on: return |
| 116 | |
| 117 | # if expired, stop user from logging in |
| 118 | from webnotes.utils import formatdate |
| 119 | if 'System Manager' in webnotes.user.roles: |
| 120 | webnotes.response['server_messages'] = """Oops! \ |
| 121 | Your subscription expired on <b>%s</b>. |
| 122 | |
| 123 | Nothing catastrophic. |
| 124 | |
| 125 | Just drop in a mail at <b>support@erpnext.com</b> and \ |
| 126 | we will guide you to get your account re-activated.""" % formatdate(conf.expires_on) |
| 127 | else: |
| 128 | webnotes.response['server_messages'] = """Oops! \ |
| 129 | Your subscription expired on <b>%s</b>. |
| 130 | |
| 131 | Nothing catastrophic. |
| 132 | |
| 133 | Just ask your System Manager to drop in a mail at <b>support@erpnext.com</b> and \ |
| 134 | we will guide him to get your account re-activated.""" % formatdate(conf.expires_on) |
| 135 | |
| 136 | webnotes.response['message'] = 'Account Expired' |
Rushabh Mehta | 30cb5c2 | 2012-04-27 18:39:56 +0530 | [diff] [blame] | 137 | raise webnotes.AuthenticationError |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 138 | |
| 139 | #### website |
| 140 | |
| 141 | def get_web_script(): |
| 142 | """returns web startup script""" |
| 143 | return webnotes.conn.get_value('Website Settings', None, 'startup_code') or '' |
| 144 | |
| 145 | def get_web_style(): |
| 146 | """returns web css""" |
| 147 | return webnotes.conn.get_value('Style Settings', None, 'custom_css') or '' |
| 148 | |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 149 | def get_web_header(page_name): |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 150 | """get website header""" |
| 151 | from website.utils import get_header |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 152 | return get_header(page_name) |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 153 | |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 154 | def get_web_footer(page_name): |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 155 | """get website footer""" |
| 156 | from website.utils import get_footer |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 157 | return get_footer(page_name) |