【问题标题】:how do i display change password form with angular我如何使用角度显示更改密码表单
【发布时间】:2021-10-17 04:48:30
【问题描述】:

晕, 我正在开发一个带有忘记密码功能的 drf 和 A​​ngular 项目,其中用户通过电子邮件请求更改密码链接,这是有效的,但我的问题是在链接发送到他们用户的电子邮件后,我如何显示将允许用户更改他/她的密码,通过他们生成令牌和 uid 参数以确保用户可以更改密码 下面是我的代码sn-ps

#apiView

class RequestPasswordResetAPIView(generics.GenericAPIView):
    serializers_class = RequestNewPasswordSerializer

    def post(self, request):
        serializer = self.serializers_class(data=request.data)
        email = request.data['email']
        if CustomUser.objects.filter(email=email).exists():
            user = CustomUser.objects.get(email=email)
            uidb64 = urlsafe_base64_encode(smart_bytes(user.id))
            token = PasswordResetTokenGenerator().make_token(user)
            current_site = get_current_site(request=request).domain
            dRelativeLink = reverse(
                'register:password-reset-confirmed', kwargs={'uidb64': uidb64, 'token': token})
            django_absUrl = 'http://' + current_site + dRelativeLink
            body = 'Hi  Click on the Link below to change your password \n' + django_absUrl

###url

path('password-reset/<uidb64>/<token>/',
         PasswordTokenAPIView.as_view(), name='password-reset-confirmed'),

###密码重置链接

http://localhost:8000/account/password-reset/Mw/arcyok-59633b395b8746c3bfe2efafd613b033/

角度路由配置

 getPasswordToken(token, uidb64) {
    const url = `localhost:4200/account/${uidb64}/${token}/update-password`
    return this.httpClient.get(url)
  }

问题是我不知道如何将 uidb64 和令牌传递给 url 当我单击此链接时,我将重定向到此链接的 drf 视图,但我想要重定向到更改密码的角度形式,然后此表单将调用此

http://localhost:8000/account/password-reset/Mw/arcyok-59633b395b8746c3bfe2efafd613b033/

请问谁能做到这一点?

【问题讨论】:

    标签: angular django-rest-framework angular-ui-router


    【解决方案1】:

    你能分享你在哪个端口上运行角度服务器吗?还有这个特定页面的路由配置。我假设其中任何一个都缺少一些东西。
    更新: 试试这个。

    1. 将密码重置链接更改为此,这样当用户单击链接时,表单就会打开。
    http://localhost:4200/account/password-reset/Mw/arcyok-59633b395b8746c3bfe2efafd613b033/
    
    1. 当用户提交带有更新密码的表单时,您可以调用这个
    http://localhost:8000/account/password-reset/Mw/arcyok-59633b395b8746c3bfe2efafd613b033/
    

    可选:您可以像这样以角度配置路线

    • {path: 'account/password-reset/:uid/:token', component: ResetPasswordComponent},订阅密码重置组件中的路由参数。
    • {path: 'reset_password',component: ForgotPasswordComponent},将 uid 和令牌作为查询参数传递并在密码重置组件中订阅它们。

    【讨论】:

    • 我已经更新了我的答案,希望它有效:)
    • 很高兴听到它:) 你能把它标记为接受吗..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    相关资源
    最近更新 更多