-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d92b2c
commit b556611
Showing
27 changed files
with
1,465 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
-- Create the 'users' table | ||
CREATE TABLE users ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
email VARCHAR(120) NOT NULL UNIQUE, | ||
password VARCHAR(255) NOT NULL, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL, | ||
profile_pic VARCHAR(255) DEFAULT 'default.jpg', | ||
is_verified BOOLEAN DEFAULT FALSE, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
-- Create the 'categories' table for managing item categories separately | ||
CREATE TABLE categories ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(50) UNIQUE NOT NULL | ||
); | ||
|
||
-- Create the 'items' table with category_id column and foreign key constraint | ||
CREATE TABLE items ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(100) NOT NULL, | ||
description TEXT NOT NULL, | ||
category_id INT, | ||
image_file VARCHAR(255) DEFAULT 'default.jpg', | ||
status ENUM('lost', 'found') NOT NULL, | ||
date DATE NOT NULL, | ||
user_id INT NOT NULL, | ||
claimed BOOLEAN DEFAULT FALSE, | ||
FOREIGN KEY (category_id) REFERENCES categories(id), | ||
FOREIGN KEY (user_id) REFERENCES users(id) | ||
); | ||
|
||
-- Create the 'password_reset_tokens' table with correct column type | ||
CREATE TABLE password_reset_tokens ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
user_id INT NOT NULL, | ||
otp VARCHAR(6) NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
expires_at DATETIME NOT NULL, | ||
FOREIGN KEY (user_id) REFERENCES users(id) | ||
); | ||
|
||
-- Create the 'notifications' table with foreign key constraints | ||
CREATE TABLE notifications ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
user_id INT NOT NULL, | ||
item_id INT NOT NULL, | ||
message VARCHAR(255) NOT NULL, | ||
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
FOREIGN KEY (user_id) REFERENCES users(id), | ||
FOREIGN KEY (item_id) REFERENCES items(id) | ||
); | ||
|
||
-- Optional: Create the 'claimed_items' table to track claimed items | ||
CREATE TABLE claimed_items ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
item_id INT NOT NULL, | ||
claimer_id INT NOT NULL, | ||
claimed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
FOREIGN KEY (item_id) REFERENCES items(id), | ||
FOREIGN KEY (claimer_id) REFERENCES users(id) | ||
); | ||
|
||
ALTER TABLE users | ||
ADD COLUMN roll_number VARCHAR(20) NOT NULL, | ||
ADD COLUMN batch INT NOT NULL, | ||
ADD COLUMN course ENUM('Btech', 'Barch', 'Mtech', 'Msc', 'PHD') NOT NULL, | ||
ADD COLUMN branch ENUM('CSE', 'ECE', 'EEE', 'ICE', 'Chem', 'Civil', 'MECH', 'Prod', 'Other') NOT NULL; | ||
|
||
-- Add this to ensure foreign key constraints are correctly set up | ||
ALTER TABLE items | ||
ADD FOREIGN KEY (user_id) REFERENCES users(id); | ||
|
||
ALTER TABLE items | ||
ADD FOREIGN KEY (category_id) REFERENCES categories(id); | ||
|
||
ALTER TABLE password_reset_tokens | ||
ADD FOREIGN KEY (user_id) REFERENCES users(id); | ||
|
||
ALTER TABLE notifications | ||
ADD FOREIGN KEY (user_id) REFERENCES users(id), | ||
ADD FOREIGN KEY (item_id) REFERENCES items(id); | ||
|
||
ALTER TABLE claimed_items | ||
ADD FOREIGN KEY (item_id) REFERENCES items(id), | ||
ADD FOREIGN KEY (claimer_id) REFERENCES users(id); | ||
|
||
-- Update Enum to match the code | ||
ALTER TABLE items MODIFY status ENUM('lost', 'found') NOT NULL; | ||
ALTER TABLE items MODIFY status ENUM('lost', 'found') NOT NULL; | ||
|
||
-- Add the 'location' column to the 'items' table | ||
ALTER TABLE items | ||
ADD COLUMN location VARCHAR(255); | ||
|
||
|
||
-- Update 'course' Enum in the 'users' table | ||
ALTER TABLE users MODIFY COLUMN course ENUM('BTECH', 'BARCH', 'MTECH', 'MSC', 'PHD') NOT NULL; | ||
|
||
-- Update 'branch' Enum in the 'users' table | ||
ALTER TABLE users MODIFY COLUMN branch ENUM('CSE', 'ECE', 'EEE', 'ICE', 'CHEM', 'CIVIL', 'MECH', 'PROD', 'OTHER') NOT NULL; | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
from datetime import datetime | ||
from enum import Enum | ||
from flask_bcrypt import Bcrypt | ||
from itsdangerous import URLSafeTimedSerializer as Serializer, SignatureExpired | ||
from flask import current_app | ||
from flask_login import UserMixin | ||
|
||
db = SQLAlchemy() | ||
bcrypt = Bcrypt() | ||
|
||
# Enums for various fields | ||
|
||
class ItemStatusEnum(Enum): | ||
LOST = 'lost' | ||
FOUND = 'found' | ||
|
||
class CourseEnum(Enum): | ||
BTECH = 'Btech' | ||
BARCH = 'Barch' | ||
MTECH = 'Mtech' | ||
MSC = 'Msc' | ||
PHD = 'PHD' | ||
|
||
class BranchEnum(Enum): | ||
CSE = 'CSE' | ||
ECE = 'ECE' | ||
EEE = 'EEE' | ||
ICE = 'ICE' | ||
CHEM = 'Chem' | ||
CIVIL = 'Civil' | ||
MECH = 'MECH' | ||
PROD = 'Prod' | ||
OTHER = 'Other' | ||
|
||
|
||
class User(db.Model, UserMixin): | ||
__tablename__ = 'users' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
email = db.Column(db.String(120), unique=True, nullable=False) | ||
password = db.Column(db.String(255), nullable=False) | ||
first_name = db.Column(db.String(50), nullable=False) | ||
last_name = db.Column(db.String(50), nullable=False) | ||
profile_pic = db.Column(db.String(255), default='default.jpg') | ||
is_verified = db.Column(db.Boolean, default=False) | ||
created_at = db.Column(db.DateTime, default=datetime.utcnow) | ||
roll_number = db.Column(db.String(20), nullable=False) | ||
batch = db.Column(db.Integer, nullable=False) | ||
course = db.Column(db.Enum(CourseEnum), nullable=False) | ||
branch = db.Column(db.Enum(BranchEnum), nullable=False) | ||
|
||
items = db.relationship('Item', backref='owner', lazy=True) | ||
password_reset_tokens = db.relationship('PasswordResetToken', backref='user', lazy=True) | ||
notifications = db.relationship('Notification', backref='user', lazy=True) | ||
claimed_items = db.relationship('ClaimedItem', backref='claimer', lazy=True) | ||
|
||
def set_password(self, password): | ||
self.password = bcrypt.generate_password_hash(password).decode('utf-8') | ||
|
||
def check_password(self, password): | ||
return bcrypt.check_password_hash(self.password, password) | ||
|
||
def get_reset_token(self, expires_sec=1800): | ||
s = Serializer(current_app.config['SECRET_KEY']) | ||
return s.dumps({'user_id': self.id}, salt=current_app.config['SECURITY_PASSWORD_SALT']) | ||
|
||
@staticmethod | ||
def verify_reset_token(token): | ||
s = Serializer(current_app.config['SECRET_KEY']) | ||
try: | ||
data = s.loads(token, salt=current_app.config['SECURITY_PASSWORD_SALT'], max_age=1800) | ||
except (SignatureExpired, ValueError): | ||
return None | ||
return User.query.get(data['user_id']) | ||
|
||
def __repr__(self): | ||
return f"User('{self.email}', '{self.first_name}', '{self.last_name}')" | ||
|
||
class Category(db.Model): | ||
__tablename__ = 'categories' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(50), unique=True, nullable=False) | ||
|
||
items = db.relationship('Item', backref='category', lazy=True) | ||
|
||
def __repr__(self): | ||
return f"Category('{self.name}')" | ||
|
||
|
||
class Item(db.Model): | ||
__tablename__ = 'items' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(100), nullable=False) | ||
description = db.Column(db.Text, nullable=False) | ||
category_id = db.Column(db.Integer, db.ForeignKey('categories.id')) | ||
image_file = db.Column(db.String(255), default='default.jpg') | ||
status = db.Column(db.Enum('lost', 'found'), nullable=False) # Updated Enum | ||
date = db.Column(db.Date, nullable=False) | ||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
claimed = db.Column(db.Boolean, default=False) | ||
location = db.Column(db.String(255)) # Add this line to include the location field | ||
|
||
def __repr__(self): | ||
return f"Item('{self.name}', '{self.status}', '{self.date}')" | ||
|
||
|
||
|
||
class PasswordResetToken(db.Model): | ||
__tablename__ = 'password_reset_tokens' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
otp = db.Column(db.String(6), nullable=False) | ||
created_at = db.Column(db.DateTime, default=datetime.utcnow) | ||
expires_at = db.Column(db.DateTime, nullable=False) | ||
|
||
def __repr__(self): | ||
return f"PasswordResetToken('{self.user_id}', '{self.otp}')" | ||
|
||
class Notification(db.Model): | ||
__tablename__ = 'notifications' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
item_id = db.Column(db.Integer, db.ForeignKey('items.id'), nullable=False) | ||
message = db.Column(db.String(255), nullable=False) | ||
sent_at = db.Column(db.DateTime, default=datetime.utcnow) | ||
|
||
def __repr__(self): | ||
return f"Notification('{self.user_id}', '{self.item_id}', '{self.message}')" | ||
|
||
class ClaimedItem(db.Model): | ||
__tablename__ = 'claimed_items' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
item_id = db.Column(db.Integer, db.ForeignKey('items.id'), nullable=False) | ||
claimer_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
claimed_at = db.Column(db.DateTime, default=datetime.utcnow) | ||
|
||
def __repr__(self): | ||
return f"ClaimedItem('{self.item_id}', '{self.claimer_id}')" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
nav { | ||
background-color: #333; | ||
} | ||
|
||
nav ul { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 60px; | ||
} | ||
|
||
nav ul li { | ||
margin: 0 15px; | ||
} | ||
|
||
nav ul li a { | ||
color: white; | ||
text-decoration: none; | ||
font-size: 16px; | ||
padding: 10px 15px; | ||
display: block; | ||
} | ||
|
||
nav ul li a:hover, | ||
nav ul li a:focus { | ||
background-color: #575757; | ||
border-radius: 5px; | ||
} | ||
|
||
.container { | ||
max-width: 600px; | ||
margin: 50px auto; | ||
padding: 20px; | ||
background-color: white; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
h2 { | ||
text-align: center; | ||
margin-bottom: 30px; | ||
font-size: 24px; | ||
color: #333; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 5px; | ||
font-weight: bold; | ||
} | ||
|
||
input[type="text"], | ||
input[type="email"], | ||
input[type="password"] { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 20px; | ||
border: 1px solid #ddd; | ||
border-radius: 5px; | ||
box-sizing: border-box; | ||
transition: border-color 0.3s ease; | ||
} | ||
|
||
input[type="text"]:focus, | ||
input[type="email"]:focus, | ||
input[type="password"]:focus { | ||
border-color: #5cb85c; | ||
outline: none; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
padding: 15px; | ||
background-color: #5cb85c; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
transition: background-color 0.3s ease, transform 0.2s ease; | ||
} | ||
|
||
button:hover, | ||
button:focus { | ||
background-color: #4cae4c; | ||
transform: translateY(-1px); | ||
} | ||
|
||
button:active { | ||
background-color: #449d44; | ||
transform: translateY(0); | ||
} | ||
|
||
.error { | ||
color: #d9534f; | ||
font-size: 0.9em; | ||
margin-top: -10px; | ||
margin-bottom: 15px; | ||
display: block; | ||
} | ||
|
||
.container { | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
background: #fff; | ||
margin: 30px auto; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function validateEmail() { | ||
const emailField = document.getElementById('email'); | ||
const emailError = document.getElementById('emailError'); | ||
const collegeDomain = '@nitt.edu'; | ||
|
||
if (!emailField.value.endsWith(collegeDomain)) { | ||
emailError.textContent = 'Please enter a valid college email address (e.g., yourrollno@nitt.edu).'; | ||
return false; | ||
} else { | ||
emailError.textContent = ''; //enter eeror message | ||
} | ||
|
||
return validatePassword(); | ||
} | ||
|
||
function validatePassword() { | ||
const passwordField = document.getElementById('password'); | ||
const confirmPasswordField = document.getElementById('confirm_password'); | ||
const passwordError = document.getElementById('passwordError'); | ||
|
||
if (passwordField.value !== confirmPasswordField.value) { | ||
passwordError.textContent = 'Passwords do not match.'; | ||
return false; | ||
} else { | ||
passwordError.textContent = ''; // Clear any previous error message | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.