Browse Source

refactor: migrate account package to inject() DI

pull/23262/head
Fahri Gedik 1 year ago
parent
commit
519d99f1d4
  1. 6
      npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/account.service.ts
  2. 6
      npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/profile.service.ts
  3. 6
      npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/web/areas/account/controllers/account.service.ts
  4. 13
      npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts
  5. 14
      npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts
  6. 16
      npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts
  7. 10
      npm/ng-packs/packages/account/src/lib/components/forgot-password/forgot-password.component.ts
  8. 10
      npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts
  9. 8
      npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings-half-row.component.ts
  10. 18
      npm/ng-packs/packages/account/src/lib/components/register/register.component.ts
  11. 16
      npm/ng-packs/packages/account/src/lib/components/reset-password/reset-password.component.ts

6
npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/account.service.ts

@ -1,12 +1,14 @@
import type { RegisterDto, ResetPasswordDto, SendPasswordResetCodeDto } from './models'; import type { RegisterDto, ResetPasswordDto, SendPasswordResetCodeDto } from './models';
import { RestService } from '@abp/ng.core'; import { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core'; import { Injectable, inject } from '@angular/core';
import type { IdentityUserDto } from '../identity/models'; import type { IdentityUserDto } from '../identity/models';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class AccountService { export class AccountService {
private restService = inject(RestService);
apiName = 'AbpAccount'; apiName = 'AbpAccount';
register = (input: RegisterDto) => register = (input: RegisterDto) =>
@ -32,6 +34,4 @@ export class AccountService {
body: input, body: input,
}, },
{ apiName: this.apiName }); { apiName: this.apiName });
constructor(private restService: RestService) {}
} }

6
npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/profile.service.ts

@ -1,11 +1,13 @@
import type { ChangePasswordInput, ProfileDto, UpdateProfileDto } from './models'; import type { ChangePasswordInput, ProfileDto, UpdateProfileDto } from './models';
import { RestService } from '@abp/ng.core'; import { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core'; import { Injectable, inject } from '@angular/core';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ProfileService { export class ProfileService {
private restService = inject(RestService);
apiName = 'AbpAccount'; apiName = 'AbpAccount';
changePassword = (input: ChangePasswordInput) => changePassword = (input: ChangePasswordInput) =>
@ -30,6 +32,4 @@ export class ProfileService {
body: input, body: input,
}, },
{ apiName: this.apiName }); { apiName: this.apiName });
constructor(private restService: RestService) {}
} }

6
npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/web/areas/account/controllers/account.service.ts

@ -1,11 +1,13 @@
import type { AbpLoginResult, UserLoginInfo } from './models/models'; import type { AbpLoginResult, UserLoginInfo } from './models/models';
import { RestService } from '@abp/ng.core'; import { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core'; import { Injectable, inject } from '@angular/core';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class AccountService { export class AccountService {
private restService = inject(RestService);
apiName = 'AbpAccount'; apiName = 'AbpAccount';
checkPasswordByLogin = (login: UserLoginInfo) => checkPasswordByLogin = (login: UserLoginInfo) =>
@ -30,6 +32,4 @@ export class AccountService {
url: '/api/account/logout', url: '/api/account/logout',
}, },
{ apiName: this.apiName }); { apiName: this.apiName });
constructor(private restService: RestService) {}
} }

13
npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts

@ -1,4 +1,4 @@
import { Injectable, Injector } from '@angular/core'; import { Injectable, Injector, inject } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
@ -6,6 +6,9 @@ import { ConfigStateService, MultiTenancyService } from '@abp/ng.core';
@Injectable() @Injectable()
export class AuthWrapperService { export class AuthWrapperService {
readonly multiTenancy = inject(MultiTenancyService);
private configState = inject(ConfigStateService);
isMultiTenancyEnabled$ = this.configState.getDeep$('multiTenancy.isEnabled'); isMultiTenancyEnabled$ = this.configState.getDeep$('multiTenancy.isEnabled');
get enableLocalLogin$(): Observable<boolean> { get enableLocalLogin$(): Observable<boolean> {
@ -25,11 +28,9 @@ export class AuthWrapperService {
return this.isTenantBoxVisibleForCurrentRoute && this.multiTenancy.isTenantBoxVisible; return this.isTenantBoxVisibleForCurrentRoute && this.multiTenancy.isTenantBoxVisible;
} }
constructor( constructor() {
public readonly multiTenancy: MultiTenancyService, const injector = inject(Injector);
private configState: ConfigStateService,
injector: Injector,
) {
this.route = injector.get(ActivatedRoute); this.route = injector.get(ActivatedRoute);
} }

14
npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts

@ -5,11 +5,16 @@ import {
SessionStateService, SessionStateService,
} from '@abp/ng.core'; } from '@abp/ng.core';
import { ToasterService } from '@abp/ng.theme.shared'; import { ToasterService } from '@abp/ng.theme.shared';
import { Injectable } from '@angular/core'; import { Injectable, inject } from '@angular/core';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
@Injectable() @Injectable()
export class TenantBoxService { export class TenantBoxService {
private toasterService = inject(ToasterService);
private tenantService = inject(AbpTenantService);
private sessionState = inject(SessionStateService);
private configState = inject(ConfigStateService);
currentTenant$ = this.sessionState.getTenant$(); currentTenant$ = this.sessionState.getTenant$();
name?: string; name?: string;
@ -18,13 +23,6 @@ export class TenantBoxService {
modalBusy!: boolean; modalBusy!: boolean;
constructor(
private toasterService: ToasterService,
private tenantService: AbpTenantService,
private sessionState: SessionStateService,
private configState: ConfigStateService,
) {}
onSwitch() { onSwitch() {
const tenant = this.sessionState.getTenant(); const tenant = this.sessionState.getTenant();
this.name = tenant?.name || ''; this.name = tenant?.name || '';

16
npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts

@ -1,6 +1,6 @@
import { ProfileService } from '@abp/ng.account.core/proxy'; import { ProfileService } from '@abp/ng.account.core/proxy';
import { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared'; import { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared';
import { Component, Injector, OnInit } from '@angular/core'; import { Component, Injector, OnInit, inject } from '@angular/core';
import { import {
ReactiveFormsModule, ReactiveFormsModule,
UntypedFormBuilder, UntypedFormBuilder,
@ -32,6 +32,12 @@ const PASSWORD_FIELDS = ['newPassword', 'repeatNewPassword'];
export class ChangePasswordComponent export class ChangePasswordComponent
implements OnInit, Account.ChangePasswordComponentInputs, Account.ChangePasswordComponentOutputs implements OnInit, Account.ChangePasswordComponentInputs, Account.ChangePasswordComponentOutputs
{ {
private fb = inject(UntypedFormBuilder);
private injector = inject(Injector);
private toasterService = inject(ToasterService);
private profileService = inject(ProfileService);
private manageProfileState = inject(ManageProfileStateService);
form!: UntypedFormGroup; form!: UntypedFormGroup;
inProgress?: boolean; inProgress?: boolean;
@ -44,14 +50,6 @@ export class ChangePasswordComponent
return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch')); return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch'));
}; };
constructor(
private fb: UntypedFormBuilder,
private injector: Injector,
private toasterService: ToasterService,
private profileService: ProfileService,
private manageProfileState: ManageProfileStateService,
) {}
ngOnInit(): void { ngOnInit(): void {
this.hideCurrentPassword = !this.manageProfileState.getProfile()?.hasPassword; this.hideCurrentPassword = !this.manageProfileState.getProfile()?.hasPassword;

10
npm/ng-packs/packages/account/src/lib/components/forgot-password/forgot-password.component.ts

@ -1,5 +1,5 @@
import { AccountService } from '@abp/ng.account.core/proxy'; import { AccountService } from '@abp/ng.account.core/proxy';
import { Component } from '@angular/core'; import { Component, inject } from '@angular/core';
import { import {
ReactiveFormsModule, ReactiveFormsModule,
UntypedFormBuilder, UntypedFormBuilder,
@ -24,16 +24,16 @@ import { NgxValidateCoreModule } from '@ngx-validate/core';
], ],
}) })
export class ForgotPasswordComponent { export class ForgotPasswordComponent {
private fb = inject(UntypedFormBuilder);
private accountService = inject(AccountService);
form: UntypedFormGroup; form: UntypedFormGroup;
inProgress?: boolean; inProgress?: boolean;
isEmailSent = false; isEmailSent = false;
constructor( constructor() {
private fb: UntypedFormBuilder,
private accountService: AccountService,
) {
this.form = this.fb.group({ this.form = this.fb.group({
email: ['', [Validators.required, Validators.email]], email: ['', [Validators.required, Validators.email]],
}); });

10
npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts

@ -1,7 +1,7 @@
import { ProfileService } from '@abp/ng.account.core/proxy'; import { ProfileService } from '@abp/ng.account.core/proxy';
import { fadeIn, LoadingDirective } from '@abp/ng.theme.shared'; import { fadeIn, LoadingDirective } from '@abp/ng.theme.shared';
import { transition, trigger, useAnimation } from '@angular/animations'; import { transition, trigger, useAnimation } from '@angular/animations';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, inject } from '@angular/core';
import { eAccountComponents } from '../../enums/components'; import { eAccountComponents } from '../../enums/components';
import { ManageProfileStateService } from '../../services/manage-profile.state.service'; import { ManageProfileStateService } from '../../services/manage-profile.state.service';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@ -33,6 +33,9 @@ import { ChangePasswordComponent } from '../change-password/change-password.comp
], ],
}) })
export class ManageProfileComponent implements OnInit { export class ManageProfileComponent implements OnInit {
protected profileService = inject(ProfileService);
protected manageProfileState = inject(ManageProfileStateService);
selectedTab = 0; selectedTab = 0;
changePasswordKey = eAccountComponents.ChangePassword; changePasswordKey = eAccountComponents.ChangePassword;
@ -43,11 +46,6 @@ export class ManageProfileComponent implements OnInit {
hideChangePasswordTab?: boolean; hideChangePasswordTab?: boolean;
constructor(
protected profileService: ProfileService,
protected manageProfileState: ManageProfileStateService,
) {}
ngOnInit() { ngOnInit() {
this.profileService.get().subscribe(profile => { this.profileService.get().subscribe(profile => {
this.manageProfileState.setProfile(profile); this.manageProfileState.setProfile(profile);

8
npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings-half-row.component.ts

@ -1,4 +1,4 @@
import { Component, Inject } from '@angular/core'; import { Component, inject } from '@angular/core';
import { import {
EXTENSIONS_FORM_PROP, EXTENSIONS_FORM_PROP,
FormProp, FormProp,
@ -24,12 +24,16 @@ import { LocalizationPipe } from '@abp/ng.core';
imports: [ReactiveFormsModule, LocalizationPipe], imports: [ReactiveFormsModule, LocalizationPipe],
}) })
export class PersonalSettingsHalfRowComponent { export class PersonalSettingsHalfRowComponent {
private propData = inject<FormProp>(EXTENSIONS_FORM_PROP);
public displayName: string; public displayName: string;
public name: string; public name: string;
public id: string; public id: string;
public formGroup!: UntypedFormGroup; public formGroup!: UntypedFormGroup;
constructor(@Inject(EXTENSIONS_FORM_PROP) private propData: FormProp) { constructor() {
const propData = this.propData;
this.displayName = propData.displayName; this.displayName = propData.displayName;
this.name = propData.name; this.name = propData.name;
this.id = propData.id || ''; this.id = propData.id || '';

18
npm/ng-packs/packages/account/src/lib/components/register/register.component.ts

@ -6,7 +6,7 @@ import {
LocalizationPipe, LocalizationPipe,
} from '@abp/ng.core'; } from '@abp/ng.core';
import { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared'; import { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared';
import { Component, Injector, OnInit } from '@angular/core'; import { Component, Injector, OnInit, inject } from '@angular/core';
import { import {
ReactiveFormsModule, ReactiveFormsModule,
UntypedFormBuilder, UntypedFormBuilder,
@ -35,6 +35,13 @@ const { maxLength, required, email } = Validators;
], ],
}) })
export class RegisterComponent implements OnInit { export class RegisterComponent implements OnInit {
protected fb = inject(UntypedFormBuilder);
protected accountService = inject(AccountService);
protected configState = inject(ConfigStateService);
protected toasterService = inject(ToasterService);
protected authService = inject(AuthService);
protected injector = inject(Injector);
form!: UntypedFormGroup; form!: UntypedFormGroup;
inProgress?: boolean; inProgress?: boolean;
@ -43,15 +50,6 @@ export class RegisterComponent implements OnInit {
authWrapperKey = eAccountComponents.AuthWrapper; authWrapperKey = eAccountComponents.AuthWrapper;
constructor(
protected fb: UntypedFormBuilder,
protected accountService: AccountService,
protected configState: ConfigStateService,
protected toasterService: ToasterService,
protected authService: AuthService,
protected injector: Injector,
) {}
ngOnInit() { ngOnInit() {
this.init(); this.init();
this.buildForm(); this.buildForm();

16
npm/ng-packs/packages/account/src/lib/components/reset-password/reset-password.component.ts

@ -1,6 +1,6 @@
import { AccountService } from '@abp/ng.account.core/proxy'; import { AccountService } from '@abp/ng.account.core/proxy';
import { ButtonComponent, getPasswordValidators } from '@abp/ng.theme.shared'; import { ButtonComponent, getPasswordValidators } from '@abp/ng.theme.shared';
import { Component, Injector, OnInit } from '@angular/core'; import { Component, Injector, OnInit, inject } from '@angular/core';
import { import {
ReactiveFormsModule, ReactiveFormsModule,
UntypedFormBuilder, UntypedFormBuilder,
@ -26,6 +26,12 @@ const PASSWORD_FIELDS = ['password', 'confirmPassword'];
], ],
}) })
export class ResetPasswordComponent implements OnInit { export class ResetPasswordComponent implements OnInit {
private fb = inject(UntypedFormBuilder);
private accountService = inject(AccountService);
private route = inject(ActivatedRoute);
private router = inject(Router);
private injector = inject(Injector);
form!: UntypedFormGroup; form!: UntypedFormGroup;
inProgress = false; inProgress = false;
@ -38,14 +44,6 @@ export class ResetPasswordComponent implements OnInit {
return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch')); return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch'));
}; };
constructor(
private fb: UntypedFormBuilder,
private accountService: AccountService,
private route: ActivatedRoute,
private router: Router,
private injector: Injector,
) {}
ngOnInit(): void { ngOnInit(): void {
this.route.queryParams.subscribe(({ userId, resetToken }) => { this.route.queryParams.subscribe(({ userId, resetToken }) => {
if (!userId || !resetToken) this.router.navigateByUrl('/account/login'); if (!userId || !resetToken) this.router.navigateByUrl('/account/login');

Loading…
Cancel
Save