refactor user accounts structure
This commit is contained in:
@@ -60,18 +60,18 @@ export class AuthComponent {
|
||||
|
||||
if (!redirectUrl) {
|
||||
switch (this.selectedRole()) {
|
||||
case 'SUPERADMIN':
|
||||
redirectUrl = '/super_admin';
|
||||
break;
|
||||
case 'ADMIN':
|
||||
redirectUrl = '/super_admin';
|
||||
break;
|
||||
case 'POS':
|
||||
redirectUrl = '/pos';
|
||||
case 'PROVIDER':
|
||||
redirectUrl = '/provider';
|
||||
break;
|
||||
case 'PARTNER':
|
||||
redirectUrl = '/partner';
|
||||
break;
|
||||
case 'CONSUMER':
|
||||
redirectUrl = '/consumer';
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.router.navigateByUrl(redirectUrl);
|
||||
|
||||
@@ -62,7 +62,6 @@ export class LoginComponent {
|
||||
// role: [this.defaultRole, [Validators.required]],
|
||||
});
|
||||
|
||||
selectedRole = signal<TRoles>('SUPERADMIN');
|
||||
ngOnInit() {
|
||||
// this.captchaService.requestNewCaptcha();
|
||||
}
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
import { AuthService } from '@/core';
|
||||
import { IUserLoginInfo, TRoles } from '@/core/models';
|
||||
import { ToastService } from '@/core/services/toast.service';
|
||||
import { MustMatch } from '@/core/validators';
|
||||
import { password } from '@/core/validators/password.validator';
|
||||
import { UikitFieldComponent } from '@/uikit/uikit-field.component';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { Button } from 'primeng/button';
|
||||
import { ImageModule } from 'primeng/image';
|
||||
import { InputGroupModule } from 'primeng/inputgroup';
|
||||
import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
|
||||
import { InputText } from 'primeng/inputtext';
|
||||
import { Message } from 'primeng/message';
|
||||
import { Password } from 'primeng/password';
|
||||
import { ProgressSpinnerModule } from 'primeng/progressspinner';
|
||||
import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
// import { AuthService } from '@/core';
|
||||
// import { IUserLoginInfo, TRoles } from '@/core/models';
|
||||
// import { ToastService } from '@/core/services/toast.service';
|
||||
// import { MustMatch } from '@/core/validators';
|
||||
// import { password } from '@/core/validators/password.validator';
|
||||
// import { UikitFieldComponent } from '@/uikit/uikit-field.component';
|
||||
// import { CommonModule } from '@angular/common';
|
||||
// import { Component, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
// import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
// import { Router } from '@angular/router';
|
||||
// import { Button } from 'primeng/button';
|
||||
// import { ImageModule } from 'primeng/image';
|
||||
// import { InputGroupModule } from 'primeng/inputgroup';
|
||||
// import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
|
||||
// import { InputText } from 'primeng/inputtext';
|
||||
// import { Message } from 'primeng/message';
|
||||
// import { Password } from 'primeng/password';
|
||||
// import { ProgressSpinnerModule } from 'primeng/progressspinner';
|
||||
// import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
|
||||
@Component({
|
||||
selector: 'app-modify-login-info',
|
||||
templateUrl: './modify-login-info.component.html',
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
Password,
|
||||
InputText,
|
||||
ImageModule,
|
||||
ProgressSpinnerModule,
|
||||
RadioButtonModule,
|
||||
InputGroupModule,
|
||||
InputGroupAddonModule,
|
||||
UikitFieldComponent,
|
||||
Message,
|
||||
],
|
||||
})
|
||||
export class ModifyLoginInfoComponent {
|
||||
@Input() userLoginInfo!: Partial<IUserLoginInfo>;
|
||||
@Input() role!: TRoles;
|
||||
// @Component({
|
||||
// selector: 'app-modify-login-info',
|
||||
// templateUrl: './modify-login-info.component.html',
|
||||
// imports: [
|
||||
// CommonModule,
|
||||
// ReactiveFormsModule,
|
||||
// Button,
|
||||
// Password,
|
||||
// InputText,
|
||||
// ImageModule,
|
||||
// ProgressSpinnerModule,
|
||||
// RadioButtonModule,
|
||||
// InputGroupModule,
|
||||
// InputGroupAddonModule,
|
||||
// UikitFieldComponent,
|
||||
// Message,
|
||||
// ],
|
||||
// })
|
||||
// export class ModifyLoginInfoComponent {
|
||||
// @Input() userLoginInfo!: Partial<IUserLoginInfo>;
|
||||
// @Input() role!: TRoles;
|
||||
|
||||
@Output() onSubmit = new EventEmitter<IUserLoginInfo>();
|
||||
@Output() toLogin = new EventEmitter<void>();
|
||||
// @Output() onSubmit = new EventEmitter<IUserLoginInfo>();
|
||||
// @Output() toLogin = new EventEmitter<void>();
|
||||
|
||||
private readonly authService = inject(AuthService);
|
||||
private readonly toastService = inject(ToastService);
|
||||
private readonly router = inject(Router);
|
||||
private readonly fb = inject(FormBuilder);
|
||||
// private readonly authService = inject(AuthService);
|
||||
// private readonly toastService = inject(ToastService);
|
||||
// private readonly router = inject(Router);
|
||||
// private readonly fb = inject(FormBuilder);
|
||||
|
||||
readonly isLoading = signal<boolean>(false);
|
||||
readonly errorMessage = signal<string>('');
|
||||
readonly hidePassword = signal<boolean>(true);
|
||||
// readonly isLoading = signal<boolean>(false);
|
||||
// readonly errorMessage = signal<string>('');
|
||||
// readonly hidePassword = signal<boolean>(true);
|
||||
|
||||
readonly infoForm = this.fb.group(
|
||||
{
|
||||
username: [this.userLoginInfo?.username, [Validators.required]],
|
||||
password: ['', [Validators.required, password()]],
|
||||
confirmPassword: ['', [Validators.required]],
|
||||
mobile: [this.userLoginInfo?.mobile, [Validators.required]],
|
||||
email: [this.userLoginInfo?.email, [Validators.required, Validators.email]],
|
||||
},
|
||||
{
|
||||
validators: [MustMatch('password', 'confirmPassword')],
|
||||
},
|
||||
);
|
||||
// readonly infoForm = this.fb.group(
|
||||
// {
|
||||
// username: [this.userLoginInfo?.username, [Validators.required]],
|
||||
// password: ['', [Validators.required, password()]],
|
||||
// confirmPassword: ['', [Validators.required]],
|
||||
// mobile: [this.userLoginInfo?.mobile, [Validators.required]],
|
||||
// email: [this.userLoginInfo?.email, [Validators.required, Validators.email]],
|
||||
// },
|
||||
// {
|
||||
// validators: [MustMatch('password', 'confirmPassword')],
|
||||
// },
|
||||
// );
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.getInfo(this.role).subscribe({
|
||||
next: (info) => {
|
||||
this.infoForm.patchValue(info);
|
||||
},
|
||||
error: () => {
|
||||
this.toLogin.emit();
|
||||
},
|
||||
});
|
||||
}
|
||||
// ngOnInit() {
|
||||
// this.authService.getInfo(this.role).subscribe({
|
||||
// next: (info) => {
|
||||
// this.infoForm.patchValue(info);
|
||||
// },
|
||||
// error: () => {
|
||||
// this.toLogin.emit();
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
submit(): void {
|
||||
this.infoForm.markAllAsTouched();
|
||||
if (this.infoForm.invalid) return;
|
||||
const credentials: IUserLoginInfo = this.infoForm.value as IUserLoginInfo;
|
||||
this.isLoading.set(true);
|
||||
this.authService.changeInfo(credentials, this.role).subscribe({
|
||||
next: () => {
|
||||
this.toastService.success({
|
||||
text: 'اطلاعات با موفقیت بهروزرسانی شد',
|
||||
});
|
||||
this.errorMessage.set('');
|
||||
this.onSubmit?.emit();
|
||||
this.isLoading.set(false);
|
||||
// this.router.navigateByUrl(this.redirectUrl.replace(/\/[^/]*$/, ''));
|
||||
},
|
||||
error: (error) => {
|
||||
this.isLoading.set(false);
|
||||
// this.errorMessage.set('نام کاربری یا رمز عبور اشتباه است');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
// submit(): void {
|
||||
// this.infoForm.markAllAsTouched();
|
||||
// if (this.infoForm.invalid) return;
|
||||
// const credentials: IUserLoginInfo = this.infoForm.value as IUserLoginInfo;
|
||||
// this.isLoading.set(true);
|
||||
// this.authService.changeInfo(credentials, this.role).subscribe({
|
||||
// next: () => {
|
||||
// this.toastService.success({
|
||||
// text: 'اطلاعات با موفقیت بهروزرسانی شد',
|
||||
// });
|
||||
// this.errorMessage.set('');
|
||||
// this.onSubmit?.emit();
|
||||
// this.isLoading.set(false);
|
||||
// // this.router.navigateByUrl(this.redirectUrl.replace(/\/[^/]*$/, ''));
|
||||
// },
|
||||
// error: (error) => {
|
||||
// this.isLoading.set(false);
|
||||
// // this.errorMessage.set('نام کاربری یا رمز عبور اشتباه است');
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
import { AuthService } from '@/core';
|
||||
import { ISignupRequestPayload, IUserLoginInfo, Maybe, TRoles } from '@/core/models';
|
||||
import { ToastService } from '@/core/services/toast.service';
|
||||
import { mobileValidator, MustMatch } from '@/core/validators';
|
||||
import { password } from '@/core/validators/password.validator';
|
||||
// import { GenderSelectComponent } from '@/shared/catalog';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { UikitFieldComponent } from '@/uikit/uikit-field.component';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { Button } from 'primeng/button';
|
||||
import { ImageModule } from 'primeng/image';
|
||||
import { InputGroupModule } from 'primeng/inputgroup';
|
||||
import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
|
||||
import { Password } from 'primeng/password';
|
||||
import { ProgressSpinnerModule } from 'primeng/progressspinner';
|
||||
import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
// import { AuthService } from '@/core';
|
||||
// import { ISignupRequestPayload, IUserLoginInfo, Maybe, TRoles } from '@/core/models';
|
||||
// import { ToastService } from '@/core/services/toast.service';
|
||||
// import { mobileValidator, MustMatch } from '@/core/validators';
|
||||
// import { password } from '@/core/validators/password.validator';
|
||||
// // import { GenderSelectComponent } from '@/shared/catalog';
|
||||
// import { InputComponent } from '@/shared/components';
|
||||
// import { UikitFieldComponent } from '@/uikit/uikit-field.component';
|
||||
// import { CommonModule } from '@angular/common';
|
||||
// import { Component, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
// import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
// import { Router } from '@angular/router';
|
||||
// import { Button } from 'primeng/button';
|
||||
// import { ImageModule } from 'primeng/image';
|
||||
// import { InputGroupModule } from 'primeng/inputgroup';
|
||||
// import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
|
||||
// import { Password } from 'primeng/password';
|
||||
// import { ProgressSpinnerModule } from 'primeng/progressspinner';
|
||||
// import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
|
||||
@Component({
|
||||
selector: 'auth-signup',
|
||||
templateUrl: './signup.component.html',
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
Password,
|
||||
ImageModule,
|
||||
ProgressSpinnerModule,
|
||||
RadioButtonModule,
|
||||
InputGroupModule,
|
||||
InputGroupAddonModule,
|
||||
UikitFieldComponent,
|
||||
InputComponent,
|
||||
// GenderSelectComponent,
|
||||
],
|
||||
})
|
||||
export class SignupComponent {
|
||||
@Input() userLoginInfo!: Partial<IUserLoginInfo>;
|
||||
@Input() role!: TRoles;
|
||||
// @Component({
|
||||
// selector: 'auth-signup',
|
||||
// templateUrl: './signup.component.html',
|
||||
// imports: [
|
||||
// CommonModule,
|
||||
// ReactiveFormsModule,
|
||||
// Button,
|
||||
// Password,
|
||||
// ImageModule,
|
||||
// ProgressSpinnerModule,
|
||||
// RadioButtonModule,
|
||||
// InputGroupModule,
|
||||
// InputGroupAddonModule,
|
||||
// UikitFieldComponent,
|
||||
// InputComponent,
|
||||
// // GenderSelectComponent,
|
||||
// ],
|
||||
// })
|
||||
// export class SignupComponent {
|
||||
// @Input() userLoginInfo!: Partial<IUserLoginInfo>;
|
||||
// @Input() role!: TRoles;
|
||||
|
||||
@Output() onSubmit = new EventEmitter<IUserLoginInfo>();
|
||||
@Output() toLogin = new EventEmitter<void>();
|
||||
// @Output() onSubmit = new EventEmitter<IUserLoginInfo>();
|
||||
// @Output() toLogin = new EventEmitter<void>();
|
||||
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly toastService: ToastService,
|
||||
private readonly router: Router,
|
||||
) {}
|
||||
// constructor(
|
||||
// private readonly authService: AuthService,
|
||||
// private readonly toastService: ToastService,
|
||||
// private readonly router: Router,
|
||||
// ) {}
|
||||
|
||||
private readonly fb = inject(FormBuilder);
|
||||
// private readonly fb = inject(FormBuilder);
|
||||
|
||||
readonly isLoading = signal<boolean>(false);
|
||||
readonly errorMessage = signal<string>('');
|
||||
readonly hidePassword = signal<boolean>(true);
|
||||
// readonly isLoading = signal<boolean>(false);
|
||||
// readonly errorMessage = signal<string>('');
|
||||
// readonly hidePassword = signal<boolean>(true);
|
||||
|
||||
readonly form = this.fb.group(
|
||||
{
|
||||
firstName: ['', [Validators.required]],
|
||||
lastName: ['', [Validators.required]],
|
||||
gender: [null as Maybe<boolean>, [Validators.required]],
|
||||
mobile: ['', [Validators.required, mobileValidator()]],
|
||||
email: ['', [Validators.required, Validators.email]],
|
||||
username: ['', [Validators.required]],
|
||||
password: ['', [Validators.required, password()]],
|
||||
confirmPassword: ['', [Validators.required]],
|
||||
},
|
||||
{
|
||||
validators: [MustMatch('password', 'confirmPassword')],
|
||||
},
|
||||
);
|
||||
// readonly form = this.fb.group(
|
||||
// {
|
||||
// firstName: ['', [Validators.required]],
|
||||
// lastName: ['', [Validators.required]],
|
||||
// gender: [null as Maybe<boolean>, [Validators.required]],
|
||||
// mobile: ['', [Validators.required, mobileValidator()]],
|
||||
// email: ['', [Validators.required, Validators.email]],
|
||||
// username: ['', [Validators.required]],
|
||||
// password: ['', [Validators.required, password()]],
|
||||
// confirmPassword: ['', [Validators.required]],
|
||||
// },
|
||||
// {
|
||||
// validators: [MustMatch('password', 'confirmPassword')],
|
||||
// },
|
||||
// );
|
||||
|
||||
submit(): void {
|
||||
this.form.markAllAsTouched();
|
||||
// submit(): void {
|
||||
// this.form.markAllAsTouched();
|
||||
|
||||
if (this.form.invalid) return;
|
||||
const credentials = this.form.value as ISignupRequestPayload;
|
||||
this.isLoading.set(true);
|
||||
this.authService.signup(credentials, this.role).subscribe({
|
||||
next: () => {
|
||||
this.toastService.success({
|
||||
text: 'ثبت نام با موفقیت انجام شد. لطفا وارد شوید.',
|
||||
});
|
||||
this.errorMessage.set('');
|
||||
this.onSubmit?.emit();
|
||||
this.isLoading.set(false);
|
||||
},
|
||||
error: (error) => {
|
||||
this.isLoading.set(false);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
// if (this.form.invalid) return;
|
||||
// const credentials = this.form.value as ISignupRequestPayload;
|
||||
// this.isLoading.set(true);
|
||||
// this.authService.signup(credentials, this.role).subscribe({
|
||||
// next: () => {
|
||||
// this.toastService.success({
|
||||
// text: 'ثبت نام با موفقیت انجام شد. لطفا وارد شوید.',
|
||||
// });
|
||||
// this.errorMessage.set('');
|
||||
// this.onSubmit?.emit();
|
||||
// this.isLoading.set(false);
|
||||
// },
|
||||
// error: (error) => {
|
||||
// this.isLoading.set(false);
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user