Commit b2915503 authored by sheng's avatar sheng

store pincode into sqlite

parent b894a17c
...@@ -3,7 +3,7 @@ import json ...@@ -3,7 +3,7 @@ import json
import os import os
import requests import requests
import subprocess import subprocess
import sqlite3 import simple_sql
from wifi_utils import * from wifi_utils import *
from flask_bootstrap import Bootstrap from flask_bootstrap import Bootstrap
...@@ -17,6 +17,10 @@ recent_dir = os.path.abspath(os.path.dirname(__file__)) ...@@ -17,6 +17,10 @@ recent_dir = os.path.abspath(os.path.dirname(__file__))
wifi_list = [] wifi_list = []
def is_encrypted(cell): def is_encrypted(cell):
if(cell.security == '--'): if(cell.security == '--'):
return False return False
...@@ -91,8 +95,25 @@ def pin_setup(): ...@@ -91,8 +95,25 @@ def pin_setup():
return render_template('pincode.html') return render_template('pincode.html')
@app.route('/pincode_storage',methods=['POST']) @app.route('/pincode_storage',methods=['POST'])
def pin_store(): def pin_store():
pin = request.form.get("pin")
print(pin)
if pin:
try:
simple_sql.store(pin)
simple_sql.findAllPincode()
except:
simple_sql.init()
simple_sql.store(pin)
return "OK",200
else:
return "Server Error",500
@app.route("/main_page", methods=['GET'])
def main_page():
return render_template("main_page.html") return render_template("main_page.html")
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True) app.run(host='0.0.0.0', port=8080, debug=True)
File added
import sqlite3
sql = sqlite3.connect('pincode', check_same_thread=False)
cur = sql.cursor()
def init():
global cur
global sql
cur.execute('''
CREATE TABLE PIN_TABLE
(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
PINCODE TEXT NOT NULL);
''')
sql.commit()
print("Initial DB table")
def store(pin):
global cur
global sql
cmd="INSERT INTO PIN_TABLE (PINCODE) VALUES (?)"
print(cmd)
cur.execute("INSERT INTO PIN_TABLE (PINCODE) VALUES (?)", (pin,))
sql.commit()
print("Insert into database")
return True
def findAllPincode():
global cur
global sql
cmd = "SELECT * from PIN_TABLE"
ret = cur.execute(cmd)
pins = ret.fetchall()
for i in pins:
print(i)
...@@ -2,16 +2,15 @@ ...@@ -2,16 +2,15 @@
{% block head %} {% block head %}
{{super()}} {{super()}}
<link href="http://code.jquery.com/ui/1.9.0/themes/ui-darkness/jquery-ui.css" rel="stylesheet"> <link href="http://code.jquery.com/ui/1.9.0/themes/ui-darkness/jquery-ui.css" rel="stylesheet">
<link href="../static/css/keyboard.css" rel="stylesheet"> <link rel="stylesheet" href="{{url_for('static',filename='css/main.css')}}">
<link href="../static/css/style.css" rel="stylesheet">
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<body > <body >
<div class="col" > <div class="col-2" >
<button type="submit" >Pincode Setup</button> <button type="submit" class="btn btn-primary">Pincode Setup</button>
</div> </div>
<div > <div class="col-2">
<button type="submit">Preference</button> <button type="submit" class="btn btn-primary">Preference</button>
</div> </div>
{% block footer %} {% block footer %}
......
...@@ -57,10 +57,11 @@ ...@@ -57,10 +57,11 @@
if( pin_code.length == 6 ){ if( pin_code.length == 6 ){
console.log(pin_code); console.log(pin_code);
pin = pin_code.join(''); pin = pin_code.join('');
data="pin="+pin
$.ajax({ $.ajax({
type:"POST", type:"POST",
url:"http://localhost:8080/pincode_storage", url:"http://localhost:8080/pincode_storage",
data:pin, data:data,
success:function(data, status){ success:function(data, status){
alert("PIN CODE SETUP SUCCESS"); alert("PIN CODE SETUP SUCCESS");
window.location.href="http://localhost:8080/main_page"; window.location.href="http://localhost:8080/main_page";
......
Markdown is supported
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