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

94 lines
3.1 KiB
Python
Raw Normal View History

2012-02-23 07:05:32 +00:00
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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-02-15 08:35:42 +00:00
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'])
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
"""
2012-02-29 13:08:18 +00:00
from webnotes.utils.file_manager import add_file_list, remove_file
user = webnotes.session['user']
# remove old file
old_image = webnotes.conn.get_value('Profile', user, 'user_image')
if old_image:
remove_file('Profile', user, old_image)
# add new file
add_file_list('Profile', user, fname, fid)
webnotes.conn.set_value('Profile', user, 'user_image', fid)
@webnotes.whitelist()
def set_user_background(fid, fname):
"""
Set uploaded image as user image
"""
from webnotes.utils.file_manager import add_file_list, remove_file
user = webnotes.session['user']
# remove old file
old_image = webnotes.conn.get_value('Profile', user, 'background_image')
if old_image:
remove_file('Profile', user, old_image)
# add new file
add_file_list('Profile', user, fname, fid)
webnotes.conn.set_value('Profile', user, 'background_image', fid)