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 { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import type { IdentityUserDto } from '../identity/models';
@Injectable({
providedIn: 'root',
})
export class AccountService {
private restService = inject(RestService);
apiName = 'AbpAccount';
register = (input: RegisterDto) =>
@ -32,6 +34,4 @@ export class AccountService {
body: input,
},
{ 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 { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class ProfileService {
private restService = inject(RestService);
apiName = 'AbpAccount';
changePassword = (input: ChangePasswordInput) =>
@ -30,6 +32,4 @@ export class ProfileService {
body: input,
},
{ 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 { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class AccountService {
private restService = inject(RestService);
apiName = 'AbpAccount';
checkPasswordByLogin = (login: UserLoginInfo) =>
@ -30,6 +32,4 @@ export class AccountService {
url: '/api/account/logout',
},
{ 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 { map } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
@ -6,6 +6,9 @@ import { ConfigStateService, MultiTenancyService } from '@abp/ng.core';
@Injectable()
export class AuthWrapperService {
readonly multiTenancy = inject(MultiTenancyService);
private configState = inject(ConfigStateService);
isMultiTenancyEnabled$ = this.configState.getDeep$('multiTenancy.isEnabled');
get enableLocalLogin$(): Observable<boolean> {
@ -25,11 +28,9 @@ export class AuthWrapperService {
return this.isTenantBoxVisibleForCurrentRoute && this.multiTenancy.isTenantBoxVisible;
}
constructor(
public readonly multiTenancy: MultiTenancyService,
private configState: ConfigStateService,
injector: Injector,
) {
constructor() {
const injector = inject(Injector);
this.route = injector.get(ActivatedRoute);
}

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

@ -5,11 +5,16 @@ import {
SessionStateService,
} from '@abp/ng.core';
import { ToasterService } from '@abp/ng.theme.shared';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { finalize } from 'rxjs/operators';
@Injectable()
export class TenantBoxService {
private toasterService = inject(ToasterService);
private tenantService = inject(AbpTenantService);
private sessionState = inject(SessionStateService);
private configState = inject(ConfigStateService);
currentTenant$ = this.sessionState.getTenant$();
name?: string;
@ -18,13 +23,6 @@ export class TenantBoxService {
modalBusy!: boolean;
constructor(
private toasterService: ToasterService,
private tenantService: AbpTenantService,
private sessionState: SessionStateService,
private configState: ConfigStateService,
) {}
onSwitch() {
const tenant = this.sessionState.getTenant();
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 { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared';
import { Component, Injector, OnInit } from '@angular/core';
import { Component, Injector, OnInit, inject } from '@angular/core';
import {
ReactiveFormsModule,
UntypedFormBuilder,
@ -32,6 +32,12 @@ const PASSWORD_FIELDS = ['newPassword', 'repeatNewPassword'];
export class ChangePasswordComponent
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;
inProgress?: boolean;
@ -44,14 +50,6 @@ export class ChangePasswordComponent
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 {
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 { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import {
ReactiveFormsModule,
UntypedFormBuilder,
@ -24,16 +24,16 @@ import { NgxValidateCoreModule } from '@ngx-validate/core';
],
})
export class ForgotPasswordComponent {
private fb = inject(UntypedFormBuilder);
private accountService = inject(AccountService);
form: UntypedFormGroup;
inProgress?: boolean;
isEmailSent = false;
constructor(
private fb: UntypedFormBuilder,
private accountService: AccountService,
) {
constructor() {
this.form = this.fb.group({
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 { fadeIn, LoadingDirective } from '@abp/ng.theme.shared';
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 { ManageProfileStateService } from '../../services/manage-profile.state.service';
import { CommonModule } from '@angular/common';
@ -33,6 +33,9 @@ import { ChangePasswordComponent } from '../change-password/change-password.comp
],
})
export class ManageProfileComponent implements OnInit {
protected profileService = inject(ProfileService);
protected manageProfileState = inject(ManageProfileStateService);
selectedTab = 0;
changePasswordKey = eAccountComponents.ChangePassword;
@ -43,11 +46,6 @@ export class ManageProfileComponent implements OnInit {
hideChangePasswordTab?: boolean;
constructor(
protected profileService: ProfileService,
protected manageProfileState: ManageProfileStateService,
) {}
ngOnInit() {
this.profileService.get().subscribe(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 {
EXTENSIONS_FORM_PROP,
FormProp,
@ -24,12 +24,16 @@ import { LocalizationPipe } from '@abp/ng.core';
imports: [ReactiveFormsModule, LocalizationPipe],
})
export class PersonalSettingsHalfRowComponent {
private propData = inject<FormProp>(EXTENSIONS_FORM_PROP);
public displayName: string;
public name: string;
public id: string;
public formGroup!: UntypedFormGroup;
constructor(@Inject(EXTENSIONS_FORM_PROP) private propData: FormProp) {
constructor() {
const propData = this.propData;
this.displayName = propData.displayName;
this.name = propData.name;
this.id = propData.id || '';

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

@ -6,7 +6,7 @@ import {
LocalizationPipe,
} from '@abp/ng.core';
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 {
ReactiveFormsModule,
UntypedFormBuilder,
@ -35,6 +35,13 @@ const { maxLength, required, email } = Validators;
],
})
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;
inProgress?: boolean;
@ -43,15 +50,6 @@ export class RegisterComponent implements OnInit {
authWrapperKey = eAccountComponents.AuthWrapper;
constructor(
protected fb: UntypedFormBuilder,
protected accountService: AccountService,
protected configState: ConfigStateService,
protected toasterService: ToasterService,
protected authService: AuthService,
protected injector: Injector,
) {}
ngOnInit() {
this.init();
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 { ButtonComponent, getPasswordValidators } from '@abp/ng.theme.shared';
import { Component, Injector, OnInit } from '@angular/core';
import { Component, Injector, OnInit, inject } from '@angular/core';
import {
ReactiveFormsModule,
UntypedFormBuilder,
@ -26,6 +26,12 @@ const PASSWORD_FIELDS = ['password', 'confirmPassword'];
],
})
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;
inProgress = false;
@ -38,14 +44,6 @@ export class ResetPasswordComponent implements OnInit {
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 {
this.route.queryParams.subscribe(({ userId, resetToken }) => {
if (!userId || !resetToken) this.router.navigateByUrl('/account/login');

Loading…
Cancel
Save