mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
fixes to add user
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
from webnotes.utils import cint, load_json, cstr
|
from webnotes.utils import cint, load_json, cstr
|
||||||
|
from webnotes.model.doc import Document
|
||||||
|
|
||||||
try: import json
|
try: import json
|
||||||
except: import simplejson as json
|
except: import simplejson as json
|
||||||
@@ -65,8 +66,7 @@ def add_user(args):
|
|||||||
# add profile record
|
# add profile record
|
||||||
#
|
#
|
||||||
def add_profile(args):
|
def add_profile(args):
|
||||||
from webnotes.utils import validate_email_add
|
from webnotes.utils import validate_email_add, now
|
||||||
from webnotes.model.doc import Document
|
|
||||||
email = args['user']
|
email = args['user']
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
@@ -80,7 +80,7 @@ def add_profile(args):
|
|||||||
if sql("select name from tabProfile where name = %s", email):
|
if sql("select name from tabProfile where name = %s", email):
|
||||||
# exists, enable it
|
# exists, enable it
|
||||||
sql("update tabProfile set enabled = 1, docstatus=0 where name = %s", email)
|
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:
|
else:
|
||||||
# does not exist, create it!
|
# does not exist, create it!
|
||||||
pr = Document('Profile')
|
pr = Document('Profile')
|
||||||
@@ -95,8 +95,22 @@ def add_profile(args):
|
|||||||
if args.get('password'):
|
if args.get('password'):
|
||||||
sql("""
|
sql("""
|
||||||
UPDATE tabProfile
|
UPDATE tabProfile
|
||||||
SET password = PASSWORD(%s)
|
SET password = PASSWORD(%s), modified = %s
|
||||||
WHERE name = %s""", (args.get('password'), email))
|
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
|
# post comment
|
||||||
@@ -166,3 +180,18 @@ def update_security(args=''):
|
|||||||
else:
|
else:
|
||||||
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
|
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
|
||||||
else: webnotes.msgprint('Settings Updated')
|
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
|
||||||
|
"""
|
||||||
@@ -22,67 +22,10 @@ class DocType:
|
|||||||
self.doc, self.doclist = d,dl
|
self.doc, self.doclist = d,dl
|
||||||
self.last_profile = None
|
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):
|
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)
|
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 ''
|
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 -------------------------------------------------------------------------------------------------
|
#------------return role list -------------------------------------------------------------------------------------------------
|
||||||
# All roles of Role Master
|
# All roles of Role Master
|
||||||
def get_role(self):
|
def get_role(self):
|
||||||
@@ -113,75 +56,3 @@ class DocType:
|
|||||||
pr.parentfield = 'userroles'
|
pr.parentfield = 'userroles'
|
||||||
pr.save(1)
|
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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user