Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-090
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-090
2021-090
Commits
1ad31777
Commit
1ad31777
authored
Aug 22, 2021
by
IT18111170-Silva S.H.I
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update: issues fixed
parent
d3a9b45e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
21 deletions
+51
-21
Agri_Backend/Agripreneur_App/Auth/Token.py
Agri_Backend/Agripreneur_App/Auth/Token.py
+11
-5
Agri_Backend/Agripreneur_App/Routes/Gamification.py
Agri_Backend/Agripreneur_App/Routes/Gamification.py
+3
-2
Agri_Backend/Agripreneur_App/Routes/Leaderboard.py
Agri_Backend/Agripreneur_App/Routes/Leaderboard.py
+17
-6
Agri_Backend/Agripreneur_App/Routes/PricePage.py
Agri_Backend/Agripreneur_App/Routes/PricePage.py
+13
-6
Agri_Backend/Agripreneur_App/Routes/User.py
Agri_Backend/Agripreneur_App/Routes/User.py
+7
-2
No files found.
Agri_Backend/Agripreneur_App/Auth/Token.py
View file @
1ad31777
...
@@ -23,17 +23,23 @@ def check_for_token(func):
...
@@ -23,17 +23,23 @@ def check_for_token(func):
return
Response
(
return
Response
(
response
=
json
.
dumps
({
"message"
:
"Missing token"
}),
response
=
json
.
dumps
({
"message"
:
"Missing token"
}),
status
=
200
,
status
=
200
,
# need to find a way to continue the rest of called API, currently it shows the above message
)
)
try
:
try
:
data
=
jwt
.
decode
(
token
,
'app.SECRET_KEY'
,
[
'HS256'
])
data
=
jwt
.
decode
(
token
,
'app.SECRET_KEY'
,
[
'HS256'
])
return
Response
(
# return "123"
response
=
json
.
dumps
({
"message"
:
data
}),
# return Response(
status
=
200
,
# response= json.dumps({"message": data}),
)
# status=200,
# need to find a way to continue the rest of called API, currently it shows the above message
# )
except
:
except
:
return
Response
(
return
Response
(
response
=
json
.
dumps
({
"message"
:
"invalid token"
}),
response
=
json
.
dumps
({
"message"
:
"invalid token"
}),
status
=
200
,
status
=
200
,
# need to find a way to continue the rest of called API, currently it shows the above message
)
)
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
wrapped
return
wrapped
...
@@ -66,7 +72,7 @@ def public():
...
@@ -66,7 +72,7 @@ def public():
@
app
.
route
(
"/login"
,
methods
=
[
"POST"
])
@
app
.
route
(
"/login"
,
methods
=
[
"POST"
])
def
login
():
def
login
():
if
request
.
form
[
'email'
]
and
request
.
form
[
"password"
]
==
'password'
:
if
request
.
form
[
'email'
]
and
request
.
form
[
"password"
]:
session
[
'user'
]
=
request
.
form
[
'email'
]
session
[
'user'
]
=
request
.
form
[
'email'
]
token
=
jwt
.
encode
({
token
=
jwt
.
encode
({
'user'
:
request
.
form
[
'email'
]
'user'
:
request
.
form
[
'email'
]
...
...
Agri_Backend/Agripreneur_App/Routes/Gamification.py
View file @
1ad31777
...
@@ -5,7 +5,8 @@ from flask import Response, request
...
@@ -5,7 +5,8 @@ from flask import Response, request
# import pymongo
# import pymongo
import
json
import
json
from
bson.objectid
import
ObjectId
from
bson.objectid
import
ObjectId
import
Agripreneur_App.Auth.Token
from
Agripreneur_App.Auth.Token
import
check_for_token
...
@@ -17,7 +18,7 @@ def add_points_earns(id):
...
@@ -17,7 +18,7 @@ def add_points_earns(id):
try
:
try
:
# points 1-10
# points 1-10
# points = 4000
# points = 4000
earns
=
2
000
earns
=
8
000
# points calculation algorithm
# points calculation algorithm
if
earns
>=
5000
:
if
earns
>=
5000
:
points
=
10
points
=
10
...
...
Agri_Backend/Agripreneur_App/Routes/Leaderboard.py
View file @
1ad31777
...
@@ -4,8 +4,13 @@ from flask import Response, request
...
@@ -4,8 +4,13 @@ from flask import Response, request
# import pymongo
# import pymongo
import
json
import
json
from
bson.objectid
import
ObjectId
from
bson.objectid
import
ObjectId
import
Agripreneur_App.Auth.Token
from
Agripreneur_App.Auth.Token
import
check_for_token
from
bson.json_util
import
dumps
# Python3 code to convert a tuple
# into a string using reduce() function
# import functools
# import operator
...
@@ -14,8 +19,12 @@ import redis
...
@@ -14,8 +19,12 @@ import redis
redisClient
=
redis
.
Redis
(
host
=
'localhost'
,
port
=
6379
,
db
=
0
)
redisClient
=
redis
.
Redis
(
host
=
'localhost'
,
port
=
6379
,
db
=
0
)
print
(
redisClient
)
print
(
redisClient
)
# def convertTuple(tup):
# str = functools.reduce(operator.add, (tup))
# return str
@
app
.
route
(
"/getDetails"
,
methods
=
[
"POST"
])
@
app
.
route
(
"/getDetails"
,
methods
=
[
"POST"
])
#
@check_for_token
@
check_for_token
def
get_point_redis
():
def
get_point_redis
():
earn_gain
=
"Earn_gained"
earn_gain
=
"Earn_gained"
...
@@ -39,15 +48,17 @@ def get_point_redis():
...
@@ -39,15 +48,17 @@ def get_point_redis():
print
(
response
)
print
(
response
)
my_json
=
response
.
decode
(
"utf-8"
)
# my_json = response.decode('utf-8'
)
print
(
my_json
)
# print(my_json)
# stringOBJ = convertTuple(response)
# print(stringOBJ)
data
=
json
.
loads
(
my_json
)
#
data = json.loads(my_json)
return
Response
(
return
Response
(
response
=
json
.
dumps
({
"message"
:
data
}),
response
=
json
.
dumps
({
"message"
:
json
.
loads
(
dumps
(
response
))
}),
status
=
200
,
status
=
200
,
)
)
...
...
Agri_Backend/Agripreneur_App/Routes/PricePage.py
View file @
1ad31777
...
@@ -4,21 +4,24 @@ from flask import Response, request
...
@@ -4,21 +4,24 @@ from flask import Response, request
# import pymongo
# import pymongo
import
json
import
json
from
bson.objectid
import
ObjectId
from
bson.objectid
import
ObjectId
import
Agripreneur_App.Auth.Token
from
Agripreneur_App.Auth.Token
import
check_for_token
from
bson.json_util
import
dumps
# from json import stringify
@
app
.
route
(
"/discount/<id>"
,
methods
=
[
"GET"
])
@
app
.
route
(
"/discount/<id>"
,
methods
=
[
"GET"
])
#
@check_for_token
@
check_for_token
def
calculate_discount
(
id
):
def
calculate_discount
(
id
):
# should have payload wi9th the user detaisl and it is send to FE
# should have payload wi9th the user detaisl and it is send to FE
user_earns
=
db
.
CropData
.
find_one
({
"_id"
:
ObjectId
(
id
)})
user_earns
=
db
.
CropData
.
find_one
({
"_id"
:
ObjectId
(
id
)})
print
(
user_earns
)
#
print(user_earns)
user_points
=
user_earns
[
'points'
]
user_points
=
user_earns
[
'points'
]
print
(
user_points
)
#
print(user_points)
if
user_points
==
1
:
if
user_points
==
1
:
discount
=
1
discount
=
1
...
@@ -41,11 +44,15 @@ def calculate_discount(id):
...
@@ -41,11 +44,15 @@ def calculate_discount(id):
elif
user_points
==
10
:
elif
user_points
==
10
:
discount
=
10
discount
=
10
payload
=
user_earns
[
"userID"
]
print
(
payload
)
# abc = json.stringify(payload)
# print(abc)
# TypeError: exceptions must derive from BaseException
return
Response
(
return
Response
(
response
=
json
.
dumps
({
"Discount percentage"
:
discount
,
"payload"
:
payload
}),
response
=
json
.
dumps
({
"Discount percentage"
:
discount
,
"payload"
:
json
.
loads
(
dumps
(
payload
))
}),
status
=
200
,
status
=
200
,
)
)
\ No newline at end of file
Agri_Backend/Agripreneur_App/Routes/User.py
View file @
1ad31777
...
@@ -10,7 +10,7 @@ from flask import Response, request
...
@@ -10,7 +10,7 @@ from flask import Response, request
import
json
import
json
from
bson.objectid
import
ObjectId
from
bson.objectid
import
ObjectId
import
Agripreneur_App.Auth.Token
import
Agripreneur_App.Auth.Token
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
...
@@ -21,9 +21,14 @@ import Agripreneur_App.Auth.Token
...
@@ -21,9 +21,14 @@ import Agripreneur_App.Auth.Token
@
app
.
route
(
"/users"
,
methods
=
[
"POST"
])
@
app
.
route
(
"/users"
,
methods
=
[
"POST"
])
def
create_user
():
def
create_user
():
try
:
try
:
password
=
request
.
form
[
"password"
]
hashed_value
=
generate_password_hash
(
password
,
method
=
'sha256'
)
user
=
{
"name"
:
request
.
form
[
"name"
],
user
=
{
"name"
:
request
.
form
[
"name"
],
"email"
:
request
.
form
[
"email"
],
"email"
:
request
.
form
[
"email"
],
"password"
:
request
.
form
[
"password"
]
,
"password"
:
hashed_value
,
"district"
:
request
.
form
[
"district"
]}
"district"
:
request
.
form
[
"district"
]}
dbResponse
=
db
.
users
.
insert_one
(
user
)
dbResponse
=
db
.
users
.
insert_one
(
user
)
print
(
dbResponse
.
inserted_id
)
print
(
dbResponse
.
inserted_id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment