commit
18a339e6b2
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
from website import create_app
|
||||
|
||||
|
||||
app = create_app()
|
||||
|
||||
if __name__ == '__name__' :
|
||||
app.run(debug=True)
|
@ -0,0 +1,44 @@
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
def info():
|
||||
print("Info Argument: Name_Picture Name_User")
|
||||
|
||||
def calculUser(cur):
|
||||
id_free = 1
|
||||
|
||||
while True :
|
||||
cur.execute('SELECT id FROM Data_Picture WHERE id == ?',(str(id_free)))
|
||||
tmp = cur.fetchall()
|
||||
|
||||
if len(tmp) == 0 :
|
||||
break
|
||||
id_free+=1
|
||||
|
||||
return id_free
|
||||
|
||||
arg = sys.argv
|
||||
|
||||
if len(arg) != 3 :
|
||||
info()
|
||||
exit(1)
|
||||
|
||||
try :
|
||||
conn = sqlite3.connect('instance/database.db')
|
||||
cur = conn.cursor()
|
||||
print("Connection : OK")
|
||||
|
||||
id_free = calculUser(cur)
|
||||
|
||||
nom_picture = arg[1]
|
||||
user = arg[2]
|
||||
|
||||
cur.execute('INSERT INTO Data_Picture(id,data,user_id) VALUES(?,?,?)',(id_free,nom_picture,user))
|
||||
conn.commit()
|
||||
print("Picture add")
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
except sqlite3.Error as error :
|
||||
print(error)
|
||||
|
@ -0,0 +1,53 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from os import path
|
||||
from flask_login import LoginManager, login_manager
|
||||
|
||||
db = SQLAlchemy()
|
||||
DB_NAME = "database.db"
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__,static_url_path='/static')
|
||||
app.config['SECRET_KEY'] = 'toto'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
|
||||
db.init_app(app)
|
||||
|
||||
from .views import views
|
||||
#import les routes de views
|
||||
|
||||
from .auth import auth
|
||||
#import les routes de auth
|
||||
|
||||
app.register_blueprint(views,url_prefix='/')
|
||||
app.register_blueprint(auth,url_prefix='/')
|
||||
#Préfixes pour accéder à ces routes
|
||||
|
||||
from .models import User,DataPicture
|
||||
create_database(app)
|
||||
|
||||
#redirect on the page login if not loggin
|
||||
login_manager = LoginManager()
|
||||
login_manager.login_view = 'auth.login'
|
||||
#what app we use
|
||||
login_manager.init_app(app)
|
||||
|
||||
#how we load a User ( model User and the primary key id)
|
||||
@login_manager.user_loader
|
||||
def load_user(id):
|
||||
return User.query.get(int(id))
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
def create_database(app):
|
||||
if not path.exists('website/' + DB_NAME):
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
print('Created Database!')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,73 @@
|
||||
from flask import Blueprint,render_template,request,flash, redirect ,url_for
|
||||
from .models import User
|
||||
from werkzeug.security import generate_password_hash,check_password_hash
|
||||
from . import db
|
||||
from flask_login import login_user,login_required,logout_user,current_user
|
||||
|
||||
auth = Blueprint('auth',__name__)
|
||||
|
||||
|
||||
@auth.route('/login',methods=['GET','POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
email = request.form.get('email')
|
||||
password = request.form.get('password')
|
||||
|
||||
user = User.query.filter_by(email=email).first()
|
||||
if user:
|
||||
if check_password_hash(user.password,password):
|
||||
#logged
|
||||
print("logged")
|
||||
login_user(user,remember=True)
|
||||
return redirect(url_for('views.home'))
|
||||
else :
|
||||
#Password wrong
|
||||
print("Password wrong")
|
||||
pass
|
||||
else :
|
||||
#Not find user
|
||||
print("User don't exist")
|
||||
|
||||
return render_template("login.html")
|
||||
|
||||
@auth.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
@auth.route('/sign-up',methods=['GET','POST'])
|
||||
def sign_up():
|
||||
if request.method == 'POST' :
|
||||
email = request.form.get('email')
|
||||
firstName = request.form.get('firstName')
|
||||
password = request.form.get('password')
|
||||
password2 = request.form.get('password2')
|
||||
|
||||
#Check if exist user
|
||||
user = User.query.filter_by(email=email).first()
|
||||
if user :
|
||||
print("User already exist")
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
elif len(email) < 4 :
|
||||
print("test")
|
||||
pass
|
||||
elif len(firstName) < 2 :
|
||||
pass
|
||||
elif password != password2 :
|
||||
return "Wrong"
|
||||
elif len(password) < 7 :
|
||||
return "Wrong"
|
||||
else :
|
||||
new_user = User(email=email,firstName=firstName,password=generate_password_hash(password,method='sha256'),config_pi="rien")
|
||||
db.session.add(new_user)
|
||||
db.session.commit()
|
||||
login_user(user,remember=True)
|
||||
return redirect(url_for('auth.login'))
|
||||
else :
|
||||
return render_template("sign-up.html")
|
||||
|
||||
|
||||
|
||||
# Utiliser flash pour envoyer des petits message (error ou sucess)!!
|
@ -0,0 +1 @@
|
||||
TEST CONGIF
|
@ -0,0 +1,29 @@
|
||||
from enum import unique
|
||||
from . import db
|
||||
#Import db from init.py
|
||||
from flask_login import UserMixin
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
class DataPicture(db.Model):
|
||||
id = db.Column(db.Integer,primary_key=True)
|
||||
data = db.Column(db.String(100))
|
||||
date = db.Column(db.DateTime(timezone=True),default=func.now())
|
||||
|
||||
#Foreign Key of User
|
||||
user_id = db.Column(db.Integer,db.ForeignKey('user.id'))
|
||||
|
||||
|
||||
class User(db.Model,UserMixin):
|
||||
|
||||
id = db.Column(db.Integer,primary_key=True)
|
||||
email = db.Column(db.String(100),unique=True)
|
||||
password = db.Column(db.String(100))
|
||||
firstName = db.Column(db.String(100))
|
||||
|
||||
config_pi = db.Column(db.String(100))
|
||||
|
||||
#lien au niveau de html voir home.html
|
||||
pictures = db.relationship('DataPicture')
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 469 KiB |
After Width: | Height: | Size: 6.7 KiB |
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Page Home :
|
||||
</h1>
|
||||
|
||||
<h1><a href="/login">Login</a></h1>
|
||||
<h1><a href="/sign-up">Sign-up</a></h1>
|
||||
<h1><a href="/logout">Logout</a></h1>
|
||||
<h1><a href="/">Home</a></h1>
|
||||
<h1 >
|
||||
User info :
|
||||
</h1>
|
||||
{% if user.is_authenticated %}
|
||||
<p>TEST TOTO</p>
|
||||
{% endif %}
|
||||
<h1>Test data</h1>
|
||||
{% for var in user.pictures %}
|
||||
|
||||
<img src="/static/picture/{{var.data}}" />
|
||||
<p>{{var.data}}</p>
|
||||
{% endfor %}
|
||||
<form method="post">
|
||||
<textarea name="data" id="data"></textarea>
|
||||
<br />
|
||||
<button type="submit">Envoyer data</button>
|
||||
</form>
|
||||
<h1><a href="/delete_all_picture">delete_all_picture</a></h1>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Page Sign-up :
|
||||
</h1>
|
||||
|
||||
<h1><a href="/login">Login</a></h1>
|
||||
<h1><a href="/sign-up">Sign-up</a></h1>
|
||||
<h1><a href="/logout">Logout</a></h1>
|
||||
<h1><a href="/">Home</a></h1>
|
||||
|
||||
|
||||
|
||||
<form method="POST">
|
||||
<h3 align="center">Login</h3>
|
||||
<div>
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" name="email" placeholder="Enter Email"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="password">password</label>
|
||||
<input type="password" id="password" name="password" placeholder="Enter password"/>
|
||||
</div>
|
||||
<br />
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Page Logout :
|
||||
</h1>
|
||||
|
||||
<h1><a href="/login">Login</a></h1>
|
||||
<h1><a href="/sign-up">Sign-up</a></h1>
|
||||
<h1><a href="/logout">Logout</a></h1>
|
||||
<h1><a href="/">Home</a></h1>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Page Sign-up :
|
||||
</h1>
|
||||
|
||||
<h1><a href="/login">Login</a></h1>
|
||||
<h1><a href="/sign-up">Sign-up</a></h1>
|
||||
<h1><a href="/logout">Logout</a></h1>
|
||||
<h1><a href="/">Home</a></h1>
|
||||
|
||||
|
||||
|
||||
<form method="POST">
|
||||
<h3 align="center">Sign-up</h3>
|
||||
<div>
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" name="email" placeholder="Enter Email"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="firstName">First name</label>
|
||||
<input type="firstName" id="firstName" name="firstName" placeholder="Enter firstName"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="password">password</label>
|
||||
<input type="password" id="password" name="password" placeholder="Enter password"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="password2">password2</label>
|
||||
<input type="password2" id="password2" name="password2" placeholder="Enter password2"/>
|
||||
</div>
|
||||
<br />
|
||||
<button type="submit">submit</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,50 @@
|
||||
from crypt import methods
|
||||
from flask import Blueprint, render_template,request,redirect ,url_for
|
||||
import flask
|
||||
from flask_login import login_required,current_user
|
||||
from requests import session
|
||||
from .models import DataPicture
|
||||
from . import db
|
||||
|
||||
|
||||
views = Blueprint('views',__name__)
|
||||
|
||||
|
||||
@views.route('/',methods=['GET','POST'])
|
||||
@login_required
|
||||
def home():
|
||||
if request.method == 'POST':
|
||||
var = request.form.get('data')
|
||||
|
||||
if len(var) < 1 :
|
||||
pass
|
||||
else :
|
||||
new_data = DataPicture(data=var,user_id=current_user.id)
|
||||
db.session.add(new_data)
|
||||
db.session.commit()
|
||||
print("data add")
|
||||
|
||||
return render_template("home.html",user=current_user)
|
||||
|
||||
|
||||
@views.route('/delete_all_picture')
|
||||
@login_required
|
||||
def delete_all_picture():
|
||||
var = 1
|
||||
data = DataPicture.query.get(var)
|
||||
|
||||
while data :
|
||||
db.session.delete(data)
|
||||
var+=1
|
||||
data = DataPicture.query.get(var)
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('views.home'))
|
||||
|
||||
|
||||
@views.route('/api/config',methods=['GET'])
|
||||
@login_required
|
||||
def api():
|
||||
file = current_user.config_pi
|
||||
file ="test.txt"
|
||||
return flask.send_file("config/"+file)
|
Loading…
Reference in new issue