new login authentication
This commit is contained in:
parent
16c4e72199
commit
bedc1fe534
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
*.comp.js
|
||||
.DS_Store
|
||||
server_tools
|
||||
user_files
|
||||
patch.log
|
||||
lib
|
||||
versions-local.db
|
||||
|
@ -6,7 +6,7 @@ pscript['onload_Event Updates'] = function() {
|
||||
|
||||
pscript.home_make_body();
|
||||
pscript.home_make_status();
|
||||
pscript.home_pre_process();
|
||||
pscript.home_set_banner();
|
||||
pscript.home_make_widgets();
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ pscript.home_make_body = function() {
|
||||
|
||||
// ==================================
|
||||
|
||||
pscript.home_pre_process = function(wrapper) {
|
||||
pscript.home_set_banner = function(wrapper) {
|
||||
var wrapper = page_body.pages['Event Updates'];
|
||||
var cp = locals['Control Panel']['Control Panel'];
|
||||
|
||||
|
@ -43,14 +43,11 @@ pscript.myc_show_erpnext_message = function() {
|
||||
//
|
||||
pscript.myc_add_user = function() {
|
||||
var fields = [{
|
||||
fieldtype: 'Data',
|
||||
fieldname: 'user',
|
||||
reqd: 1,
|
||||
label: 'Email Id of the user to add'
|
||||
}];
|
||||
|
||||
if(!pscript.is_erpnext_saas) {
|
||||
fields = fields.concat([
|
||||
fieldtype: 'Data',
|
||||
fieldname: 'user',
|
||||
reqd: 1,
|
||||
label: 'Email Id of the user to add'
|
||||
},
|
||||
{
|
||||
fieldtype: 'Data',
|
||||
fieldname: 'first_name',
|
||||
@ -67,14 +64,15 @@ pscript.myc_add_user = function() {
|
||||
fieldname: 'password',
|
||||
reqd: 1,
|
||||
label: 'Password'
|
||||
}]);
|
||||
},
|
||||
{
|
||||
fieldtype: 'Button',
|
||||
label: 'Add',
|
||||
fieldname: 'add'
|
||||
}];
|
||||
}
|
||||
|
||||
fields.push({
|
||||
fieldtype: 'Button',
|
||||
label: 'Add',
|
||||
fieldname: 'add'
|
||||
});
|
||||
fields.push();
|
||||
|
||||
var d = new wn.widgets.Dialog({
|
||||
title: 'Add User',
|
||||
|
@ -2,102 +2,28 @@ import webnotes
|
||||
import webnotes.defs
|
||||
from webnotes.utils import cint
|
||||
|
||||
#
|
||||
# alias the current user
|
||||
#
|
||||
def on_login(login_manager):
|
||||
"""
|
||||
called from login manager, before login
|
||||
"""
|
||||
try:
|
||||
import server_tools.gateway_utils
|
||||
server_tools.gateway_utils.check_login()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# login as
|
||||
if login_manager.user == 'Administrator':
|
||||
user = webnotes.form.getvalue('login_as')
|
||||
|
||||
if user:
|
||||
# create if missing (due to some bug)
|
||||
login_as(user, login_manager)
|
||||
|
||||
# alisaing here... so check if the user is disabled
|
||||
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)
|
||||
|
||||
if hasattr(webnotes.defs, 'validate_ip'):
|
||||
msg = getattr(webnotes.defs, 'validate_ip')()
|
||||
if msg: webnotes.msgprint(msg, raise_exception=1)
|
||||
|
||||
login_manager.user = user
|
||||
|
||||
#
|
||||
# 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()
|
||||
|
||||
#
|
||||
# save (login from)
|
||||
#
|
||||
def on_login_post_session(login_manager):
|
||||
# login from
|
||||
if webnotes.form_dict.get('login_from'):
|
||||
webnotes.session['data']['login_from'] = webnotes.form.getvalue('login_from')
|
||||
webnotes.session_obj.update()
|
||||
|
||||
"""
|
||||
called after login
|
||||
update login_from and delete parallel sessions
|
||||
"""
|
||||
# Clear previous sessions i.e. logout previous log-in attempts
|
||||
exception_list = ['demo@webnotestech.com', 'Administrator']
|
||||
if webnotes.session['user'] not in exception_list:
|
||||
sid_list = webnotes.conn.sql("""
|
||||
SELECT sid
|
||||
FROM `tabSessions`
|
||||
DELETE FROM `tabSessions`
|
||||
WHERE
|
||||
user=%s AND
|
||||
sid!=%s
|
||||
ORDER BY lastupdate desc""", \
|
||||
sid!=%s""", \
|
||||
(webnotes.session['user'], webnotes.session['sid']), as_list=1)
|
||||
for sid in sid_list:
|
||||
webnotes.conn.sql("DELETE FROM `tabSessions` WHERE sid=%s", sid[0])
|
||||
|
||||
update_account_details()
|
||||
|
||||
#
|
||||
# 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)
|
||||
|
||||
#
|
||||
# create a profile (if logs in for the first time)
|
||||
#
|
||||
def login_as(user, login_manager):
|
||||
import os
|
||||
import webnotes
|
||||
webnotes.session = {'user': user}
|
||||
ip = os.environ.get('REMOTE_ADDR')
|
||||
|
||||
# validate if user is from SSO
|
||||
if ip == '72.55.168.105' or 1:
|
||||
# if user does not exist, create it
|
||||
if not webnotes.conn.sql("select name from tabProfile where name=%s", user):
|
||||
from webnotes.model.doc import Document
|
||||
|
||||
import webnotes
|
||||
import webnotes.utils.webservice
|
||||
|
||||
p = Document('Profile')
|
||||
p.first_name = webnotes.form_dict.get('first_name')
|
||||
p.last_name = webnotes.form_dict.get('last_name')
|
||||
p.email = user
|
||||
p.name = user
|
||||
p.enabled = 1
|
||||
p.owner = user
|
||||
p.save(1)
|
||||
|
||||
|
@ -12,22 +12,14 @@ body {
|
||||
background-color: #e2e2e2;
|
||||
}
|
||||
|
||||
.layout_wrapper {
|
||||
padding: 13px;
|
||||
margin: 7px;
|
||||
-moz-box-shadow: 1px 1px 6px #AAA;
|
||||
-webkit-box-shadow: 1px 1px 6px #AAA;
|
||||
box-shadow: 1px 1px 6px #AAA;
|
||||
background-color: #FFF;
|
||||
.erpnext-footer {
|
||||
margin: 3px auto;
|
||||
color: #888;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#birthday_area {
|
||||
display: none;
|
||||
padding: 4px;
|
||||
margin-bottom: 8px;
|
||||
background-color: #FDD;
|
||||
padding: 4px;
|
||||
color: #644;
|
||||
.erpnext-footer a, .erpnext-footer a:hover, .erpnext-footer a:visited {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.module-icons {
|
||||
|
@ -13,7 +13,6 @@ if(inList(user_roles,'System Manager')) is_system_manager = 1;
|
||||
function startup_setup() {
|
||||
pscript.is_erpnext_saas = cint(locals['Control Panel']['Control Panel'].sync_with_gateway)
|
||||
|
||||
|
||||
if(get_url_arg('embed')) {
|
||||
// hide header, footer
|
||||
$dh(page_body.banner_area);
|
||||
@ -21,18 +20,18 @@ function startup_setup() {
|
||||
$dh(page_body.footer);
|
||||
return;
|
||||
}
|
||||
|
||||
if(user=='Guest' && !get_url_arg('akey')) {
|
||||
if(pscript.is_erpnext_saas) {
|
||||
window.location.href = 'https://www.erpnext.com';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// page structure
|
||||
// --------------
|
||||
$td(page_body.wntoolbar.body_tab,0,0).innerHTML = '<i><b>erp</b>next</i>';
|
||||
$y($td(page_body.wntoolbar.body_tab,0,0), {width:'140px', color:'#FFF', paddingLeft:'8px', paddingRight:'8px', fontSize:'14px'})
|
||||
if(page_body.wntoolbar) {
|
||||
$td(page_body.wntoolbar.body_tab,0,0).innerHTML = '<i><b>erp</b>next</i>';
|
||||
$y($td(page_body.wntoolbar.body_tab,0,0), {
|
||||
width:'140px',
|
||||
color:'#FFF',
|
||||
paddingLeft:'8px',
|
||||
paddingRight:'8px',
|
||||
fontSize:'14px'
|
||||
});
|
||||
}
|
||||
$dh(page_body.banner_area);
|
||||
|
||||
// sidebar
|
||||
@ -41,7 +40,7 @@ function startup_setup() {
|
||||
|
||||
// border to the body
|
||||
// ------------------
|
||||
$dh(page_body.footer);
|
||||
page_body.footer.innerHTML = '<div class="erpnext-footer">Powered by <a href="https://erpnext.com">ERPNext</a></div>';
|
||||
|
||||
// setup toolbar
|
||||
pscript.startup_setup_toolbar();
|
||||
|
@ -3,7 +3,7 @@
|
||||
<meta charset="utf-8">
|
||||
<title>ERPNext</title>
|
||||
<meta name="author" content="">
|
||||
<script type="text/javascript">window._version_number="34"
|
||||
<script type="text/javascript">window._version_number="45"
|
||||
|
||||
wn={}
|
||||
wn.provide=function(namespace){var nsl=namespace.split('.');var l=nsl.length;var parent=window;for(var i=0;i<l;i++){var n=nsl[i];if(!parent[n]){parent[n]={}}
|
||||
|
@ -1 +1 @@
|
||||
34
|
||||
45
|
Loading…
Reference in New Issue
Block a user