Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbush committed Sep 23, 2024
1 parent 1be695b commit 5eaf534
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 50 deletions.
23 changes: 21 additions & 2 deletions postrify-frontend/src/app/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,25 @@ import { AuthService } from '../services/auth.service';
@if (authService.isAuthenticated()) {
<span class="username">{{ authService.getUsername() }}</span>
<button class="logout-button" (click)="logout()">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-logout"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2" /><path d="M9 12h12l-3 -3" /><path d="M18 15l3 -3" /></svg>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="icon icon-tabler icons-tabler-outline icon-tabler-logout"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2"
/>
<path d="M9 12h12l-3 -3" />
<path d="M18 15l3 -3" />
</svg>
</button>
} @else {
<a routerLink="/login" class="auth-button">Login</a>
Expand Down Expand Up @@ -138,7 +156,8 @@ import { AuthService } from '../services/auth.service';
color: var(--header-text);
}
.toggle-button:hover, .logout-button:hover {
.toggle-button:hover,
.logout-button:hover {
color: var(--primary-color);
}
Expand Down
56 changes: 29 additions & 27 deletions postrify-frontend/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ import { Router } from '@angular/router';
required
pattern="^[a-zA-Z0-9_]{3,20}$"
/>
@if (usernameInput.invalid &&
(usernameInput.dirty || usernameInput.touched)) {
<div
class="error-message"
>
@if (usernameInput.errors?.['required']) {
<span>Username is required.</span>
}
@if (usernameInput.errors?.['pattern']) {
<span>Username must be 3-20 characters and can only contain letters,
numbers and underscores.</span>
}
</div>
}
@if (
usernameInput.invalid &&
(usernameInput.dirty || usernameInput.touched)
) {
<div class="error-message">
@if (usernameInput.errors?.['required']) {
<span>Username is required.</span>
}
@if (usernameInput.errors?.['pattern']) {
<span
>Username must be 3-20 characters and can only contain
letters, numbers and underscores.</span
>
}
</div>
}
</div>
<div class="form-group">
<label for="password">Password</label>
Expand All @@ -50,19 +52,19 @@ import { Router } from '@angular/router';
required
pattern="^.{6,}$"
/>
@if (passwordInput.invalid &&
(passwordInput.dirty || passwordInput.touched)) {
<div
class="error-message"
>
@if (passwordInput.errors?.['required']) {
<span>Password is required.</span>
}
@if (passwordInput.errors?.['pattern']) {
<span>Password must be at least 6 characters long.</span>
}
</div>
}
@if (
passwordInput.invalid &&
(passwordInput.dirty || passwordInput.touched)
) {
<div class="error-message">
@if (passwordInput.errors?.['required']) {
<span>Password is required.</span>
}
@if (passwordInput.errors?.['pattern']) {
<span>Password must be at least 6 characters long.</span>
}
</div>
}
</div>
<button type="submit" [disabled]="loginForm.invalid">Login</button>
</form>
Expand Down
28 changes: 15 additions & 13 deletions postrify-frontend/src/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ import { ToastService } from '../services/toast.service';
required
pattern="^[a-zA-Z0-9_]{3,20}$"
/>
@if (usernameInput.invalid && (usernameInput.dirty || usernameInput.touched)) {
<div
class="error-message"
>
@if (
usernameInput.invalid &&
(usernameInput.dirty || usernameInput.touched)
) {
<div class="error-message">
@if (usernameInput.errors?.['required']) {
<span>Username is required.</span>
}
@if (usernameInput.errors?.['pattern']) {
<span>Username must be 3-20 characters and can only contain letters,
numbers and underscores.</span>
<span
>Username must be 3-20 characters and can only contain
letters, numbers and underscores.</span
>
}
</div>
}
Expand All @@ -49,9 +52,7 @@ import { ToastService } from '../services/toast.service';
pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$"
/>
@if (emailInput.invalid && (emailInput.dirty || emailInput.touched)) {
<div
class="error-message"
>
<div class="error-message">
@if (emailInput.errors?.['required']) {
<span>Email is required.</span>
}
Expand All @@ -72,10 +73,11 @@ import { ToastService } from '../services/toast.service';
required
pattern="^.{6,}$"
/>
@if (passwordInput.invalid && (passwordInput.dirty || passwordInput.touched)) {
<div
class="error-message"
>
@if (
passwordInput.invalid &&
(passwordInput.dirty || passwordInput.touched)
) {
<div class="error-message">
@if (passwordInput.errors?.['required']) {
<span>Password is required.</span>
}
Expand Down
18 changes: 10 additions & 8 deletions postrify-frontend/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ export class AuthService {
constructor(private http: HttpClient) {}

login(username: string, password: string): Observable<LoginResponse> {
return this.http.post<LoginResponse>(`${this.apiUrl}/signin`, {
username,
password,
}).pipe(
tap((response) => {
localStorage.setItem('token', response.token);
localStorage.setItem('username', response.username);
return this.http
.post<LoginResponse>(`${this.apiUrl}/signin`, {
username,
password,
})
);
.pipe(
tap((response) => {
localStorage.setItem('token', response.token);
localStorage.setItem('username', response.username);
}),
);
}

register(
Expand Down

0 comments on commit 5eaf534

Please sign in to comment.