Commit b2915503 authored by sheng's avatar sheng

store pincode into sqlite

parent b894a17c
......@@ -3,7 +3,7 @@ import json
import os
import requests
import subprocess
import sqlite3
import simple_sql
from wifi_utils import *
from flask_bootstrap import Bootstrap
......@@ -17,6 +17,10 @@ recent_dir = os.path.abspath(os.path.dirname(__file__))
wifi_list = []
def is_encrypted(cell):
if(cell.security == '--'):
return False
......@@ -91,8 +95,25 @@ def pin_setup():
return render_template('pincode.html')
@app.route('/pincode_storage',methods=['POST'])
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")
if __name__ == '__main__':
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 @@
{% block head %}
{{super()}}
<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 href="../static/css/style.css" rel="stylesheet">
<link rel="stylesheet" href="{{url_for('static',filename='css/main.css')}}">
{% endblock %}
{% block content %}
<body >
<div class="col" >
<button type="submit" >Pincode Setup</button>
<div class="col-2" >
<button type="submit" class="btn btn-primary">Pincode Setup</button>
</div>
<div >
<button type="submit">Preference</button>
<div class="col-2">
<button type="submit" class="btn btn-primary">Preference</button>
</div>
{% block footer %}
......
......@@ -57,10 +57,11 @@
if( pin_code.length == 6 ){
console.log(pin_code);
pin = pin_code.join('');
data="pin="+pin
$.ajax({
type:"POST",
url:"http://localhost:8080/pincode_storage",
data:pin,
data:data,
success:function(data, status){
alert("PIN CODE SETUP SUCCESS");
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