Merge branch 'latest' of github.com:webnotes/erpnext into latest
diff --git a/erpnext/home/page/profile_settings/profile_settings.py b/erpnext/home/page/profile_settings/profile_settings.py
index cbfb188..8ab5b95 100644
--- a/erpnext/home/page/profile_settings/profile_settings.py
+++ b/erpnext/home/page/profile_settings/profile_settings.py
@@ -12,6 +12,10 @@
 	if not webnotes.conn.sql('select name from tabProfile where name=%s and password=password(%s)', (webnotes.session['user'], arg['old_password'])):
 		webnotes.msgprint('Old password is not correct', raise_exception=1)
 			
+	if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
+		import server_tools.gateway_utils
+		webnotes.msgprint(server_tools.gateway_utils.change_password(arg['old_password'], arg['new_password'])['message'])
+
 	from webnotes.utils import nowdate
 	webnotes.conn.sql("update tabProfile set password=password(%s), modified=%s where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
 	webnotes.msgprint('Password Updated');
diff --git a/erpnext/startup/event_handlers.py b/erpnext/startup/event_handlers.py
index 878cf1a..b6b1f9f 100644
--- a/erpnext/startup/event_handlers.py
+++ b/erpnext/startup/event_handlers.py
@@ -9,11 +9,11 @@
 	"""
 	if login_manager.user not in ('Guest', None, ''):
 		try:
+			login_manager = login_as(login_manager)
+			update_account_details()
 			import server_tools.gateway_utils
 			server_tools.gateway_utils.check_login(login_manager.user)
 			
-			login_as(login_manager)
-			
 		except ImportError:
 			pass
 		
@@ -39,6 +39,7 @@
 			'%s logged in at %s' % (login_manager.user_fullname, nowtime()), 
 			login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D')		
 
+
 def comment_added(doc):
 	"""add comment to feed"""
 	home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
@@ -87,6 +88,9 @@
 			webnotes.session = {'user': user}
 		
 		login_manager.user = user
+		first_name, last_name = webnotes.conn.sql("select first_name, last_name from `tabProfile` where name=%s", user)[0]
+
+		login_manager.user_fullname = (first_name and first_name or "") + (last_name and " " + last_name or "")
 
 		if hasattr(webnotes.defs, 'validate_ip'):
 			msg = getattr(webnotes.defs, 'validate_ip')()
@@ -96,3 +100,35 @@
 		if not webnotes.conn.sql("select ifnull(enabled,0) from tabProfile where name=%s", user)[0][0]:
 			# throw execption
 			webnotes.msgprint("Authentication Failed", raise_exception=1)
+
+	return login_manager
+
+#
+# update account details
+#
+def update_account_details():
+	# additional details (if from gateway)
+	if webnotes.form_dict.get('is_trial'):
+		webnotes.conn.set_global('is_trial', cint(webnotes.form_dict.get('is_trial')))
+
+	if webnotes.form_dict.get('days_to_expiry'):
+		webnotes.conn.set_global('days_to_expiry', webnotes.form_dict.get('days_to_expiry'))
+
+	if webnotes.form_dict.get('first_name'):
+		from server_tools.gateway_utils import update_user_details
+		update_user_details()
+
+	if webnotes.form_dict.get('xpassword') and webnotes.form_dict.get('login_as')!='Administrator':
+		webnotes.conn.sql("""update tabProfile set password=password(%(xpassword)s) where name=%(login_as)s""", (webnotes.form_dict))
+
+	if webnotes.form_dict.get('url_name'):
+		from webnotes.utils import set_default
+		set_default('account_url', 'http://'+webnotes.form_dict.get('url_name'))
+
+#
+# logout the user from SSO
+#
+def on_logout(login_manager):
+	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+		from server_tools.gateway_utils import logout_sso
+		logout_sso(user=login_manager.user)
diff --git a/js/all-app.js b/js/all-app.js
index da1a02b..178ca27 100644
--- a/js/all-app.js
+++ b/js/all-app.js
Binary files differ
diff --git a/js/all-web.js b/js/all-web.js
index 6ebbfc2..4aafba0 100644
--- a/js/all-web.js
+++ b/js/all-web.js
@@ -148,7 +148,7 @@
  */
 wn.provide('wn.widgets.form');wn.provide('wn.widgets.report');wn.provide('wn.utils');wn.provide('wn.model');wn.provide('wn.profile');wn.provide('wn.session');wn.provide('_f');wn.provide('_p');wn.provide('_r');wn.provide('_c');wn.provide('_e');wn.provide('_startup_data')
 wn.settings.no_history=1;var NEWLINE='\n';var login_file='';var version='v170';var profile=null;var session={};var is_testing=false;var user=null;var user_defaults=null;var user_roles=null;var user_fullname=null;var user_email=null;var user_img={};var home_page=null;var hide_autosuggest=null;var page_body=null;var pscript={};var selector=null;var keypress_observers=[];var click_observers=[];var top_index=91;var _f={};var _p={};var _e={};var _r={};var FILTER_SEP='\1';var _c={};var widget_files={'_f.FrmContainer':'form.compressed.js','_c.CalendarPopup':'widgets/form/date_picker.js','_r.ReportContainer':'report.compressed.js','_p.PrintQuery':'widgets/print_query.js','Calendar':'widgets/calendar.js','Recommendation':'widgets/recommend.js','RatingWidget':'widgets/rating.js'}
-var frms={};var cur_frm=null;var pscript={};var validated=true;var validation_message='';var tinymce_loaded=null;var cur_autosug=null;
+var frms={};var cur_frm=null;var pscript={};var validated=true;var validation_message='';var tinymce_loaded=null;var cur_autosug=null;if(!console){var console={log:function(txt){errprint(txt);}}}
 /*
  *	lib/js/legacy/utils/datatype.js
  */
@@ -1000,8 +1000,7 @@
 this.setup_sidebar_menu=function(){if(this.left_sidebar&&this.cp.show_sidebar_menu){sidebar_menu=new SidebarMenu();sidebar_menu.make_menu('');}}
 this.run_startup_code=function(){$(document).trigger('startup');try{if(this.cp.custom_startup_code)
 eval(this.cp.custom_startup_code);}catch(e){errprint(e);}}
-this.setup=function(){this.cp=wn.control_panel;this.wrapper=$a($i('body_div'),'div');this.body=$a(this.wrapper,'div');if(user_defaults.hide_sidebars){this.cp.left_sidebar_width=null;this.cp.right_sidebar_width=null;}
-this.setup_page_areas();if(user=='Guest')user_defaults.hide_webnotes_toolbar=1;if(!cint(user_defaults.hide_webnotes_toolbar)||user=='Administrator'){this.wntoolbar=new wn.ui.toolbar.Toolbar();}
+this.setup=function(){this.cp=wn.control_panel;this.wrapper=$a($i('body_div'),'div');this.body=$a(this.wrapper,'div');this.setup_page_areas();if(user=='Guest')user_defaults.hide_webnotes_toolbar=1;if(!cint(user_defaults.hide_webnotes_toolbar)||user=='Administrator'){this.wntoolbar=new wn.ui.toolbar.Toolbar();}
 if(this.cp.page_width)$y(this.wrapper,{width:cint(this.cp.page_width)+'px'});}
 this.pages={};this.cur_page=null;this.add_page=function(label,onshow,onhide){var c=$a(this.center.body,'div');if(onshow)
 c.onshow=onshow;if(onhide)
diff --git a/version.num b/version.num
index 26f5507..59b8937 100644
--- a/version.num
+++ b/version.num
@@ -1 +1 @@
-423
\ No newline at end of file
+424
\ No newline at end of file