diff --git a/angular.json b/angular.json
index 2d38b90..8bca3fc 100644
--- a/angular.json
+++ b/angular.json
@@ -43,7 +43,7 @@
},
{
"type": "anyComponentStyle",
- "maximumWarning": "4kB",
+ "maximumWarning": "5kB",
"maximumError": "8kB"
}
],
diff --git a/src/app/admin/admin.component.css b/src/app/admin/admin.component.css
index abe8982..7b6796d 100644
--- a/src/app/admin/admin.component.css
+++ b/src/app/admin/admin.component.css
@@ -296,7 +296,7 @@ button {
background-color: #8a6bbf;
color: white;
padding: 12px 22px;
- margin: 10px;
+ margin-right: 15px;
border: none;
border-radius: 25px;
cursor: pointer;
@@ -335,7 +335,8 @@ button.toggle-button:hover:active, button.toggle-button:hover {
button.logout {
background-color: #713252;
- margin: 0 0 0 5px;
+ margin: 0;
+ padding: 12px 16px;
}
button.logout:hover {
diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html
index 81421f6..b5c1ab5 100644
--- a/src/app/admin/admin.component.html
+++ b/src/app/admin/admin.component.html
@@ -2,15 +2,16 @@
-

@if (!isNarrow) {
+
Admin Dashboard
}
+
-
+
@@ -129,7 +130,7 @@
@@ -187,3 +188,11 @@
+
+
+
+
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts
index 3a2cf68..e95c02d 100644
--- a/src/app/admin/admin.component.ts
+++ b/src/app/admin/admin.component.ts
@@ -9,6 +9,7 @@ import {ViewportService} from '../shared/services/viewport.service';
import {Title} from '@angular/platform-browser';
import {ModalComponent} from '../shared/modal/modal.component';
import {AuthService} from '../shared/services/auth.service';
+import {ShortenerComponent} from '../shared/shortener/shortener.component';
@Component({
selector: 'app-admin',
@@ -19,7 +20,8 @@ import {AuthService} from '../shared/services/auth.service';
NgStyle,
ModalComponent,
TitleCasePipe,
- RouterLink
+ RouterLink,
+ ShortenerComponent
]
})
export class AdminComponent implements OnInit, OnDestroy {
@@ -35,10 +37,12 @@ export class AdminComponent implements OnInit, OnDestroy {
content: string = '';
modalTitle: string = '';
- isModalOpen: boolean = false;
+ isUserModalOpen: boolean = false;
userMode: 'create' | 'edit' | 'delete' = 'create';
isUserDropdownOpen = false;
+ isShortenerModalOpen: boolean = false;
+
userData = {
username: '',
password: '',
@@ -72,7 +76,7 @@ export class AdminComponent implements OnInit, OnDestroy {
}
startTokenValidation() {
- this.tokenValidationInterval = interval(300000).subscribe(() => {
+ this.tokenValidationInterval = interval(60000).subscribe(() => {
this.authService.validateToken().subscribe();
});
}
@@ -209,12 +213,25 @@ export class AdminComponent implements OnInit, OnDestroy {
}
openUserModal() {
- this.isModalOpen = true;
+ this.isUserModalOpen = true;
this.modalTitle = 'Manage Users';
this.userMode = 'create';
this.isUserDropdownOpen = false;
}
+ closeModal() {
+ this.isUserModalOpen = false;
+ this.userData = {
+ username: '',
+ password: '',
+ id: '',
+ };
+ }
+
+ closeShortenerModal() {
+ this.isShortenerModalOpen = false;
+ }
+
toggleUserDropdown(): void {
this.isUserDropdownOpen = !this.isUserDropdownOpen;
}
@@ -254,15 +271,6 @@ export class AdminComponent implements OnInit, OnDestroy {
}
}
- closeModal() {
- this.isModalOpen = false;
- this.userData = {
- username: '',
- password: '',
- id: '',
- };
- }
-
createUserFromValues(username: string, password: string): void {
if (!username?.trim() || !password?.trim()) {
alert('Both username and password are required!');
@@ -387,4 +395,8 @@ export class AdminComponent implements OnInit, OnDestroy {
this.deleteArticle(articleId);
}
}
+
+ openShortenerModal() {
+ this.isShortenerModalOpen = true;
+ }
}
diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts
index eb18062..09a83dc 100644
--- a/src/app/app.routes.ts
+++ b/src/app/app.routes.ts
@@ -10,7 +10,6 @@ import {SocialsComponent} from './socials/socials.component';
// import {ServicesComponent} from './services/services.component';
// import {TosComponent} from './tos/tos.component';
import {ImprintComponent} from './imprint/imprint.component';
-import {ShortenerComponent} from './shortener/shortener.component';
import {PrivacyComponent} from './privacy/privacy.component';
import {SuccessComponent} from './checkout/success/success.component';
import {CancelComponent} from './checkout/cancel/cancel.component';
@@ -28,7 +27,6 @@ export const routes: Routes = [
{ path: 'privacy', component: PrivacyComponent },
{ path: 'imprint', component: ImprintComponent },
{ path: 'blog/:slug', component: ArticlePageComponent },
- { path: 'shortener', component: ShortenerComponent },
{ path: 'checkout/success', pathMatch: 'full', component: SuccessComponent },
{ path: 'checkout/cancel', pathMatch: 'full', component: CancelComponent },
{ path: '**', pathMatch: 'full', component: NotFoundComponent }
diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts
index 7e09521..d790308 100644
--- a/src/app/login/login.component.ts
+++ b/src/app/login/login.component.ts
@@ -1,10 +1,9 @@
-import {Component, Inject, OnInit, PLATFORM_ID} from '@angular/core';
+import {Component, OnInit} from '@angular/core';
import {AuthService} from '../shared/services/auth.service';
-import {ActivatedRoute, Router} from '@angular/router';
+import {Router} from '@angular/router';
import {FormsModule} from '@angular/forms';
import {ViewportService} from '../shared/services/viewport.service';
import { Title } from '@angular/platform-browser';
-import { take } from 'rxjs/operators';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
@Component({
@@ -21,35 +20,18 @@ export class LoginComponent implements OnInit {
username = '';
password = '';
errorMessage = '';
- private readonly allowedAdminRoutes = new Set([
- '/admin',
- '/shortener'
- ]);
isNarrow = false;
- redirectUrl = '/admin';
constructor(
private authService: AuthService,
private router: Router,
- private route: ActivatedRoute,
private deviceService: ViewportService,
private titleService: Title,
- @Inject(PLATFORM_ID) private platformId: Object
) {}
ngOnInit() {
this.titleService.setTitle('Login | itzMiney')
this.isNarrow = this.deviceService.isNarrow;
-
- this.route.queryParams.pipe(take(1)).subscribe(params => {
- const raw = params['redirectUrl'];
-
- if (typeof raw === 'string' && this.allowedAdminRoutes.has(raw)) {
- this.redirectUrl = raw;
- } else {
- this.redirectUrl = '/admin';
- }
- });
}
onLogin() {
@@ -57,7 +39,7 @@ export class LoginComponent implements OnInit {
this.authService.login(this.username.trim(), this.password).subscribe({
next: () => {
- void this.router.navigateByUrl(this.redirectUrl);
+ void this.router.navigate(['/admin']);
},
error: (err) => {
this.errorMessage =
diff --git a/src/app/shared/modal/modal.component.css b/src/app/shared/modal/modal.component.css
index c62995f..d42e9b8 100644
--- a/src/app/shared/modal/modal.component.css
+++ b/src/app/shared/modal/modal.component.css
@@ -26,12 +26,12 @@
.close-btn {
position: absolute;
- top: 4px;
- right: 8px;
+ top: 25px;
+ right: 25px;
background: none;
color: white;
border: none;
- font-size: 28px;
+ font-size: 40px;
cursor: pointer;
transition: all ease-in-out 0.2s;
}
diff --git a/src/app/shared/modal/modal.component.html b/src/app/shared/modal/modal.component.html
index aca3bd2..0827133 100644
--- a/src/app/shared/modal/modal.component.html
+++ b/src/app/shared/modal/modal.component.html
@@ -1,7 +1,7 @@
@if (isOpen) {
-
-
-
+
+
+
{{ title }}
diff --git a/src/app/shared/services/auth.service.ts b/src/app/shared/services/auth.service.ts
index 3fb32e9..03fe330 100644
--- a/src/app/shared/services/auth.service.ts
+++ b/src/app/shared/services/auth.service.ts
@@ -18,10 +18,10 @@ export class AuthService {
return localStorage.getItem('token');
}
- login(username: string, password: string): Observable
{
- return this.http.post(this.apiUrl, { username, password }).pipe(
- tap((response: any) => {
- if (response?.token) localStorage.setItem('token', response.token);
+ login(username: string, password: string): Observable<{ token: string }> {
+ return this.http.post<{ token: string }>(this.apiUrl, { username, password }).pipe(
+ tap(response => {
+ localStorage.setItem('token', response.token);
})
);
}
@@ -29,60 +29,47 @@ export class AuthService {
logout(): void {
if (this.redirectingToLogin) return;
+ localStorage.removeItem('token');
+
if (this.router.url.startsWith('/login')) {
- localStorage.removeItem('token');
return;
}
this.redirectingToLogin = true;
- localStorage.removeItem('token');
-
- const tree = this.router.parseUrl(this.router.url);
- delete tree.queryParams?.['redirectUrl'];
- const cleanRedirectUrl = tree.toString();
-
- void this.router.navigate(['/login'], {
- queryParams: { redirectUrl: cleanRedirectUrl },
- replaceUrl: true
- }).finally(() => {
+ void this.router.navigate(['/login'], { replaceUrl: true }).finally(() => {
this.redirectingToLogin = false;
});
}
- private isJwtNotExpired(token: string | null): boolean {
- if (!token) return false;
-
- try {
- const payload = JSON.parse(atob(token.split('.')[1]));
- const expMs = payload.exp * 1000;
- return expMs > Date.now();
- } catch {
- return false;
- }
- }
-
- isTokenValid(): Observable {
+ validateToken(): Observable {
const token = this.token;
- if (!this.isJwtNotExpired(token)) {
+ if (!token) {
+ this.logout();
return of(false);
}
- return this.http.get('/api/users', {
- headers: { Authorization: `Bearer ${token}` }
+ try {
+ const payload = JSON.parse(atob(token.split('.')[1]));
+ const isValid = payload.exp * 1000;
+
+ if (!isValid) {
+ this.logout();
+ return of(false);
+ }
+ } catch {
+ this.logout();
+ return of(false);
+ }
+
+ return this.http.get('api/users', {
+ headers: {Authorization: `Bearer ${token}`}
}).pipe(
map(() => true),
- catchError(() => of(false))
- );
- }
-
- validateToken(): Observable {
- return this.isTokenValid().pipe(
- tap(valid => {
- if (!valid) {
- this.logout();
- }
+ catchError(() => {
+ this.logout();
+ return of(false);
})
);
}
diff --git a/src/app/shortener/shortener.component.css b/src/app/shared/shortener/shortener.component.css
similarity index 63%
rename from src/app/shortener/shortener.component.css
rename to src/app/shared/shortener/shortener.component.css
index c0460d2..00e9c65 100644
--- a/src/app/shortener/shortener.component.css
+++ b/src/app/shared/shortener/shortener.component.css
@@ -1,3 +1,16 @@
+.container-wrapper {
+ position: fixed;
+ top: 0;
+ left: 0;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+ width: 100%;
+ background: rgba(0, 0, 0, 0.5);
+ z-index: 1000;
+}
+
.container {
display: flex;
flex-direction: column;
@@ -5,11 +18,13 @@
align-items: center;
min-width: 300px;
padding: 25px;
- background-color: #ffffff;
+ background-color: #202025;
+ color: #fff;
border-radius: 35px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
max-height: 90vh;
overflow: hidden;
+ z-index: 1001;
}
.container-content {
@@ -17,18 +32,9 @@
width: 100%;
}
-.container-wrapper {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- background-color: #592840;
-}
-
h1 {
margin-top: 40px;
text-align: center;
- color: #333;
}
h3 {
@@ -47,23 +53,36 @@ h3 {
gap: 12px;
}
+input {
+ color: white;
+ background: #26262c;
+ border: none;
+ padding: 10px 20px;
+ border-radius: 25px;
+ transition: all ease-in-out 0.2s;
+ box-sizing: border-box;
+ font-size: 1rem;
+}
+
+input:focus {
+ outline: none;
+ background: #2b2b32;
+}
+
input[type="url"],
input[type="text"] {
- min-width: 240px;
- padding: 10px;
- border: 1px solid #ddd;
- border-radius: 25px;
- font-size: 1rem;
- box-sizing: border-box;
+ min-width: 250px;
}
input[type="number"] {
max-width: 80px;
- padding: 10px;
- border: 1px solid #ddd;
- border-radius: 25px;
- font-size: 1rem;
- box-sizing: border-box;
+ -moz-appearance: textfield;
+}
+
+input[type="number"]::-webkit-inner-spin-button,
+input[type="number"]::-webkit-inner-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
}
button {
@@ -75,12 +94,12 @@ button {
}
.btn-primary {
- background-color: #007bff;
+ background-color: #8a6bbf;
color: white;
}
.btn-danger {
- background-color: #dc3545;
+ background-color: #BA243AFF;
color: white;
}
@@ -104,10 +123,9 @@ button:hover {
.url-list-items li {
- background-color: #fff;
+ background: #26262c;
padding: 10px 15px;
row-gap: 10px;
- border: 1px solid #ddd;
border-radius: 20px;
line-height: 1.5rem;
}
@@ -117,7 +135,7 @@ li + li {
}
.url-list-items a {
- color: #007bff;
+ color: #D688ECFF;
text-decoration: none;
}
@@ -127,7 +145,7 @@ li + li {
.copy-btn {
background: transparent;
- color: #007bff;
+ color: #D688ECFF;
border: none;
cursor: pointer;
font-size: 1rem;
@@ -137,5 +155,25 @@ li + li {
}
.copy-btn:active, .copy-btn:focus {
- color: #3e6c49;
+ color: #7dc68e;
+}
+
+.close-btn {
+ position: absolute;
+ top: 25px;
+ right: 25px;
+ background: none;
+ color: white;
+ border: none;
+ font-size: 40px;
+ cursor: pointer;
+ transition: all ease-in-out 0.2s;
+}
+
+.close-btn:hover {
+ color: #ebe1fa;
+}
+
+.close-btn:active {
+ color: #a172e8;
}
diff --git a/src/app/shared/shortener/shortener.component.html b/src/app/shared/shortener/shortener.component.html
new file mode 100644
index 0000000..a84ff98
--- /dev/null
+++ b/src/app/shared/shortener/shortener.component.html
@@ -0,0 +1,89 @@
+@if (isOpen) {
+
+
+
+
+
URL Shortener
+
+
+
+
+
+
+
+
Existing Short URLs
+
+
+
+
+ @if (noURLs) {
+
+
No short URLs available.
+
+ } @else {
+
+ }
+
+
+
+}
diff --git a/src/app/shared/shortener/shortener.component.ts b/src/app/shared/shortener/shortener.component.ts
new file mode 100644
index 0000000..413c54a
--- /dev/null
+++ b/src/app/shared/shortener/shortener.component.ts
@@ -0,0 +1,130 @@
+import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
+import {ShortenerService} from '../services/shortener.service';
+import {FormsModule} from '@angular/forms';
+import { SlicePipe } from '@angular/common';
+import {AuthService} from '../services/auth.service';
+
+@Component({
+ selector: 'app-shortener',
+ imports: [
+ FormsModule,
+ SlicePipe
+],
+ templateUrl: './shortener.component.html',
+ styleUrl: './shortener.component.css'
+})
+export class ShortenerComponent implements OnInit {
+ @Input() isOpen: boolean = false;
+ @Output() onClose = new EventEmitter();
+
+ urls: any[] = [];
+ noURLs: boolean = false;
+
+ og_url: string = '';
+ short_name: string | null = null;
+ deleteId: number | null = null;
+
+ copiedShort: string | null = null;
+
+ constructor(
+ private shortenerService: ShortenerService,
+ private authService: AuthService,
+ ) {}
+
+ ngOnInit() {
+ this.loadURLs();
+ }
+
+ loadURLs(): void {
+ const token = this.authService.token;
+
+ if (!token) {
+ return;
+ }
+
+ this.shortenerService.getAllURLs(token).subscribe({
+ next: (data) => {
+ this.urls = data;
+ this.noURLs = data.length === 0;
+ },
+ error: (err) => {
+ console.error('Error loading URLs:', err)
+ }
+ });
+ }
+
+ createShortURL(form: any) {
+ const og_url = form.value.og_url;
+ const short_name = form.value.short_name ?? null;
+
+ if (!og_url) {
+ alert('Original URL Required!');
+ return;
+ }
+
+ const token = this.authService.token;
+
+ if (!token) {
+ return;
+ }
+
+ const req$ = short_name
+ ? this.shortenerService.postURL(token, og_url, short_name)
+ : this.shortenerService.postURL(token, og_url);
+
+ req$.subscribe({
+ next: () => {
+ alert('Short URL created successfully!');
+ this.loadURLs();
+ },
+ error: (error) => {
+ alert('Error creating Short URL');
+ console.error(error);
+ }
+ });
+ }
+
+ deleteShortURL(form: any) {
+ const id = form.value.deleteId;
+
+ if (!id || isNaN(Number(id))) {
+ alert('Invalid input. Please enter a valid Short URL ID.');
+ return;
+ }
+
+ const token = this.authService.token!;
+
+ if (!token) {
+ return;
+ }
+
+ this.shortenerService.deleteURL(Number(id), token).subscribe({
+ next: () => {
+ alert(`Short URL with ID ${id} deleted successfully`);
+ this.loadURLs();
+ },
+ error: (error) => {
+ alert(`Error deleting Short URL ${id}: ${error.message}`);
+ console.error('Error deleting Short URL:', error);
+ }
+ });
+ }
+
+ copyShortUrl(shortCode: string): void {
+ const shortUrl = `https://itz.sh/${shortCode}`;
+
+ navigator.clipboard.writeText(shortUrl).then(() => {
+ this.copiedShort = shortCode;
+
+ setTimeout(() => {
+ if (this.copiedShort === shortCode) this.copiedShort = null;
+ }, 2000);
+ }).catch(() => {
+ });
+ }
+
+ closeShortenerModal() {
+ this.isOpen = false;
+ this.onClose.emit();
+ }
+}
diff --git a/src/app/shortener/shortener.component.html b/src/app/shortener/shortener.component.html
deleted file mode 100644
index 8a454aa..0000000
--- a/src/app/shortener/shortener.component.html
+++ /dev/null
@@ -1,85 +0,0 @@
-
-
-
-
URL Shortener
-
-
-
-
-
-
-
-
Existing Short URLs
-
-
-
-
- @if (noURLs) {
-
-
No short URLs available.
-
- } @else {
-
- }
-
-
-
-
-
diff --git a/src/app/shortener/shortener.component.ts b/src/app/shortener/shortener.component.ts
deleted file mode 100644
index 1d66a93..0000000
--- a/src/app/shortener/shortener.component.ts
+++ /dev/null
@@ -1,135 +0,0 @@
-import { Component, OnInit, OnDestroy} from '@angular/core';
-import {Title} from '@angular/platform-browser';
-import {ShortenerService} from '../shared/services/shortener.service';
-import {interval, Subscription, switchMap} from 'rxjs';
-import {FormsModule} from '@angular/forms';
-import { SlicePipe } from '@angular/common';
-import {AuthService} from '../shared/services/auth.service';
-import {filter} from 'rxjs/operators';
-
-@Component({
- selector: 'app-shortener',
- imports: [
- FormsModule,
- SlicePipe
-],
- templateUrl: './shortener.component.html',
- styleUrl: './shortener.component.css'
-})
-export class ShortenerComponent implements OnInit, OnDestroy {
- tokenValidationInterval: Subscription = new Subscription();
-
- urls: any[] = [];
- noURLs: boolean = false;
-
- og_url: string = '';
- short_name: string | null = null;
- deleteId: number | null = null;
-
- copiedShort: string | null = null;
-
- constructor(
- private shortenerService: ShortenerService,
- private authService: AuthService,
- private titleService: Title
- ) {}
-
- ngOnInit() {
- this.titleService.setTitle('Shortener | itzMiney')
- this.loadURLs();
- this.startTokenValidation();
- }
-
- ngOnDestroy() {
- this.tokenValidationInterval.unsubscribe();
- }
-
- startTokenValidation() {
- this.tokenValidationInterval = interval(300000).subscribe(() => {
- this.authService.validateToken().subscribe();
- });
- }
-
- loadURLs(): void {
- this.authService.validateToken().pipe(
- filter(valid => valid),
- switchMap(() => this.shortenerService.getAllURLs(this.authService.token!))
- ).subscribe({
- next: (data) => {
- this.urls = data;
- this.noURLs = data.length === 0;
- },
- error: (err) => console.error(err)
- });
- }
-
- createShortURL(form: any) {
- const og_url = form.value.og_url;
- const short_name = form.value.short_name ?? null;
-
- if (!og_url) {
- alert('Original URL Required!');
- return;
- }
-
- this.authService.validateToken().subscribe(valid => {
- if (!valid) return;
-
- const token = this.authService.token!;
-
- const req$ = short_name
- ? this.shortenerService.postURL(token, og_url, short_name)
- : this.shortenerService.postURL(token, og_url);
-
- req$.subscribe(
- () => {
- alert('Short URL created successfully!');
- this.loadURLs();
- },
- (error) => {
- alert('Error creating Short URL');
- console.error(error);
- }
- );
- });
- }
-
- deleteShortURL(form: any) {
- const id = form.value.deleteId;
-
- if (!id || isNaN(Number(id))) {
- alert('Invalid input. Please enter a valid Short URL ID.');
- return;
- }
-
- this.authService.validateToken().subscribe(valid => {
- if (!valid) return;
-
- const token = this.authService.token!;
-
- this.shortenerService.deleteURL(Number(id), token).subscribe(
- () => {
- alert(`Short URL with ID ${id} deleted successfully`);
- this.loadURLs();
- },
- (error) => {
- alert(`Error deleting Short URL ${id}: ${error.message}`);
- console.error('Error deleting Short URL:', error);
- }
- );
- });
- }
-
- copyShortUrl(shortCode: string): void {
- const shortUrl = `https://itz.sh/${shortCode}`;
-
- navigator.clipboard.writeText(shortUrl).then(() => {
- this.copiedShort = shortCode;
-
- setTimeout(() => {
- if (this.copiedShort === shortCode) this.copiedShort = null;
- }, 2000);
- }).catch(() => {
- });
- }
-}