fixes to add user
diff --git a/erpnext/home/page/my_company/my_company.py b/erpnext/home/page/my_company/my_company.py
index c239162..09bb9ee 100644
--- a/erpnext/home/page/my_company/my_company.py
+++ b/erpnext/home/page/my_company/my_company.py
@@ -1,6 +1,7 @@
import webnotes
from webnotes.utils import cint, load_json, cstr
+from webnotes.model.doc import Document
try: import json
except: import simplejson as json
@@ -65,8 +66,7 @@
# add profile record
#
def add_profile(args):
- from webnotes.utils import validate_email_add
- from webnotes.model.doc import Document
+ from webnotes.utils import validate_email_add, now
email = args['user']
sql = webnotes.conn.sql
@@ -80,7 +80,7 @@
if sql("select name from tabProfile where name = %s", email):
# exists, enable it
sql("update tabProfile set enabled = 1, docstatus=0 where name = %s", email)
- webnotes.msgprint('Profile exists, enabled it')
+ webnotes.msgprint('Profile exists, enabled it with new password')
else:
# does not exist, create it!
pr = Document('Profile')
@@ -92,11 +92,25 @@
pr.user_type = 'System User'
pr.save(1)
- if args.get('password'):
- sql("""
- UPDATE tabProfile
- SET password = PASSWORD(%s)
- WHERE name = %s""", (args.get('password'), email))
+ if args.get('password'):
+ sql("""
+ UPDATE tabProfile
+ SET password = PASSWORD(%s), modified = %s
+ WHERE name = %s""", (args.get('password'), now, email))
+
+ send_welcome_mail(email, args.get('password'))
+
+def send_welcome_mail(email, password):
+ """send welcome mail to user with password and login url"""
+ pr = Document('Profile', email)
+ from webnotes.utils.email_lib import sendmail_md
+ args = {
+ 'company': webnotes.conn.get_default('company'),
+ 'name': email,
+ 'password': password,
+ 'account_url': webnotes.conn.get_default('account_url')
+ }
+ sendmail_md(pr.email, subject="Welcome to ERPNext", msg=welcome_txt % args)
#
# post comment
@@ -166,3 +180,18 @@
else:
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
else: webnotes.msgprint('Settings Updated')
+
+welcome_txt = """
+## %(company)s
+
+#### Welcome!
+
+A new account has been created for you, here are your details:
+
+login-id: %(name)s
+password: %(password)s
+
+To login to your new ERPNext account, please go to:
+
+%(account_url)s
+"""
\ No newline at end of file
diff --git a/erpnext/patches/jan_mar_2012/subdomain_login_patch.py b/erpnext/patches/jan_mar_2012/subdomain_login_patch.py
index 9c72b0e..b0633cc 100644
--- a/erpnext/patches/jan_mar_2012/subdomain_login_patch.py
+++ b/erpnext/patches/jan_mar_2012/subdomain_login_patch.py
@@ -4,7 +4,7 @@
def execute():
add_default_home_page()
cleanup()
-
+
def cleanup():
from webnotes.model import delete_doc
delete_doc("DocType", "SSO Control")
@@ -19,4 +19,4 @@
d.parentfield = 'default_home_pages'
d.role = 'Guest'
d.home_page = 'Login Page'
- d.save(1)
\ No newline at end of file
+ d.save(1)
diff --git a/erpnext/utilities/doctype/profile_control/profile_control.py b/erpnext/utilities/doctype/profile_control/profile_control.py
index 189d8b1..b8db231 100644
--- a/erpnext/utilities/doctype/profile_control/profile_control.py
+++ b/erpnext/utilities/doctype/profile_control/profile_control.py
@@ -22,66 +22,9 @@
self.doc, self.doclist = d,dl
self.last_profile = None
- # Sync Profile with Gateway
- # -------------------------
- def sync_with_gateway(self,pid):
- p = Document('Profile',pid)
-
- # login to gateway
- from webnotes.utils.webservice import FrameworkServer
- fw = FrameworkServer('www.erpnext.com','/','__system@webnotestech.com','password',https=1)
-
- account_id = sql("select value from tabSingles where doctype='Control Panel' and field='account_id'")[0][0]
-
- # call add profile
- ret = fw.runserverobj('Profile Control','Profile Control','add_profile_gateway',str([p.first_name, p.middle_name, p.last_name, p.email, p.name, account_id]))
-
- if ret.get('exc'):
- msgprint(ret['exc'])
- raise Exception
-
def get_role_permission(self,role):
perm = sql("select distinct t1.`parent`, t1.`read`, t1.`write`, t1.`create`, t1.`submit`,t1.`cancel`,t1.`amend` from `tabDocPerm` t1, `tabDocType` t2 where t1.`role` ='%s' and t1.docstatus !=2 and t1.permlevel = 0 and t1.`read` = 1 and t2.module != 'Recycle Bin' and t1.parent=t2.name "%role)
return perm or ''
-
-
- # Check if password is expired
- # --------------------------------
- def has_pwd_expired(self):
- if session['user'] != 'Administrator' and session['user'].lower() != 'demo':
- last_pwd_date = None
- try:
- last_pwd_date = sql("select password_last_updated from tabProfile where name=%s",session['user'])[0][0] or ''
- except:
- return 'No'
- if cstr(last_pwd_date) == '':
- sql("update tabProfile set password_last_updated = '%s' where name='%s'"% (nowdate(),session['user']))
- return 'No'
- else:
- date_diff = (getdate(nowdate()) - last_pwd_date).days
- expiry_period = sql("select value from tabSingles where doctype='Control Panel' and field='password_expiry_days'")
- if expiry_period and cint(expiry_period[0][0]) and cint(expiry_period[0][0]) < date_diff:
- return 'Yes'
- return 'No'
-
- def reset_password(self,pwd):
- if sql("select name from tabProfile where password=PASSWORD(%s) and name=%s", (pwd,session['user'])):
- return 'Password cannot be same as old password'
- sql("update tabProfile set password=PASSWORD(%s),password_last_updated=%s where name = %s", (pwd,nowdate(),session['user']))
- return 'ok'
-
-#-------------------------------------------------------------------------------------------------------
- #functions for manage user page
- #-----------Enable/Disable Profile-----------------------------------------------------------------------------------------------
- def change_login(self,args):
- args = eval(args)
-
- if cint(args['set_disabled'])==0:
- sql("update `tabProfile` set enabled=1 where name='%s'"%args['user'])
- else:
- sql("update `tabProfile` set enabled=0 where name='%s'"%args['user'])
-
- return 'ok'
#------------return role list -------------------------------------------------------------------------------------------------
# All roles of Role Master
@@ -113,75 +56,3 @@
pr.parentfield = 'userroles'
pr.save(1)
-
-
- # Add new member
- # ---------------
- def add_profile(self,arg):
-
- # Check credit balance
- get_obj('WN ERP Client Control').check_credit_balance()
-
- arg=eval(arg)
- pr=Document('Profile')
- for d in arg.keys():
- if d!='role':
- pr.fields[d] = arg[d]
-
- pr.enabled=0
- pr.user_type='System User'
- pr.save(1)
- pr_obj = get_obj('Profile',pr.name)
- if (pr.name):
- msg="New member is added"
- pr_obj.on_update()
- else:
- msg="Profile not created"
-
- return cstr(msg)
-
- # to find currently login user
- def current_login(self):
- cl_list=sql("select distinct user from tabSessions")
- if cl_list:
- cl_list=[x[0] for x in cl_list]
-
- return cl_list
-
-
- # Remove Profile
- # ---------------
- def remove_profile(self, user):
- # delete profile
- webnotes.model.delete_doc('Profile',user)
-
- # Update WN ERP Client Control
- sql("update tabSingles set value = value - 1 where field = 'total_users' and doctype = 'WN ERP Client Control'")
-
- # login to gateway
- from webnotes.utils.webservice import FrameworkServer
- fw = FrameworkServer('www.erpnext.com','/','__system@webnotestech.com','password',https=1)
-
- account_id = sql("select value from tabSingles where doctype='Control Panel' and field='account_id'")[0][0]
-
- # call remove profile
- ret = fw.runserverobj('Profile Control','Profile Control','remove_app_sub',str([user, account_id, session['user']]))
-
- if ret.get('exc'):
- msgprint(ret['exc'])
- raise Exception
-
- return "User Removed Successfully"
-
-
- # Create Profile
- # ---------------
- def create_profile(self, email):
- if sql("select name from tabProfile where name = %s", email):
- sql("update tabProfile set docstatus = 0 where name = %s", email)
- else:
- pr = Document('Profile')
- pr.email = email
- pr.enabled=0
- pr.user_type='System User'
- pr.save(1)