brotherton-erpnext/erpnext/home/page/profile_settings/profile_settings.py

49 lines
1.5 KiB
Python
Raw Normal View History

import webnotes
from webnotes.utils import load_json, cint, nowdate
2012-02-13 11:20:52 +00:00
@webnotes.whitelist()
def change_password(arg):
2011-07-06 05:12:02 +00:00
"""
Change password
"""
arg = load_json(arg)
2012-01-19 09:39:49 +00:00
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)
2012-01-19 09:39:49 +00:00
from webnotes.utils import nowdate
2012-01-19 10:43:34 +00:00
webnotes.conn.sql("update tabProfile set password=password(%s), modified=%s where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
2012-01-19 09:39:49 +00:00
webnotes.msgprint('Password Updated');
2012-02-13 11:20:52 +00:00
@webnotes.whitelist()
def get_user_details(arg=None):
2011-09-05 07:44:18 +00:00
"""
Returns user first name, last name and bio
"""
return webnotes.conn.sql("select first_name, last_name, bio from tabProfile where name=%s", webnotes.user.name, as_dict=1)[0]
2012-02-13 11:20:52 +00:00
@webnotes.whitelist()
def set_user_details(arg=None):
2011-09-05 07:44:18 +00:00
"""
updates user details given in argument
"""
from webnotes.model.doc import Document
p = Document('Profile', webnotes.user.name)
2012-01-11 11:23:50 +00:00
arg_dict = load_json(arg)
if not 'bio' in arg_dict: arg_dict['bio'] = None
if not 'last_name' in arg_dict: arg_dict['last_name'] = None
p.fields.update(arg_dict)
p.save()
webnotes.msgprint('Updated')
2011-09-05 07:44:18 +00:00
2012-02-13 11:20:52 +00:00
@webnotes.whitelist()
def set_user_image(fid, fname):
2011-09-05 07:44:18 +00:00
"""
Set uploaded image as user image
"""
from webnotes.utils.file_manager import add_file_list, remove_all
remove_all('Profile', webnotes.session['user'])
add_file_list('Profile', webnotes.session['user'], fname, fid)