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 | 028abd2 | 2013-01-31 11:20:10 +0530 | [diff] [blame] | 28 | webnotes.conn.begin() |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 29 | home.make_feed('Login', 'Profile', login_manager.user, login_manager.user, |
Anand Doshi | aea8204 | 2012-10-15 15:30:56 +0530 | [diff] [blame] | 30 | '%s logged in at %s' % (get_user_fullname(login_manager.user), nowtime()), |
Rushabh Mehta | 028abd2 | 2013-01-31 11:20:10 +0530 | [diff] [blame] | 31 | login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') |
| 32 | webnotes.conn.commit() |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 33 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 34 | def check_if_expired(): |
| 35 | """check if account is expired. If expired, do not allow login""" |
| 36 | import conf |
| 37 | # check if expires_on is specified |
| 38 | if not hasattr(conf, 'expires_on'): return |
| 39 | |
| 40 | # check if expired |
| 41 | from datetime import datetime, date |
| 42 | expires_on = datetime.strptime(conf.expires_on, '%Y-%m-%d').date() |
| 43 | if date.today() <= expires_on: return |
| 44 | |
| 45 | # if expired, stop user from logging in |
| 46 | from webnotes.utils import formatdate |
Anand Doshi | dcb6c2c | 2012-09-28 16:09:49 +0530 | [diff] [blame] | 47 | 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] | 48 | |
Rushabh Mehta | d1b2afc | 2012-12-12 15:58:46 +0530 | [diff] [blame] | 49 | if 'System Manager' in webnotes.user.get_roles(): |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 50 | msg += """Just drop in a mail at <b>support@erpnext.com</b> and |
| 51 | we will guide you to get your account re-activated.""" |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 52 | else: |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 53 | msg += """Just ask your System Manager to drop in a mail at <b>support@erpnext.com</b> and |
| 54 | we will guide him to get your account re-activated.""" |
| 55 | |
| 56 | webnotes.msgprint(msg) |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 57 | |
| 58 | webnotes.response['message'] = 'Account Expired' |
Rushabh Mehta | 30cb5c2 | 2012-04-27 18:39:56 +0530 | [diff] [blame] | 59 | raise webnotes.AuthenticationError |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 60 | |
| 61 | |
| 62 | def comment_added(doc): |
| 63 | """add comment to feed""" |
| 64 | home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, |
| 65 | '<i>"' + doc.comment + '"</i>', '#6B24B3') |
| 66 | |