forked from pasqualedetrino/easyFind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
167 lines (134 loc) · 4.92 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from flask import Flask , render_template, redirect
import insertDB
import os
from flask import Flask
from flask_hashing import Hashing
from flask import Flask,request,session
from flask_login import LoginManager, login_user, logout_user, login_required, UserMixin, current_user
from werkzeug import secure_filename
app = Flask(__name__)
app.config['HASHING_METHOD'] = 'sha384'
hashing = Hashing(app)
hashing.init_app(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = ''
app.config['SECRET_KEY'] = "lkkajdghdadkglajkgah"
app.config [ 'UPLOAD_FOLDER'] = 'static/prodotti'
@login_manager.user_loader
def load_user(user_id):
return User(user_id)
class User(UserMixin):
def __init__(self,id):
self.id = id
def get_name(self):
return self.id
if __name__ == '__main__':
app.run()
@app.route('/')
def main():
return render_template('index.html', error = {'value' : 'false'})
@app.route('/signUp', methods=('GET', 'POST'))
def signUp():
if request.method == 'POST':
name = request.form.get('nome')
password = request.form.get('password')
citta = request.form.get('citta')
indirizzo = request.form.get('indirizzo')
lat = float(request.form.get('lat'))
long = float(request.form.get('long'))
return (insertDB.insert(name, password, citta, indirizzo, lat, long))
@app.route('/signIn', methods=('GET', 'POST'))
def signIn():
if request.method == 'POST':
name = request.form.get('form-username')
password = request.form.get ('form-password')
return (insertDB.access(name, password))
@app.route('/Home_page')
@login_required
def Home_page():
username = current_user.get_name()
return insertDB.home(username, None, "unsuccessful")
@app.route('/insertOgg', methods=('GET', 'POST'))
@login_required
def insertOgg():
if request.method == 'POST':
nomeProdotto = request.form.get('articolo')
quantita = request.form.get('quantita')
prezzo = request.form.get('prezzo')
nome = current_user.get_name()
return (insertDB.insertOggetto(nomeProdotto, quantita, prezzo, nome) )
@app.route('/myOgg', methods=('GET', 'POST') )
@login_required
def myOgg():
if request.method == 'POST':
mioIdOgg = request.form.get('mioId_ogg')
mioArticolo = request.form.get('mioArticolo')
miaQuantita = request.form.get('miaQuantita')
print('mioIdOgg ' + mioIdOgg)
print('mioArticolo ' + mioArticolo)
print('miaQuantita ' + miaQuantita)
return (insertDB.modificaOggetto(mioIdOgg, mioArticolo, miaQuantita) )
@app.route('/setCategoria', methods=('GET', 'POST'))
@login_required
def get_post_javascript_data():
jsdata = request.form['cat']
print('jsondata ' + jsdata)
username = current_user.get_name()
return insertDB.home(username, jsdata, "unsuccessful")
# ---------------------------------------------------------------------------------------------------
from flask_restplus import Api, Resource
import ApiUser
api = Api()
api.init_app(app)
@api.route('/api/prodottoCitta/<citta>/<nomeProdotto>')
class prodottoCitta(Resource):
def get(self, citta, nomeProdotto):
return ApiUser.ProdottoComune(citta, nomeProdotto)
@api.route('/api/prodottoCoordinate/<nomeProdotto>/<lat>/<long>/<raggio>')
class prodottoCoordinate(Resource):
def get(self, nomeProdotto, lat, long, raggio):
return ApiUser.ProdottoComunePosizione(nomeProdotto, lat, long, raggio)
@api.route('/api/prodottoCoordinatePrezzo/<nomeProdotto>/<lat>/<long>/<raggio>')
class prodottoCoordinate(Resource):
def get(self, nomeProdotto, lat, long, raggio):
return ApiUser.ProdottoComunePosizionePrezzo(nomeProdotto, lat, long, raggio)
@api.route('/api/categorie')
class categorie(Resource):
def get(self):
return ApiUser.CategoriePresenti()
@api.route('/api/prodotticategoria/<categoria>')
class prodotticategoria(Resource):
def get(self, categoria):
return ApiUser.ProdottiCategoria(categoria)
@app.route('/logout')
@login_required
def logout():
logout_user()
return redirect('/indexOut')
@app.route('/indexOut')
def indexOut():
return render_template('index.html', error = {'value' : 'disconnect'})
@app.route('/uploader', methods=('GET', 'POST'))
@login_required
def upload_file():
print("ook");
if request.method == 'POST':
f = request.files['file']
categoria= request.form.get('categoria')
nome_prod = request.form.get('nome_prodotto')
boolRis = insertDB.insert_prod(categoria,nome_prod,f)
if boolRis == True:
return redirect('HomePage')
else:
return redirect('Home-Page')
@app.route('/HomePage')
@login_required
def HomePage():
username = current_user.get_name()
return insertDB.home(username, None, "success")
@app.route('/Home-Page')
@login_required
def HomePag():
username = current_user.get_name()
return insertDB.home(username, None, "ridondante")