Spaces:
Sleeping
Sleeping
| import sqlite3 | |
| from datetime import date | |
| def get_connection(): | |
| conn = sqlite3.connect("fitplan.db", check_same_thread=False) | |
| return conn | |
| def create_tables(): | |
| conn = get_connection() | |
| cur = conn.cursor() | |
| cur.execute(""" | |
| CREATE TABLE IF NOT EXISTS users( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| email TEXT UNIQUE, | |
| password TEXT, | |
| otp TEXT | |
| ) | |
| """) | |
| conn.commit() | |
| conn.close() | |
| # Register user | |
| def register_user(email, password): | |
| conn = get_connection() | |
| cur = conn.cursor() | |
| try: | |
| cur.execute( | |
| "INSERT INTO users(email,password) VALUES (?,?)", | |
| (email, password) | |
| ) | |
| conn.commit() | |
| return True | |
| except: | |
| return False | |
| finally: | |
| conn.close() | |
| # Save OTP | |
| def save_otp(email, otp): | |
| conn = get_connection() | |
| cur = conn.cursor() | |
| cur.execute( | |
| "UPDATE users SET otp=? WHERE email=?", | |
| (otp, email) | |
| ) | |
| conn.commit() | |
| conn.close() | |
| # Verify OTP | |
| def verify_otp(email, otp): | |
| conn = get_connection() | |
| cur = conn.cursor() | |
| cur.execute( | |
| "SELECT * FROM users WHERE email=? AND otp=?", | |
| (email, otp) | |
| ) | |
| user = cur.fetchone() | |
| conn.close() | |
| return user |