Net Core + Angular-电子邮件确认令牌

时间:2019-02-21 12:05:59

标签: angular asp.net-core

我在更改密码所需的网络核心中生成一个令牌,该令牌被发送到电子邮件,然后单击电子邮件中的链接后,它将移到有角的首页,这将执行API请求以确认电子邮件地址,不幸的是问题是API的令牌已更改,即,在以上两个令牌中看不到+,即一个令牌。它的第一个版本是API中生成的版本,第二个版本是从前端到达API的令牌。我不知道该如何处理。我知道问题出在前面,因为这是他要求激活电子邮件的原因。

生成的令牌:

CfDJ8BUjSrrXE9xEiTFPyVuPcKDsxGyY81gv4tiZ+Y8Ntrx6PPMGmhqgpDUI7Kbpuc5PZz/YcudD/SWYSGqeniyPlpZGxfgclYwNtm/3Ef3uHUTajlrs61yMPEVA/g0yLWzaHkkxitckXYdclgK8RyUEA3s4rnJ9xP1ihHlkPFZNgn5cC4q/x/oSgjxBAysGaoBM192TfS9dhGDeKR4YqYBVQEYQKnmtljkdKdgt21z0d4zGaW0rHBOn/GtLIrGXwcokng==

获得的令牌

CfDJ8BUjSrrXE9xEiTFPyVuPcKDsxGyY81gv4tiZ Y8Ntrx6PPMGmhqgpDUI7Kbpuc5PZz/YcudD/SWYSGqeniyPlpZGxfgclYwNtm/3Ef3uHUTajlrs61yMPEVA/g0yLWzaHkkxitckXYdclgK8RyUEA3s4rnJ9xP1ihHlkPFZNgn5cC4q/x/oSgjxBAysGaoBM192TfS9dhGDeKR4YqYBVQEYQKnmtljkdKdgt21z0d4zGaW0rHBOn/GtLIrGXwcokng==

我发送请求的代码:

 ngOnInit() {
    this.activateRouted.queryParamMap.subscribe(params => {
    let code = params.get("confirmationToken");
    let userId = params.get("id");

      if (code != null && userId != null){
        this.userService.confirmEmail(userId,code).subscribe((data: any) => this.confirmSuccess(data), 
        (err: HttpErrorResponse) => this.confirmError(err));
      }
    });
  }

userService的confirmEmail方法:

  public confirmEmail(userId: string, code: string) {
    const req = this.apiService.get(`/api/register/confirm/?id=${userId}&confirmationToken=${code}`);
    return req;
  }

1 个答案:

答案 0 :(得分:0)

如果有人遇到类似的问题,我给出解决方案: encodeURIComponent 到令牌参数:)现在一切正常,

public confirmEmail(userId: string, code: string) {
    const req = this.apiService.get(`/api/register/confirm/?id=${userId}&confirmationToken=${encodeURIComponent(code)}`);
    console.log(req);
    return req;
  }