0

我设法显示了当前用户的电子邮件,但是如何获取用户 ID?

Template:
<div *ngIf="!hasLoggedIn">
   {{ (profile$ | async)?.email }}
</div>

TypeScript:
import { Profile, GetProfile, ProfileState, } from '@abp/ng.core';       

export class Component implements OnInit {
   @Select(ProfileState.getProfile) //State
   profile$: Observable<Profile.Response>;  //Model

   get hasLoggedIn(): boolean {
      return this.oAuthService.hasValidAccessToken();
   }

   constructor(private oAuthService: OAuthService) {}

   ngOnInit() {
   this.store.dispatch(new GetProfile()).subscribe(); //Action
   }
}

里面app-routing.module.ts有 import of ApplicationLayoutComponent,里面有一个变量声明,currentUser $: Observable <ApplicationConfiguration.CurrentUser>;用于在导航栏中显示用户名,在ApplicationConfiguration模型内部有一个 Id,但我无法像使用电子邮件那样实现它

Ps:对不起我的英语

4

2 回答 2

0

您可以使用GetCurrentLoginInformations(),它位于SessionServiceProxy中。它返回一个包含UserLoginInfoDto的对象,其中包含电子邮件、姓名等

于 2020-02-11T05:11:43.090 回答
-1
public async Task LinkToUser(LinkToUserInput input)
{
    var loginResult = await _logInManager.LoginAsync(input.UsernameOrEmailAddress, input.Password, input.TenancyName);

    if (loginResult.Result != AbpLoginResultType.Success)
    {
        throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, input.UsernameOrEmailAddress, input.TenancyName);
    }

    if (AbpSession.IsUser(loginResult.User))
    {
        throw new UserFriendlyException(L("YouCannotLinkToSameAccount"));
    }

    if (loginResult.User.ShouldChangePasswordOnNextLogin)
    {
        throw new UserFriendlyException(L("ChangePasswordBeforeLinkToAnAccount"));
    }

    await _userLinkManager.Link(GetCurrentUser(), loginResult.User);
}
于 2022-02-08T09:09:37.980 回答