Skip to content

Commit

Permalink
Merge pull request #11 from The-True-Hooha/dev
Browse files Browse the repository at this point in the history
base model v1
  • Loading branch information
The-True-Hooha authored Sep 24, 2024
2 parents 2ef22c9 + a541d96 commit bce0006
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 120 deletions.
35 changes: 18 additions & 17 deletions app/controllers/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from app.schema.schema import UserCreate, DomainResponse, Token, CreateUserResponse, LoginData, LoginResponse, PaginatedDomainsResponse, PaginatedSubDomainsResponse, SubdomainSearchResponse
from app.database.database import User, Domain, SubDomain, get_database
from app.service.search_enumerator import get_subdomain_data, get_updated_domains
from app.service.service import create_new_user, create_access_token, get_user_from_cookie, isAdmin, get_user, login_user, get_my_profile, get_user_domain_with_subdomains, get_user_domains
from app.service.service import create_new_user, create_access_token, get_user_from_cookie, isAdmin, get_user, login_user, get_my_profile, get_user_domain_with_subdomains, get_user_domains, get_auth_user

router = APIRouter()

Expand Down Expand Up @@ -44,7 +44,7 @@ def create_user(user: UserCreate, response: Response, request: Request, db: Sess
httponly=True,
secure=True,
samesite="strict",
max_age=6*60
max_age=14 * 24 * 60 * 60
)
return new_user

Expand All @@ -59,10 +59,11 @@ def handle_login_user(data: LoginData, request: Request, response: Response, db:
httponly=True,
secure=True,
samesite="strict",
max_age=6*60,
max_age=14 * 24 * 60 * 60,
)
return data


@router.get("/profile/me")
@limiter.limit("5/minute")
def my_profile(request: Request, user: User = Depends(get_user_from_cookie), db: Session = Depends(get_database)):
Expand All @@ -72,7 +73,7 @@ def my_profile(request: Request, user: User = Depends(get_user_from_cookie), db:
@router.get("/domains", response_model=PaginatedDomainsResponse)
@limiter.limit("10/minute")
async def get_user_domains(
request:Request,
request: Request,
skip: int = Query(0, ge=0),
limit: int = Query(10, ge=1, le=100),
current_user: User = Depends(get_user_from_cookie),
Expand All @@ -87,31 +88,31 @@ async def get_user_domains(
)


@router.get("/domains/{name}", response_model=PaginatedSubDomainsResponse)
@limiter.limit("10/minute")
@router.get("/domains/{id}")
@limiter.limit("15/minute")
async def read_user_domain(
request: Request,
name: str,
id: int,
skip: int = Query(0, ge=0),
limit: int = Query(10, ge=1, le=100),
current_user: User = Depends(get_user_from_cookie),
db: Session = Depends(get_database)
):
domain, total_subdomains = get_user_domain_with_subdomains(
db, current_user, name, skip, limit)
db, current_user, id, skip, limit)
if domain is None:
raise HTTPException(status_code=404, detail="Domain cannot be found")
return PaginatedSubDomainsResponse(
domain=domain,
sub_domains=domain.sub_domains,
total_subdomains=total_subdomains,
skip=skip,
limit=limit
)
return {
"domain": domain,
"sub_domains": domain.sub_domains,
"total_subdomains": total_subdomains,
"skip": skip,
"limit": limit
}


@router.get("/domain/check-updates")
@limiter.limit("5/minute")
async def get_domain_updates(request:Request, domain:str, user:User = Depends(get_user_from_cookie), db:Session = Depends(get_database)):
async def get_domain_updates(request: Request, domain: str, user: User = Depends(get_user_from_cookie), db: Session = Depends(get_database)):
data = await get_updated_domains(db=db, domain=domain, user=user)
return SubdomainSearchResponse(**data)
return SubdomainSearchResponse(**data)
2 changes: 2 additions & 0 deletions app/service/search_enumerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ async def run_all_query_async(self):

async def get_subdomain_data(domain: str, db: Session, user: User) -> Dict[str, List[str]]:
try:
print("is it coming?")
parsed_domain = urlparse(f"http://{domain}").netloc
res = SubDomainScrapper(parsed_domain)
data = await res.run_all_query_async()
Expand Down Expand Up @@ -355,6 +356,7 @@ async def get_subdomain_data(domain: str, db: Session, user: User) -> Dict[str,
"wildcards": sorted(list(res.wildcard_subdomains))
}
except Exception as e:
print(e)
raise HTTPException(
status_code=500, detail=f"An error occurred: {str(e)}")

Expand Down
4 changes: 2 additions & 2 deletions app/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ def get_user_domains(db: Session, user: User, skip: int = 0, limit: int = 10) ->
return domains, total


def get_user_domain_with_subdomains(db: Session, user: User, domain_name: str, skip: int = 0, limit: int = 10) -> Tuple[Domain, int]:
def get_user_domain_with_subdomains(db: Session, user: User, id: int, skip: int = 0, limit: int = 10) -> Tuple[Domain, int]:
domain:Domain = db.query(Domain).filter(
Domain.domain_name == domain_name,
Domain.id == id,
Domain.user_id == user.id
).first()

Expand Down
70 changes: 65 additions & 5 deletions app/static/css/profile.css
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
.domain-table {
.domain-table, .subdomain-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

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

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

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

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

Expand All @@ -43,4 +46,61 @@

.view-btn:hover, .delete-btn:hover {
opacity: 0.8;
}

#pagination {
margin-top: 20px;
text-align: center;
}

#pagination button, #pagination span {
margin: 0 5px;
padding: 5px 10px;
border: 1px solid #ddd;
background-color: #f8f8f8;
cursor: pointer;
}

#pagination span {
background-color: #4CAF50;
color: white;
border-color: #4CAF50;
}

#pagination button:hover {
background-color: #ddd;
}

.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}

.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}

.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
91 changes: 77 additions & 14 deletions app/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,6 @@ nav ul li a {
margin-bottom: 1rem;
}

.results {
padding: 4rem 0;
}

.results h3 {
text-align: center;
font-size: 2rem;
margin-bottom: 2rem;
}

#subdomainList {
list-style: none;
display: grid;
Expand All @@ -179,10 +169,6 @@ footer {
margin-top: auto;
}

.hidden {
display: none;
}

@media (max-width: 768px) {
header .container {
flex-direction: column;
Expand All @@ -200,3 +186,80 @@ footer {
width: 100%;
}
}
.results {
padding: 4rem 0;
}

.results h3 {
text-align: center;
font-size: 2rem;
margin-bottom: 2rem;
}

#resultsContent {
background-color: #fff;
padding: 2rem;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#resultsContent p {
font-size: 1.2rem;
margin-bottom: 1rem;
}

#resultsContent h4 {
color: var(--primary-color);
margin-top: 1.5rem;
margin-bottom: 1rem;
}

#resultsContent ul {
list-style: none;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}

#resultsContent li {
background-color: var(--secondary-color);
padding: 0.5rem 1rem;
border-radius: 5px;
}

.hidden {
display: none;
}

.loader {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 2rem 0;
}

.spinner {
border: 4px solid var(--secondary-color);
border-top: 4px solid var(--primary-color);
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

.loader p {
margin-top: 1rem;
font-size: 1.2rem;
color: var(--primary-color);
}

/* Ensure hidden class actually hides the element */
.hidden {
display: none !important;
}
Loading

0 comments on commit bce0006

Please sign in to comment.