webshop login, logout
This commit is contained in:
parent
8f43b31dae
commit
a54cb247c4
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
var erpnext = {};
|
var erpnext = {};
|
||||||
|
|
||||||
|
// Add / update a new Lead / Communication
|
||||||
// subject, sender, description
|
// subject, sender, description
|
||||||
erpnext.send_message = function(opts) {
|
erpnext.send_message = function(opts) {
|
||||||
if(opts.btn) {
|
if(opts.btn) {
|
||||||
@ -31,6 +32,27 @@ erpnext.send_message = function(opts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup the user tools
|
||||||
|
//
|
||||||
|
$(document).ready(function() {
|
||||||
|
// update login
|
||||||
|
var full_name = getCookie("full_name");
|
||||||
|
if(full_name.substr(0,1)=='"') {
|
||||||
|
full_name = full_name.substr(1, full_name.length-2);
|
||||||
|
}
|
||||||
|
if(full_name) {
|
||||||
|
$("#user-tools").html(repl('<a href="account" title="My Account">%(full_name)s</a> | \
|
||||||
|
<a href="cart" title="Shopping Cart"><i class="icon-shopping-cart"></i> (%(count)s)</a> | \
|
||||||
|
<a href="server.py?cmd=web_logout" title="Sign Out"><i class="icon-signout"></i></a>', {
|
||||||
|
full_name: full_name,
|
||||||
|
count: getCookie("cart_count") || "0"
|
||||||
|
}));
|
||||||
|
$("#user-tools a").tooltip({"placement":"bottom"});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Utility functions
|
||||||
|
|
||||||
function valid_email(id) {
|
function valid_email(id) {
|
||||||
if(id.toLowerCase().search("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")==-1)
|
if(id.toLowerCase().search("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")==-1)
|
||||||
return 0; else return 1; }
|
return 0; else return 1; }
|
||||||
@ -55,3 +77,51 @@ function repl(s, dict) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCookie(name) {
|
||||||
|
return getCookies()[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCookies() {
|
||||||
|
var c = document.cookie, v = 0, cookies = {};
|
||||||
|
if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
|
||||||
|
c = RegExp.$1;
|
||||||
|
v = 1;
|
||||||
|
}
|
||||||
|
if (v === 0) {
|
||||||
|
c.split(/[,;]/).map(function(cookie) {
|
||||||
|
var parts = cookie.split(/=/, 2),
|
||||||
|
name = decodeURIComponent(parts[0].trimLeft()),
|
||||||
|
value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
|
||||||
|
cookies[name] = value;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
c.match(/(?:^|\s+)([!#$%&'*+\-.0-9A-Z^`a-z|~]+)=([!#$%&'*+\-.0-9A-Z^`a-z|~]*|"(?:[\x20-\x7E\x80\xFF]|\\[\x00-\x7F])*")(?=\s*[,;]|$)/g).map(function($0, $1) {
|
||||||
|
var name = $0,
|
||||||
|
value = $1.charAt(0) === '"'
|
||||||
|
? $1.substr(1, -1).replace(/\\(.)/g, "$1")
|
||||||
|
: $1;
|
||||||
|
cookies[name] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cookies;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof String.prototype.trimLeft !== "function") {
|
||||||
|
String.prototype.trimLeft = function() {
|
||||||
|
return this.replace(/^\s+/, "");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof String.prototype.trimRight !== "function") {
|
||||||
|
String.prototype.trimRight = function() {
|
||||||
|
return this.replace(/\s+$/, "");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof Array.prototype.map !== "function") {
|
||||||
|
Array.prototype.map = function(callback, thisArg) {
|
||||||
|
for (var i=0, n=this.length, a=[]; i<n; i++) {
|
||||||
|
if (i in this) a[i] = callback.call(thisArg, this[i]);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -105,6 +105,7 @@ def get_dropbox_session():
|
|||||||
return sess
|
return sess
|
||||||
|
|
||||||
def upload_file_to_dropbox(filename, folder, dropbox_client):
|
def upload_file_to_dropbox(filename, folder, dropbox_client):
|
||||||
|
from dropbox import rest
|
||||||
size = os.stat(filename).st_size
|
size = os.stat(filename).st_size
|
||||||
f = open(filename,'r')
|
f = open(filename,'r')
|
||||||
if size > 4194304:
|
if size > 4194304:
|
||||||
|
@ -1,99 +1,7 @@
|
|||||||
# Please edit this list and import only required elements
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
from webnotes.utils import set_default
|
|
||||||
from webnotes.model import db_exists
|
|
||||||
from webnotes.model.doc import Document
|
|
||||||
from webnotes.model.bean import copy_doclist
|
|
||||||
from webnotes.model.code import get_obj
|
|
||||||
from webnotes import msgprint
|
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self,doc,doclist=[]):
|
def __init__(self,doc,doclist=[]):
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
self.doclist = doclist
|
self.doclist = doclist
|
||||||
|
|
||||||
def enable_login(self,arg):
|
|
||||||
arg = eval(arg)
|
|
||||||
sql("update tabContact set disable_login = 'No' where name=%s",arg['contact'])
|
|
||||||
sql("update tabProfile set enabled=1 where name=%s",arg['email'])
|
|
||||||
|
|
||||||
def disable_login(self,arg):
|
|
||||||
arg = eval(arg)
|
|
||||||
sql("update tabContact set disable_login = 'Yes' where name=%s",arg['contact'])
|
|
||||||
sql("update tabProfile set enabled=0 where name=%s",arg['email'])
|
|
||||||
|
|
||||||
def create_login(self,arg):
|
|
||||||
arg = eval(arg)
|
|
||||||
cont_det = sql("select * from tabContact where name=%s",(arg['contact']),as_dict=1)
|
|
||||||
if cont_det[0]['docstatus'] !=0:
|
|
||||||
msgprint('Please save the corresponding contact first')
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
if sql("select name from tabProfile where name=%s",cont_det[0]['email_id']):
|
|
||||||
msgprint('Profile with same name already exist.')
|
|
||||||
raise Exception
|
|
||||||
else:
|
|
||||||
p = Document('Profile')
|
|
||||||
p.name = cont_det[0]['email_id']
|
|
||||||
p.first_name = cont_det[0]['first_name']
|
|
||||||
p.last_name = cont_det[0]['last_name']
|
|
||||||
p.email = cont_det[0]['email_id']
|
|
||||||
p.cell_no = cont_det[0]['contact_no']
|
|
||||||
p.password = 'password'
|
|
||||||
p.enabled = 1
|
|
||||||
p.user_type = 'Partner';
|
|
||||||
p.save(1)
|
|
||||||
|
|
||||||
get_obj(doc=p).on_update()
|
|
||||||
|
|
||||||
role = []
|
|
||||||
if cont_det[0]['contact_type'] == 'Individual':
|
|
||||||
role = ['Customer']
|
|
||||||
else:
|
|
||||||
if cont_det[0]['is_customer']:
|
|
||||||
role.append('Customer')
|
|
||||||
if cont_det[0]['is_supplier']:
|
|
||||||
role.append('Supplier')
|
|
||||||
if cont_det[0]['is_sales_partner']:
|
|
||||||
role.append('Partner')
|
|
||||||
|
|
||||||
if role:
|
|
||||||
prof_nm = p.name
|
|
||||||
for i in role:
|
|
||||||
r = Document('UserRole')
|
|
||||||
r.parent = p.name
|
|
||||||
r.role = i
|
|
||||||
r.parenttype = 'Profile'
|
|
||||||
r.parentfield = 'userroles'
|
|
||||||
r.save(1)
|
|
||||||
|
|
||||||
if i == 'Customer':
|
|
||||||
def_keys = ['from_company','customer_name','customer']
|
|
||||||
def_val = cont_det[0]['customer_name']
|
|
||||||
self.set_default_val(def_keys,def_val,prof_nm)
|
|
||||||
|
|
||||||
if i == 'Supplier':
|
|
||||||
def_keys = ['supplier_name','supplier']
|
|
||||||
def_val = cont_det[0]['supplier_name']
|
|
||||||
self.set_default_val(def_keys,def_val,prof_nm)
|
|
||||||
|
|
||||||
sql("update tabContact set has_login = 'Yes' where name=%s",cont_det[0]['name'])
|
|
||||||
sql("update tabContact set disable_login = 'No' where name=%s",cont_det[0]['name'])
|
|
||||||
msgprint('User login is created.')
|
|
||||||
|
|
||||||
#------set default values---------
|
|
||||||
def set_default_val(self,def_keys,def_val,prof_nm):
|
|
||||||
for d in def_keys:
|
|
||||||
kv = Document('DefaultValue')
|
|
||||||
kv.defkey = d
|
|
||||||
kv.defvalue = def_val
|
|
||||||
kv.parent = prof_nm
|
|
||||||
kv.parenttype = 'Profile'
|
|
||||||
kv.parentfield = 'defaults'
|
|
||||||
kv.save(1)
|
|
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
"creation": "2013-03-08 11:36:50",
|
"creation": "2013-03-08 11:36:50",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-03-11 15:23:21",
|
"modified": "2013-03-18 13:55:53",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -65,6 +65,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "blogger",
|
"fieldname": "blogger",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Blogger",
|
"label": "Blogger",
|
||||||
"options": "Blogger",
|
"options": "Blogger",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
@ -73,6 +74,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "blog_category",
|
"fieldname": "blog_category",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Blog Category",
|
"label": "Blog Category",
|
||||||
"options": "Blog Category"
|
"options": "Blog Category"
|
||||||
},
|
},
|
||||||
@ -86,6 +88,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "blog_intro",
|
"fieldname": "blog_intro",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Blog Intro",
|
"label": "Blog Intro",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
|
@ -4,9 +4,17 @@
|
|||||||
margin: 70px auto;
|
margin: 70px auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#login_wrapper,
|
||||||
|
#login_wrapper h3 {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
#login_wrapper a {
|
||||||
|
color: #0088cc;
|
||||||
|
}
|
||||||
|
|
||||||
.layout-wrapper {
|
.layout-wrapper {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
color: #333;
|
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
box-shadow: 1px 1px 3px 3px #ccc;
|
box-shadow: 1px 1px 3px 3px #ccc;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@ -32,7 +40,4 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
.login-footer, .login-footer a {
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
@ -47,9 +47,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav pull-right">
|
|
||||||
<li id="login-topbar-item"><a href="login">Login</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
<header>
|
<header>
|
||||||
</header>
|
</header>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="pull-right" style="margin:4px;" id="user-tools">
|
||||||
|
<a id="login-link" href="login">Login</a>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
{% if banner_html %}<div class="row" style="margin-top: 30px;">
|
{% if banner_html %}<div class="row" style="margin-top: 30px;">
|
||||||
<div class="span12">{{ banner_html }}</div>
|
<div class="span12">{{ banner_html }}</div>
|
||||||
</div>{% endif %}
|
</div>{% endif %}
|
||||||
|
@ -19,25 +19,43 @@ $(document).ready(function(wrapper) {
|
|||||||
login.do_login = function(){
|
login.do_login = function(){
|
||||||
|
|
||||||
var args = {};
|
var args = {};
|
||||||
args['usr']=$("#login_id").val();
|
if(window.is_sign_up) {
|
||||||
args['pwd']=$("#password").val();
|
args.cmd = "core.doctype.profile.profile.sign_up";
|
||||||
|
args.email = $("#login_id").val();
|
||||||
|
args.full_name = $("#full_name").val();
|
||||||
|
|
||||||
|
if(!args.email || !valid_email(args.email) || !args.full_name) {
|
||||||
|
login.set_message("Valid email and name required.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
args.cmd = "login"
|
||||||
|
args.usr = $("#login_id").val();
|
||||||
|
args.pwd = $("#password").val();
|
||||||
|
|
||||||
if(!args.usr || !args.pwd) {
|
if(!args.usr || !args.pwd) {
|
||||||
login.set_message("Both login and password required.");
|
login.set_message("Both login and password required.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#login_btn').attr("disabled", "disabled");
|
$('#login_btn').attr("disabled", "disabled");
|
||||||
|
$("#login-spinner").toggle(true);
|
||||||
$('#login_message').toggle(false);
|
$('#login_message').toggle(false);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "server.py",
|
url: "server.py",
|
||||||
data: {cmd:"login", usr:args.usr, pwd: args.pwd},
|
data: args,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
$("#login-spinner").toggle(false);
|
||||||
$('#login_btn').attr("disabled", false);
|
$('#login_btn').attr("disabled", false);
|
||||||
if(data.message=="Logged In") {
|
if(data.message=="Logged In") {
|
||||||
window.location.href = "app.html";
|
window.location.href = "app.html";
|
||||||
|
} else if(data.message=="No App") {
|
||||||
|
window.location.href = "index";
|
||||||
} else {
|
} else {
|
||||||
login.set_message(data.message);
|
login.set_message(data.message);
|
||||||
}
|
}
|
||||||
@ -47,6 +65,16 @@ login.do_login = function(){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
login.sign_up = function() {
|
||||||
|
$("#login_wrapper h3").html("Sign Up");
|
||||||
|
$("#login-label").html("Email Id");
|
||||||
|
$("#password-label").html("Full Name");
|
||||||
|
$("#password-row, #forgot-wrapper, #sign-up-wrapper, #login_message").toggle(false);
|
||||||
|
$("#full-name-row").toggle(true);
|
||||||
|
$("#login_btn").html("Register");
|
||||||
|
window.is_sign_up = true;
|
||||||
|
}
|
||||||
|
|
||||||
login.show_forgot_password = function(){
|
login.show_forgot_password = function(){
|
||||||
// create dialog
|
// create dialog
|
||||||
var login_id = $("#login_id").val();
|
var login_id = $("#login_id").val();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
{% set title="Login" %}
|
{% set title="Login" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div id='login_wrapper'>
|
<div class="container" id='login_wrapper'>
|
||||||
<div class='layout-wrapper layout-main'>
|
<div class='layout-wrapper layout-main'>
|
||||||
<p id="login_message" class="alert" style="display: none;"></p>
|
<p id="login_message" class="alert" style="display: none;"></p>
|
||||||
<h3><i class="icon-lock" style="margin-top: 7px"></i> Login</h3>
|
<h3><i class="icon-lock" style="margin-top: 7px"></i> Login</h3>
|
||||||
@ -18,34 +18,45 @@
|
|||||||
<table border="0" class="login-box">
|
<table border="0" class="login-box">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right; padding: 3px;">Login Id</td>
|
<td style="text-align: right; padding: 3px;"
|
||||||
|
id="login-label">Login Id</td>
|
||||||
<td><input id="login_id" type="text" style="width: 180px"/></td>
|
<td><input id="login_id" type="text" style="width: 180px"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr id="password-row">
|
||||||
<td style="text-align: right; padding: 3px;" >Password</td>
|
<td style="text-align: right; padding: 3px;" >Password</td>
|
||||||
<td><input id="password" type="password" style="width: 180px" /></td>
|
<td><input id="password" type="password" style="width: 180px" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr id="full-name-row" style="display: none;">
|
||||||
|
<td style="text-align: right; padding: 3px;">Full Name</td>
|
||||||
|
<td><input id="full_name" type="text" style="width: 180px" /></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
<td>
|
<td>
|
||||||
<button type="submit" id="login_btn"
|
<button type="submit" id="login_btn"
|
||||||
class="btn btn-small btn-primary">Login</button>
|
class="btn btn-small btn-primary">Login</button>
|
||||||
|
<img src="lib/images/ui/button-load.gif" id="login-spinner"
|
||||||
|
style="display: none;">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
<br>
|
<br>
|
||||||
<p style="text-align: center"><a id="forgot-password"
|
<p style="text-align: center" id="forgot-wrapper">
|
||||||
|
<a id="forgot-password" style="cursor:pointer"
|
||||||
onclick="return login.show_forgot_password()">Forgot Password</a></p>
|
onclick="return login.show_forgot_password()">Forgot Password</a></p>
|
||||||
|
<p style="text-align: center" id="sign-up-wrapper">
|
||||||
|
New user? <a id="sign-up" style="cursor:pointer"
|
||||||
|
onclick="return login.sign_up()">Sign Up</a></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="login-footer">
|
</div>
|
||||||
|
<div class="web-footer login-footer container">
|
||||||
<a href="index.html">Home</a> |
|
<a href="index.html">Home</a> |
|
||||||
<a href="https://erpnext.com">ERPNext</a><br><br>
|
<a href="https://erpnext.com">ERPNext</a><br><br>
|
||||||
{% if copyright %}
|
{% if copyright %}
|
||||||
<div class="web-footer-copyright">© {{ copyright }}
|
<div class="web-footer-copyright">© {{ copyright }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user