[WIP] Fixed forgot password #70

This commit is contained in:
Sven Heidemann 2022-10-18 21:00:13 +02:00
parent 47a73a4298
commit d0ded956cb
6 changed files with 26 additions and 24 deletions

View File

@ -16,10 +16,10 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core==2022.10.0.post6", "cpl-core==2022.10.0.post7",
"cpl-translation==2022.10.0.post1", "cpl-translation==2022.10.0.post1",
"cpl-query==2022.10.0.post2", "cpl-query==2022.10.0.post2",
"cpl-discord==2022.10.0.post5", "cpl-discord==2022.10.0.post6",
"Flask==2.2.2", "Flask==2.2.2",
"Flask-Classful==0.14.2", "Flask-Classful==0.14.2",
"Flask-Cors==3.0.10", "Flask-Cors==3.0.10",

View File

@ -6,6 +6,7 @@ from typing import Optional
import jwt import jwt
from cpl_core.database.context import DatabaseContextABC from cpl_core.database.context import DatabaseContextABC
from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.mailing import EMailClientABC, EMail from cpl_core.mailing import EMailClientABC, EMail
from cpl_query.extension import List from cpl_query.extension import List
from cpl_translation import TranslatePipe from cpl_translation import TranslatePipe
@ -35,6 +36,7 @@ class AuthService(AuthServiceABC):
def __init__( def __init__(
self, self,
env: ApplicationEnvironmentABC,
logger: ApiLogger, logger: ApiLogger,
auth_users: AuthUserRepositoryABC, auth_users: AuthUserRepositoryABC,
db: DatabaseContextABC, db: DatabaseContextABC,
@ -46,6 +48,7 @@ class AuthService(AuthServiceABC):
): ):
AuthServiceABC.__init__(self) AuthServiceABC.__init__(self)
self._environment = env
self._logger = logger self._logger = logger
self._auth_users = auth_users self._auth_users = auth_users
self._db = db self._db = db
@ -54,14 +57,6 @@ class AuthService(AuthServiceABC):
self._auth_settings = auth_settings self._auth_settings = auth_settings
self._frontend_settings = frontend_settings self._frontend_settings = frontend_settings
@staticmethod
def _get_mail_to_send() -> EMail:
mail = EMail()
mail.add_header('Mime-Version: 1.0')
mail.add_header('Content-Type: text/plain charset=utf-8')
mail.add_header('Content-Transfer-Encoding: quoted-printable')
return mail
@staticmethod @staticmethod
def _hash_sha256(password: str, salt: str) -> str: def _hash_sha256(password: str, salt: str) -> str:
return hashlib.sha256(f'{password}{salt}'.encode('utf-8')).hexdigest() return hashlib.sha256(f'{password}{salt}'.encode('utf-8')).hexdigest()
@ -141,10 +136,14 @@ class AuthService(AuthServiceABC):
if not url.endswith('/'): if not url.endswith('/'):
url = f'{url}/' url = f'{url}/'
mail = self._get_mail_to_send() mail = EMail()
mail.add_header('Mime-Version: 1.0')
mail.add_header('Content-Type: text/plain charset=utf-8')
mail.add_header('Content-Transfer-Encoding: quoted-printable')
mail.add_receiver(user.email) mail.add_receiver(user.email)
mail.subject = self._t.transform('api.auth.confirmation.subject').format(user.first_name, user.last_name) mail.subject = self._t.transform('api.auth.confirmation.subject').format(user.first_name, user.last_name)
mail.body = self._t.transform('api.auth.confirmation.message').format(url, user.confirmation_id) mail.body = self._t.transform('api.auth.confirmation.message').format(url, user.confirmation_id)
mail.body += f'\n\nDies ist eine automatische E-Mail.\nGesendet von {self._environment.application_name}-{self._environment.environment_name}@{self._environment.host_name}'
self._mailer.send_mail(mail) self._mailer.send_mail(mail)
def _send_forgot_password_id_to_user(self, user: AuthUser): def _send_forgot_password_id_to_user(self, user: AuthUser):
@ -152,10 +151,14 @@ class AuthService(AuthServiceABC):
if not url.endswith('/'): if not url.endswith('/'):
url = f'{url}/' url = f'{url}/'
mail = self._get_mail_to_send() mail = EMail()
mail.add_header('Mime-Version: 1.0')
mail.add_header('Content-Type: text/plain charset=utf-8')
mail.add_header('Content-Transfer-Encoding: quoted-printable')
mail.add_receiver(user.email) mail.add_receiver(user.email)
mail.subject = self._t.transform('api.auth.forgot_password.subject').format(user.first_name, user.last_name) mail.subject = str(self._t.transform('api.auth.forgot_password.subject').format(user.first_name, user.last_name))
mail.body = self._t.transform('api.auth.forgot_password.message').format(url, user.forgot_password_id) mail.body = str(self._t.transform('api.auth.forgot_password.message').format(url, user.forgot_password_id))
mail.body += f'\n\nDies ist eine automatische E-Mail.\nGesendet von {self._environment.application_name}-{self._environment.environment_name}@{self._environment.host_name}'
self._mailer.send_mail(mail) self._mailer.send_mail(mail)
async def get_all_auth_users_async(self) -> List[AuthUserDTO]: async def get_all_auth_users_async(self) -> List[AuthUserDTO]:

View File

@ -37,6 +37,7 @@ export class ForgetPasswordComponent implements OnInit {
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
console.log('test');
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.authService.isUserLoggedInAsync().then(result => { this.authService.isUserLoggedInAsync().then(result => {
if (result) { if (result) {

View File

@ -2,7 +2,7 @@
<div class="login-form-wrapper"> <div class="login-form-wrapper">
<div class="login-form"> <div class="login-form">
<form [formGroup]="loginForm"> <form [formGroup]="loginForm">
<h1>sh-edraft.de</h1> <h1>{{'auth.header' | translate}}</h1>
<div class="input-field"> <div class="input-field">
<input type="email" pInputText formControlName="email" placeholder="{{'auth.login.e_mail' | translate}}" [ngClass]="{ 'invalid-feedback-input': submitted && ( <input type="email" pInputText formControlName="email" placeholder="{{'auth.login.e_mail' | translate}}" [ngClass]="{ 'invalid-feedback-input': submitted && (
(loginForm.controls.email.errors && loginForm.controls.email.errors['required'] || authUserAtrErrors.email.required) || (loginForm.controls.email.errors && loginForm.controls.email.errors['required'] || authUserAtrErrors.email.required) ||

View File

@ -102,8 +102,7 @@ export class AuthService {
} }
forgotPassword(email: string): Observable<unknown> { forgotPassword(email: string): Observable<unknown> {
const emailJson = JSON.stringify(email); return this.http.post(`${this.appsettings.getApiURL()}/api/auth/forgot-password/${email}`, {
return this.http.post(`${this.appsettings.getApiURL()}/api/auth/forgot-password`, emailJson, {
headers: new HttpHeaders({ headers: new HttpHeaders({
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}) })
@ -111,8 +110,7 @@ export class AuthService {
} }
getEMailFromforgotPasswordId(id: string): Observable<EMailStringDTO> { getEMailFromforgotPasswordId(id: string): Observable<EMailStringDTO> {
const idJson = JSON.stringify(id); return this.http.post<EMailStringDTO>(`${this.appsettings.getApiURL()}/api/auth/confirm-forgot-password/${id}`, {
return this.http.post<EMailStringDTO>(`${this.appsettings.getApiURL()}/api/auth/confirm-forgot-password`, idJson, {
headers: new HttpHeaders({ headers: new HttpHeaders({
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}) })

View File

@ -166,12 +166,12 @@ header {
.input-field-info-text { .input-field-info-text {
margin: 15px 0px; margin: 15px 0px;
width: 240px; width: 100%;
} }
.login-form-submit { .login-form-submit {
.login-form-submit-btn { .login-form-submit-btn {
width: 240px; width: 100%;
} }
} }
@ -395,12 +395,12 @@ footer {
.input-field-info-text { .input-field-info-text {
margin: 15px 0px; margin: 15px 0px;
width: 240px; width: 100%;
} }
.login-form-submit { .login-form-submit {
.login-form-submit-btn { .login-form-submit-btn {
width: 240px; width: 100%;
} }
} }
@ -440,7 +440,7 @@ footer {
input, input,
.p-password { .p-password {
height: 40px; height: 40px;
width: 240px; width: 100%;
font-size: 18px; font-size: 18px;
} }
} }