webshop login, logout

This commit is contained in:
Rushabh Mehta
2013-03-19 11:12:22 +05:30
parent 8f43b31dae
commit a54cb247c4
9 changed files with 147 additions and 120 deletions

View File

@@ -105,6 +105,7 @@ def get_dropbox_session():
return sess
def upload_file_to_dropbox(filename, folder, dropbox_client):
from dropbox import rest
size = os.stat(filename).st_size
f = open(filename,'r')
if size > 4194304:

View File

@@ -1,99 +1,7 @@
# Please edit this list and import only required elements
from __future__ import unicode_literals
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:
def __init__(self,doc,doclist=[]):
self.doc = doc
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)
def __init__(self,doc,doclist=[]):
self.doc = doc
self.doclist = doclist