Commit 8b628922 authored by Prajkta_Patkar's avatar Prajkta_Patkar
Browse files

New function created to fire alter queries.

code added to check the fields
parent 17f74ca7
......@@ -41,11 +41,24 @@ def inventoryMigration(con,eng):
con.execute("alter table organisation add column invflag Integer default 0 ")
con.execute("alter table vouchers add column invid Integer")
con.execute("alter table vouchers add foreign key (invid) references invoice(invid)")
con.execute("alter table transfernote add recieveddate date")
con.execute("alter table delchal add noofpackages int")
con.execute("alter table delchal add modeoftransport text")
try:
con.execute("select themename from users")
except:
con.execute("alter table users add column themename text default 'Default'")
return 0
def addFields(con,eng):
metadata.create_all(eng)
try:
con.execute("select noofpackages,modeoftransport from delchal")
con.execute("select recieveddate from transfernote")
except:
con.execute("alter table transfernote add recieveddate date")
con.execute("alter table delchal add noofpackages int")
con.execute("alter table delchal add modeoftransport text")
return 0
......@@ -6,7 +6,7 @@ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
GNUKhata is Free Software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.and old.stockflag = 's'
the License, or (at your option) any later version.
GNUKhata is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -38,7 +38,7 @@ from pyramid.response import Response
from pyramid.view import view_defaults, view_config
from sqlalchemy.ext.baked import Result
from Crypto.PublicKey import RSA
from gkcore.models.meta import inventoryMigration
from gkcore.models.meta import inventoryMigration,addFields
import jwt
import gkcore
con= Connection
......@@ -54,42 +54,48 @@ def gkLogin(request):
The object will have the userid and orgcode and this will be sent back as a response.
Else the function will not issue any token.
"""
# try:
con= eng.connect()
try:
con= eng.connect()
try:
con.execute(select([gkdb.organisation.c.invflag]))
con.execute(select([gkdb.tranfernote.c.recieveddate]))
con.execute(select([gkdb.delchal.c.noofpackages,gkdb.delchal.c.modeoftransport]))
except:
inventoryMigration(con,eng)
dataset = request.json_body
result = con.execute(select([gkdb.users.c.userid]).where(and_(gkdb.users.c.username==dataset["username"], gkdb.users.c.userpassword== dataset["userpassword"], gkdb.users.c.orgcode==dataset["orgcode"])) )
if result.rowcount == 1:
record = result.fetchone()
result = con.execute(select([gkdb.signature]))
sign = result.fetchone()
if sign == None:
con.execute(select([gkdb.organisation.c.invflag]))
except:
inventoryMigration(con,eng)
try:
con.execute(select([gkdb.delchal.c.modeoftransport,gkdb.delchal.c.noofpackages]))
con.execute(select([gkdb.transfernote.c.recieveddate]))
except:
addFields(con,eng)
dataset = request.json_body
result = con.execute(select([gkdb.users.c.userid]).where(and_(gkdb.users.c.username==dataset["username"], gkdb.users.c.userpassword== dataset["userpassword"], gkdb.users.c.orgcode==dataset["orgcode"])) )
if result.rowcount == 1:
record = result.fetchone()
result = con.execute(select([gkdb.signature]))
sign = result.fetchone()
if sign == None:
key = RSA.generate(2560)
privatekey = key.exportKey('PEM')
sig = {"secretcode":privatekey}
gkcore.secret = privatekey
result = con.execute(gkdb.signature.insert(),[sig])
elif len(sign["secretcode"]) <= 20:
result = con.execute(gkdb.signature.delete())
if result.rowcount == 1:
key = RSA.generate(2560)
privatekey = key.exportKey('PEM')
sig = {"secretcode":privatekey}
gkcore.secret = privatekey
result = con.execute(gkdb.signature.insert(),[sig])
elif len(sign["secretcode"]) <= 20:
result = con.execute(gkdb.signature.delete())
if result.rowcount == 1:
key = RSA.generate(2560)
privatekey = key.exportKey('PEM')
sig = {"secretcode":privatekey}
gkcore.secret = privatekey
result = con.execute(gkdb.signature.insert(),[sig])
token = jwt.encode({"orgcode":dataset["orgcode"],"userid":record["userid"]},gkcore.secret,algorithm='HS256')
return {"gkstatus":enumdict["Success"],"token":token }
else:
return {"gkstatus":enumdict["UnauthorisedAccess"]}
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
finally:
con.close()
token = jwt.encode({"orgcode":dataset["orgcode"],"userid":record["userid"]},gkcore.secret,algorithm='HS256')
return {"gkstatus":enumdict["Success"],"token":token }
else:
return {"gkstatus":enumdict["UnauthorisedAccess"]}
# except:
# return {"gkstatus":enumdict["ConnectionFailed"]}
# finally:
# con.close()
@view_config(route_name='login',request_method='GET',renderer='json')
def getuserorgdetails(request):
......
......@@ -41,7 +41,8 @@ import gkcore
from gkcore.models.meta import dbconnect
from Crypto.PublicKey import RSA
from gkcore.models.gkdb import metadata
from gkcore.models.meta import inventoryMigration
from gkcore.models.meta import inventoryMigration,addFields
con= Connection
@view_defaults(route_name='organisations')
class api_organisation(object):
......@@ -105,10 +106,14 @@ class api_organisation(object):
result = self.con.execute(gkdb.signature.insert(),[sig])
try:
self.con.execute(select([gkdb.organisation.c.invflag]))
con.execute(select([gkdb.tranfernote.c.recieveddate]))
con.execute(select([gkdb.delchal.c.noofpackages,gkdb.delchal.c.modeoftransport]))
except:
inventoryMigration(self.con,eng)
try:
con.execute(select([gkdb.delchal.c.modeoftransport,gkdb.delchal.c.noofpackages]))
con.execute(select([gkdb.transfernote.c.recieveddate]))
except:
addFields(self.con,eng)
result = self.con.execute(gkdb.organisation.insert(),[orgdata])
if result.rowcount==1:
code = self.con.execute(select([gkdb.organisation.c.orgcode]).where(and_(gkdb.organisation.c.orgname==orgdata["orgname"], gkdb.organisation.c.orgtype==orgdata["orgtype"], gkdb.organisation.c.yearstart==orgdata["yearstart"], gkdb.organisation.c.yearend==orgdata["yearend"])))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment