abp icon indicating copy to clipboard operation
abp copied to clipboard

How to replace or Customize AccountController

Open mehdihadeli opened this issue 6 years ago • 13 comments

Hi, I want to customize existing abp AccountController on this route api/account, is it possible? I want to customize the register method in this controller and add some extra conditions.

mehdihadeli avatar Mar 15 '20 18:03 mehdihadeli

Is this the controller?

https://github.com/abpframework/abp/blob/ac582a519ac76e1bce0b892cc52587b1976f0f51/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs#L11

maliming avatar Mar 16 '20 06:03 maliming

Is this the controller?

https://github.com/abpframework/abp/blob/ac582a519ac76e1bce0b892cc52587b1976f0f51/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs#L11

@maliming Yes, this is my app dependencies:

[DependsOn(
        typeof(AbpAutofacModule),
        typeof(AbpAutoMapperModule),
        typeof(AbpAuditLoggingEntityFrameworkCoreModule),
        typeof(AbpSettingManagementEntityFrameworkCoreModule),
        typeof(AbpAspNetCoreMvcUiBasicThemeModule),
        typeof(AbpLdapModule)
    )]

why swagger generate other api definition like Account api or Tenant Api? I don't have dependency to these modules. 1

mehdihadeli avatar Mar 16 '20 11:03 mehdihadeli

AccountController just calls IAccountAppService. You can replace IAccountAppService.

why swagger generate other api definition like Account api or Tenant Api? I don't have dependency to these modules.

The account module depends on the identity module.

maliming avatar Mar 17 '20 01:03 maliming

Ok, Replacing IAccountAppService is a good idea, but as I said I removed both the Identity module and account module from my app dependencies for test purpose, but swagger still generates docs for these APIs !

[DependsOn(
        typeof(AbpAutofacModule),
        typeof(AbpAutoMapperModule),
        typeof(AbpAuditLoggingEntityFrameworkCoreModule),
        typeof(AbpSettingManagementEntityFrameworkCoreModule),
        typeof(AbpAspNetCoreMvcUiBasicThemeModule),
        typeof(AbpLdapModule)
    )]

here I don't have any dependecies to account or identity but swagger docs will generate.

mehdihadeli avatar Mar 17 '20 11:03 mehdihadeli

I have one question related to replacing the AccountController. I need to override de login from Account, image but it uses AccountController from Volo.Abp.Account.Web.Areas.Account.Controllers, not the one in the comments (https://github.com/abpframework/abp/issues/3132#issuecomment-599363769) and it doesn't call IAccountAppService (this one doesn't have login) I tried to create another AbpController pointing to the same route and inheritingAccountController but swagger gives error because duplicated endpoints. How can I replace the "original" login endpoint? because this is which my angular app points to. image

luisp88 avatar Mar 17 '20 16:03 luisp88

@luisp88

Overriding controllers, framework services, view component classes and any other type of classes registered to dependency injection can be overridden just like the examples above.

https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services

maliming avatar Mar 18 '20 06:03 maliming

@maliming Do you have any solution for the swagger problem that I mentioned above?

mehdihadeli avatar Mar 18 '20 12:03 mehdihadeli

@mehdihadeli Can you provider a test project?

maliming avatar Mar 19 '20 01:03 maliming

@maliming Yes

test.zip

mehdihadeli avatar Mar 19 '20 10:03 mehdihadeli

I moved my swagger problem to a new thread here: https://github.com/abpframework/abp/issues/3335 My problem for this thread resolved with @maliming guides, thanks.

mehdihadeli avatar Mar 24 '20 11:03 mehdihadeli

@maliming If I want to replace also AccountController instead of just replacing AccountAppService because I have different input dto, for example, ExtendedRegisterDto for RegisterAsync method, what I do?

In this link that you mentioned, there is no sample for the controller. https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services

mehdihadeli avatar Apr 04 '20 15:04 mehdihadeli

because I have different input dto, for example, ExtendedRegisterDto for RegisterAsync method, what I do?

Please follow: https://github.com/abpframework/abp/issues/3405

maliming avatar Apr 07 '20 00:04 maliming

Ok thanks.

mehdihadeli avatar Apr 07 '20 11:04 mehdihadeli