【问题标题】:Get UID and token obtain from password reset in react form以反应形式从密码重置中获取 UID 和令牌
【发布时间】:2019-12-28 12:21:55
【问题描述】:

我正在重置密码并且我使用了 django rest-auth,我已经通过点击 rest-auth/password/reset/ 成功地从电子邮件链接中获取了令牌和 uid,

但为了确认我想要反应形式的令牌和 uid,以便我可以更改它如何获取其余身份验证在反应 js 形式的电子邮件链接中返回的 uid 和令牌

           axios.post('http://127.0.0.1:8000/rest-auth/password/reset/',payload)
        .then(res=>{
            console.log(res)
        })
        .catch(err=>{
            console.log(err)
        })

它工作完美,它返回我:

    http://127.0.0.1:8000/rest-auth/password/reset/confirm/MQ/594-5faaa46be4277e6a1879/

如何从反应形式的 url 中获取 uid 和 token?

【问题讨论】:

  • 使用regex 可能是一种方法,用于提取uid & token

标签: django reactjs django-rest-framework django-rest-auth


【解决方案1】:

您应该配置您的反应路由器以从 url 获取参数。

  e.preventDefault();
        fetch("http://127.0.0.1:8000/rest-auth/password/reset/confirm/", {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            }, body: JSON.stringify({
                "new_password1": this.state.new_password1,
                "new_password2": this.state.new_password2,
                "uid": this.props.match.params.uid,
                "token": this.props.match.params.token,
            })
        })
            // .then(response => response.json())
            .then(response => {
                console.log(response)
            })
            .catch(error => {
                console.log(error)
            })

【讨论】:

    猜你喜欢
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多