gpt4 book ai didi

email - meteor 电子邮件验证

转载 作者:行者123 更新时间:2023-12-02 07:19:06 27 4
gpt4 key购买 nike

我正在尝试使用本教程在我的项目中进行电子邮件验证: https://themeteorchef.com/tutorials/sign-up-with-email-verification

我有方法:

//server/methods/send-email.js

import { Meteor } from 'meteor/meteor';
import { Email } from 'meteor/email';

Meteor.methods({
sendVerificationLink() {
let userId = Meteor.userId();
if ( userId ) {
console.log("Email has been sent");
return Accounts.sendVerificationEmail( userId );
}
}
});

然后在客户端调用这个方法:

//client/form.js

handleSubmit = () => {
this.validateField('phone', this.state.phone)
if (this.state.formValid) {
this.update_User({phone: this.state.phone});
}
Meteor.call( 'sendVerificationLink', ( error, response ) => {
if ( error ) {
console.log(error);
} else {
console.log("- There is no errors in Meteor.call -");
}
});

}

我收到一封带有链接的电子邮件。但是当我访问此链接时,什么也没有发生。Meteor.user().emails[ 0 ].verified - 不成立。

{Meteor.user().emails[ 0 ].verified ? <div>Success</div> : <div>Failed</div>}

我没有收到成功文本。

我已经试过了:

import { Meteor } from 'meteor/meteor';

Accounts.emailTemplates.siteName = "name";
Accounts.emailTemplates.from = "name<admin@name.io>";

Accounts.emailTemplates.verifyEmail = {
subject() {
return "[name] Verify Your Email Address";
},
text( user, url ) {
let emailAddress = user.emails[0].address,
urlWithoutHash = url.replace( '#/', '' ),
supportEmail = "support@cryptocean.io",
emailBody = `To verify your email address (${emailAddress}) visit the following link:\n\n${urlWithoutHash}\n\n If you did not request this verification, please ignore this email. If you feel something is wrong, please contact our support team: ${supportEmail}.`;

return emailBody;
}
};

Accounts.onEmailVerificationLink = function() {
console.log("Verified");
user.emails[0].verified = true;
}

但是我好像做错了什么。

我在 Meteor/后端方面不是很有经验......所以我真的希望能在这里找到一些帮助。想象一下电影《穿 Boot 的猫》中的猫正在深入你的灵魂。现在就是我))

最佳答案

正如 Deepak 所建议的,在 React 路由器中会是这样的:

<Route exact path='/reset-password/:token' component={ResetPasswordPage} />
<Route exact path='/verify-email/:token' component={VerifyEmailPage} />

并且 VerifyEmailPage 可能看起来像:

import React, { Component } from 'react'

import { Accounts } from 'meteor/accounts-base'

export default class VerifyEmailPage extends Component {

componentDidMount () {

const token = this.props.match.params.token
Accounts.verifyEmail(token, (err) => {
if (err) {
toastr.error('Could not verify email!', err.reason)
} else {
toastr.success('Email confirmed successfully!')
this.props.history.push('/feeds')
}
})
}

render () {
return (
<div>{''}</div>
)
}
}

关于email - meteor 电子邮件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50929836/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com