feat: move guest login credentials to environment and prevent guest data change via password reset
This commit is contained in:
parent
8d513ea299
commit
37cdddab1a
8 changed files with 44 additions and 12 deletions
|
|
@ -43,7 +43,9 @@
|
||||||
} @else { @if (mail.touched &&
|
} @else { @if (mail.touched &&
|
||||||
!isEmailValid(pwResetData.mail.toLowerCase())) {
|
!isEmailValid(pwResetData.mail.toLowerCase())) {
|
||||||
<p>{{ "register.errorMail1" | translate }}</p>
|
<p>{{ "register.errorMail1" | translate }}</p>
|
||||||
} }
|
} } @if(errorMessage) {
|
||||||
|
<p>{{ "forgotPW.guestPwChange" | translate }}</p>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
|
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
|
||||||
import { ButtonStateService } from '../../../services/button-state.service';
|
import { ButtonStateService } from '../../../services/button-state.service';
|
||||||
import { AuthService } from '../../../services/auth.service';
|
import { AuthService } from '../../../services/auth.service';
|
||||||
|
import { environment } from '../../../../environments/environment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-forgot-pw',
|
selector: 'app-forgot-pw',
|
||||||
|
|
@ -25,6 +26,7 @@ import { AuthService } from '../../../services/auth.service';
|
||||||
styleUrl: './forgot-pw.component.scss',
|
styleUrl: './forgot-pw.component.scss',
|
||||||
})
|
})
|
||||||
export class ForgotPwComponent {
|
export class ForgotPwComponent {
|
||||||
|
errorMessage = false;
|
||||||
pwResetData = {
|
pwResetData = {
|
||||||
mail: '',
|
mail: '',
|
||||||
};
|
};
|
||||||
|
|
@ -34,27 +36,44 @@ export class ForgotPwComponent {
|
||||||
private authService: AuthService
|
private authService: AuthService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async onSubmit(ngForm: NgForm) {
|
async onSubmit(ngForm: NgForm): Promise<void> {
|
||||||
this.buttonStateService.disableButton();
|
this.buttonStateService.disableButton();
|
||||||
|
if (this.checkGuestEmail()) return;
|
||||||
|
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
if (ngForm.submitted && ngForm.form.valid) {
|
||||||
try {
|
try {
|
||||||
await this.authService.resetPassword(
|
await this.authService.resetPassword(
|
||||||
this.pwResetData.mail.toLowerCase()
|
this.pwResetData.mail.toLowerCase()
|
||||||
);
|
);
|
||||||
this.buttonStateService.enableButton();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
} finally {
|
||||||
|
this.buttonStateService.enableButton();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isButtonDisabled() {
|
checkGuestEmail(): boolean {
|
||||||
|
this.errorMessage = false;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.pwResetData.mail.toLowerCase() ===
|
||||||
|
environment.guestEmail.toLowerCase()
|
||||||
|
) {
|
||||||
|
this.errorMessage = true;
|
||||||
|
this.buttonStateService.enableButton();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isButtonDisabled(): boolean {
|
||||||
return this.buttonStateService.isButtonDisabled;
|
return this.buttonStateService.isButtonDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmailValid(emailValue: string) {
|
isEmailValid(emailValue: string): boolean {
|
||||||
return /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/.test(emailValue);
|
return /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/.test(emailValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,16 +68,16 @@ export class PwResetComponent implements OnInit, OnDestroy {
|
||||||
this.buttonStateService.disableButton();
|
this.buttonStateService.disableButton();
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
if (ngForm.submitted && ngForm.form.valid) {
|
||||||
try {
|
try {
|
||||||
console.log(this.uidb64, this.token);
|
|
||||||
await this.authService.resetPasswordConfirm(
|
await this.authService.resetPasswordConfirm(
|
||||||
this.pwResetData.password,
|
this.pwResetData.password,
|
||||||
this.uidb64,
|
this.uidb64,
|
||||||
this.token
|
this.token
|
||||||
);
|
);
|
||||||
this.buttonStateService.enableButton();
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.errorHttpMessage = error.message;
|
this.errorHttpMessage = error.message;
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
} finally {
|
||||||
|
this.buttonStateService.enableButton();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { TokenService } from '../../services/token.service';
|
||||||
import { ButtonStateService } from '../../services/button-state.service';
|
import { ButtonStateService } from '../../services/button-state.service';
|
||||||
import { PasswordVisibilityService } from '../../services/password-visibility.service';
|
import { PasswordVisibilityService } from '../../services/password-visibility.service';
|
||||||
import { Subject, takeUntil } from 'rxjs';
|
import { Subject, takeUntil } from 'rxjs';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
|
|
@ -86,9 +87,10 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||||
this.loginData.email = this.loginData.email.toLowerCase();
|
this.loginData.email = this.loginData.email.toLowerCase();
|
||||||
try {
|
try {
|
||||||
await this.authService.login(this.loginData, this.checkboxRememberMe);
|
await this.authService.login(this.loginData, this.checkboxRememberMe);
|
||||||
this.buttonStateService.enableButton();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
} finally {
|
||||||
|
this.buttonStateService.enableButton();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
|
@ -96,8 +98,8 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
guestLogin() {
|
guestLogin() {
|
||||||
this.loginData.email = 'guest@guestaccount.com';
|
this.loginData.email = environment.guestEmail.toLowerCase();
|
||||||
this.loginData.password = 'guest@guestaccount.com';
|
this.loginData.password = environment.guestPassword.toLowerCase();
|
||||||
this.isPasswordIconVisible = !this.isPasswordIconVisible;
|
this.isPasswordIconVisible = !this.isPasswordIconVisible;
|
||||||
this.onSubmit({ submitted: true, form: { valid: true } } as NgForm);
|
this.onSubmit({ submitted: true, form: { valid: true } } as NgForm);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,11 @@ export class RegisterComponent {
|
||||||
this.registerData.email = this.registerData.email.toLowerCase();
|
this.registerData.email = this.registerData.email.toLowerCase();
|
||||||
try {
|
try {
|
||||||
await this.authService.register(this.registerData);
|
await this.authService.register(this.registerData);
|
||||||
this.buttonStateService.enableButton();
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.errorHttpMessage = error.message;
|
this.errorHttpMessage = error.message;
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
} finally {
|
||||||
|
this.buttonStateService.enableButton();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
"email": "Ihre E-Mail",
|
"email": "Ihre E-Mail",
|
||||||
"sendMail": "E-Mail senden",
|
"sendMail": "E-Mail senden",
|
||||||
"pwChange": "Passwort ändern",
|
"pwChange": "Passwort ändern",
|
||||||
|
"guestPwChange": "Das Passwort für das Gastkonto kann nicht geändert werden",
|
||||||
"invalidLink": "Dieser Link zum Zurücksetzen Ihres Passworts ist ungültig",
|
"invalidLink": "Dieser Link zum Zurücksetzen Ihres Passworts ist ungültig",
|
||||||
"notice": "Wir senden Ihnen eine E-Mail, über die Sie Ihr Passwort ändern können"
|
"notice": "Wir senden Ihnen eine E-Mail, über die Sie Ihr Passwort ändern können"
|
||||||
},
|
},
|
||||||
|
|
@ -153,7 +154,7 @@
|
||||||
"categorySelection": "Kategorie wählen",
|
"categorySelection": "Kategorie wählen",
|
||||||
"subtask": "Unteraufgaben",
|
"subtask": "Unteraufgaben",
|
||||||
"subtaskFormField": "Unteraufgabe hinzufügen",
|
"subtaskFormField": "Unteraufgabe hinzufügen",
|
||||||
"edit": "Barbeiten",
|
"edit": "Bearbeiten",
|
||||||
"clear": "Leeren",
|
"clear": "Leeren",
|
||||||
"delete": "Löschen",
|
"delete": "Löschen",
|
||||||
"update": "Aktualisieren",
|
"update": "Aktualisieren",
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
"email": "Your Email",
|
"email": "Your Email",
|
||||||
"sendMail": "Send Mail",
|
"sendMail": "Send Mail",
|
||||||
"pwChange": "Change Password",
|
"pwChange": "Change Password",
|
||||||
|
"guestPwChange": "Guest account password cannot be changed",
|
||||||
"invalidLink": "This link to reset your password is invalid",
|
"invalidLink": "This link to reset your password is invalid",
|
||||||
"notice": "We will send you an email to change your password."
|
"notice": "We will send you an email to change your password."
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,10 @@ export const environment = {
|
||||||
* For example: 'http://localhost:8000' or 'https://api.example.com'
|
* For example: 'http://localhost:8000' or 'https://api.example.com'
|
||||||
*/
|
*/
|
||||||
apiUrl: 'https://your-api-url.here',
|
apiUrl: 'https://your-api-url.here',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default email and password for guest accounts.
|
||||||
|
*/
|
||||||
|
guestEmail: 'guest@guestaccount.com',
|
||||||
|
guestPassword: 'guest@guestaccount.com',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue