Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt" |
Rushabh Mehta | ce1d527 | 2013-01-09 16:39:27 +0530 | [diff] [blame] | 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 | def on_login_post_session(login_manager): |
Rushabh Mehta | bedc1fe | 2012-01-17 18:17:06 +0530 | [diff] [blame] | 10 | """ |
| 11 | called after login |
| 12 | update login_from and delete parallel sessions |
| 13 | """ |
Anand Doshi | b63a007 | 2012-01-03 16:11:04 +0530 | [diff] [blame] | 14 | # Clear previous sessions i.e. logout previous log-in attempts |
Rushabh Mehta | 686022f | 2012-12-12 15:25:51 +0530 | [diff] [blame] | 15 | allow_multiple_sessions = ['demo@erpnext.com', 'Administrator', 'Guest'] |
| 16 | if webnotes.session['user'] not in allow_multiple_sessions: |
| 17 | from webnotes.sessions import clear_sessions |
| 18 | clear_sessions(webnotes.session.user, keep_current=True) |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 19 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 20 | # check if account is expired |
| 21 | check_if_expired() |
| 22 | |
Nabin Hait | 8bbc5a2 | 2012-11-05 18:58:15 +0530 | [diff] [blame] | 23 | if webnotes.session['user'] not in ('Guest', 'demo@erpnext.com'): |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 24 | # create feed |
| 25 | from webnotes.utils import nowtime |
Rushabh Mehta | 91ba346 | 2012-07-13 14:54:40 +0530 | [diff] [blame] | 26 | from webnotes.profile import get_user_fullname |
Rushabh Mehta | 028abd2 | 2013-01-31 11:20:10 +0530 | [diff] [blame] | 27 | webnotes.conn.begin() |
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 | 028abd2 | 2013-01-31 11:20:10 +0530 | [diff] [blame] | 30 | login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') |
| 31 | webnotes.conn.commit() |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 32 | |
Anand Doshi | 2b1d33f | 2013-07-25 17:17:47 +0530 | [diff] [blame] | 33 | if webnotes.conn.get_value("Profile", webnotes.session.user, "user_type") == "Website User": |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 34 | from website.helpers.cart import set_cart_count |
| 35 | set_cart_count() |
| 36 | |
| 37 | def on_logout(login_manager): |
| 38 | webnotes.add_cookies["cart_count"] = "" |
| 39 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 40 | def check_if_expired(): |
| 41 | """check if account is expired. If expired, do not allow login""" |
| 42 | import conf |
| 43 | # check if expires_on is specified |
| 44 | if not hasattr(conf, 'expires_on'): return |
| 45 | |
| 46 | # check if expired |
| 47 | from datetime import datetime, date |
| 48 | expires_on = datetime.strptime(conf.expires_on, '%Y-%m-%d').date() |
| 49 | if date.today() <= expires_on: return |
| 50 | |
| 51 | # if expired, stop user from logging in |
| 52 | from webnotes.utils import formatdate |
Anand Doshi | dcb6c2c | 2012-09-28 16:09:49 +0530 | [diff] [blame] | 53 | 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] | 54 | |
Rushabh Mehta | d1b2afc | 2012-12-12 15:58:46 +0530 | [diff] [blame] | 55 | if 'System Manager' in webnotes.user.get_roles(): |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 56 | msg += """Just drop in a mail at <b>support@erpnext.com</b> and |
| 57 | we will guide you to get your account re-activated.""" |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 58 | else: |
Anand Doshi | 62091db | 2012-09-28 16:06:06 +0530 | [diff] [blame] | 59 | msg += """Just ask your System Manager to drop in a mail at <b>support@erpnext.com</b> and |
| 60 | we will guide him to get your account re-activated.""" |
| 61 | |
| 62 | webnotes.msgprint(msg) |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 63 | |
| 64 | webnotes.response['message'] = 'Account Expired' |
Rushabh Mehta | 30cb5c2 | 2012-04-27 18:39:56 +0530 | [diff] [blame] | 65 | raise webnotes.AuthenticationError |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 66 | |
| 67 | |
| 68 | def comment_added(doc): |
| 69 | """add comment to feed""" |
| 70 | home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, |
| 71 | '<i>"' + doc.comment + '"</i>', '#6B24B3') |
| 72 | |