我正在尝试使用此教程在我的项目中进行电子邮件验证: 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 /后端方面不是很有经验...所以我真的希望在这里找到一些帮助。想象一下猫从“靴子里的猫”电影深入您的灵魂。现在就是我))
答案 0 :(得分:3)
像Deepak建议的那样,在React Router中应该是这样的:
<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>
)
}
}
答案 1 :(得分:2)
您如何删除其中的“返回”
<script>
// Initialize and add the map
function initMap() {
var uluru = {lat: 41.9973, lng: 21.4280};
// The map, centered at Uluru
var map = new google.maps.Map(
document.getElementById('map'), {zoom: 14, center: uluru});
// The marker, positioned at Uluru
// var marker = new google.maps.Marker({position: uluru, map: map});
function addMarker(props){
var marker = new google.maps.Marker({
position:props.coords,
map:map
//icon:props.iconImage
});
// Check for customicon
if(props.iconImage){
// Set icon image
marker.setIcon(props.iconImage);
}
// Check content
if(props.content){
var infoWindow = new google.maps.InfoWindow({
content:props.content
});
}
}
}
</script>
<h3>My Google Maps Demo</h3>
<!--The div element for the map -->
<div id="map"></div>
<button onclick="initMap.addMarker({ coords:{lat:Lat,lng:Long}, content:'<h1>bla bla content</h1>'})">Stavi Marker</button>
然后重试。
干杯, P
答案 2 :(得分:2)