Skip to content

Commit

Permalink
Merge pull request #10 from The-True-Hooha/dev
Browse files Browse the repository at this point in the history
base model: working
  • Loading branch information
The-True-Hooha authored Sep 23, 2024
2 parents acb843e + 87c8bfe commit 2ef22c9
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 75 deletions.
2 changes: 1 addition & 1 deletion app/controllers/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def handle_login_user(data: LoginData, request: Request, response: Response, db:
httponly=True,
secure=True,
samesite="strict",
max_age=6*60
max_age=6*60,
)
return data

Expand Down
19 changes: 18 additions & 1 deletion app/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class User(Base):
role = Column(Enum(RoleEnum), default=RoleEnum.user)
domains = relationship("Domain", back_populates="user")
createdDate = Column(DateTime, server_default=func.now())


def __str__(self):
return f"User(id={self.id}, email='{self.email}', role='{self.role}', createdDate='{self.createdDate}', domains='{self.domains[:5]}'),"

def __repr__(self):
return self.__str__()

class Domain(Base):
__tablename__ = "domain"
Expand All @@ -46,6 +51,12 @@ class Domain(Base):
user = relationship("User", back_populates="domains")
createdDate = Column(DateTime(timezone=True),
default=datetime.datetime.utcnow)

def __str__(self):
return f"Domain(id={self.id}, name='{self.domain_name}', active={self.isActive}, user_id={self.user_id}, createdDate={self.createdDate})"

def __repr__(self):
return self.__str__()


class SubDomain(Base):
Expand All @@ -57,6 +68,12 @@ class SubDomain(Base):
name = Column(String)
createdDate = Column(DateTime(timezone=True),
default=datetime.datetime.utcnow)

def __str__(self):
return f"SubDomain(id={self.id}, name='{self.name}', domain_id={self.domain_id})"

def __repr__(self):
return self.__str__()


def get_database():
Expand Down
13 changes: 8 additions & 5 deletions app/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi import Depends, HTTPException, status, Request
from fastapi.security import OAuth2PasswordBearer
from sqlalchemy.orm import Session, joinedload
from fastapi.responses import RedirectResponse


from app.core.core import app_setting
Expand Down Expand Up @@ -47,7 +48,7 @@ def login_user(db: Session, email: str, password: str):
"message": "successfully logged in",
"token": token
}


def create_access_token(data: dict, expiry: Optional[timedelta] = None):
to_encode = data.copy()
Expand All @@ -71,10 +72,12 @@ async def get_user_from_cookie(req:Request, db:Session = Depends(get_database)):
)
access_token = req.cookies.get("dom_explorer")
if not access_token:
raise credentials_exception
token = access_token.split()[1]
return get_auth_user(db=db, token=token)
pass
print(access_token)
RedirectResponse(url="/login")
else:
# raise credentials_exception
token = access_token.split()[1]
return await get_auth_user(db=db, token=token)

async def get_auth_user(token: str = Depends(oauth2_scheme), db: Session = Depends(get_database)):
credentials_exception = HTTPException(
Expand Down
159 changes: 159 additions & 0 deletions app/static/css/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
:root {
--primary-color: #008080;
--secondary-color: #2c3e50;
--background-color: #ecf0f1;
--text-color: #333;
--error-color: #e74c3c;
--success-color: #2ecc71;
--border-radius: 8px;
--box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
--transition: all 0.3s ease;
}

* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: 'Inter', sans-serif;
background-color: var(--background-color);
color: var(--text-color);
line-height: 1.6;
}

.auth-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}

.auth-content {
background-color: white;
border-radius: var(--border-radius);
box-shadow: var(--box-shadow);
width: 100%;
max-width: 400px;
padding: 2rem;
}

.auth-title {
text-align: center;
color: var(--secondary-color);
margin-bottom: 1.5rem;
font-size: 2rem;
}

.tabs {
display: flex;
justify-content: center;
margin-bottom: 1.5rem;
}

.tab {
background-color: transparent;
border: none;
color: var(--text-color);
cursor: pointer;
font-size: 1rem;
font-weight: 500;
padding: 0.5rem 1rem;
transition: var(--transition);
}

.tab.active {
color: var(--primary-color);
border-bottom: 2px solid var(--primary-color);
}

.tab-content {
display: none;
}

.tab-content.active {
display: block;
}

.form-group {
margin-bottom: 1rem;
}

.input-field {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: var(--border-radius);
font-size: 1rem;
transition: var(--transition);
}

.input-field:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.submit-button {
width: 100%;
padding: 0.75rem;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--border-radius);
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
}

.submit-button:hover {
background-color: #2980b9;
}

.form-message {
margin-top: 1rem;
text-align: center;
font-size: 0.9rem;
color: var(--error-color);
}

.form-message.error {
color: var(--error-color);
}

.form-message.success {
color: var(--success-color);
}

.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}

@media (max-width: 480px) {
.auth-content {
padding: 1.5rem;
}

.auth-title {
font-size: 1.5rem;
}

.tab {
font-size: 0.9rem;
}

.input-field, .submit-button {
font-size: 0.9rem;
}
}
46 changes: 46 additions & 0 deletions app/static/css/profile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.domain-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

.domain-table th, .domain-table td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}

.domain-table th {
background-color: #f2f2f2;
font-weight: bold;
}

.domain-table tr:nth-child(even) {
background-color: #f9f9f9;
}

.domain-table tr:hover {
background-color: #f5f5f5;
}

.view-btn, .delete-btn {
padding: 5px 10px;
margin-right: 5px;
border: none;
border-radius: 3px;
cursor: pointer;
}

.view-btn {
background-color: #4CAF50;
color: white;
}

.delete-btn {
background-color: #f44336;
color: white;
}

.view-btn:hover, .delete-btn:hover {
opacity: 0.8;
}
31 changes: 18 additions & 13 deletions app/static/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ async function searchSubdomains(domain) {
return response.json();
}

async function login(username, password) {
const response = await fetch("/api/v1/login", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: `username=${encodeURIComponent(
username
)}&password=${encodeURIComponent(password)}`,
credentials: "include",
});
if (!response.ok) throw new Error("Failed to login");
return response.json();


async function RegisterApi(email, password) {
try {
const data = await fetch("/api/v1/signup", {
headers: AuthHeaders,
});
} catch (err) {
throw err;
}
}

function AuthHeaders() {
return {
"Content-Type": "application/json",
};
}


Loading

0 comments on commit 2ef22c9

Please sign in to comment.