Javascript 我在reactjs上创建了登记表,我的登记表似乎有效,但我没有';我没有收到任何电子邮件验证
正如标题所说,我使用react js创建了注册表单,在完成填写表单并链接到另一个页面时,它开始工作。但问题是,在用户填写完所有表单后,它会自动发送电子邮件验证,而我没有收到任何电子邮件验证。有人能帮我解决这个问题吗,我还是个新手。任何帮助都将不胜感激 如果有人想知道:Javascript 我在reactjs上创建了登记表,我的登记表似乎有效,但我没有';我没有收到任何电子邮件验证,javascript,reactjs,Javascript,Reactjs,正如标题所说,我使用react js创建了注册表单,在完成填写表单并链接到另一个页面时,它开始工作。但问题是,在用户填写完所有表单后,它会自动发送电子邮件验证,而我没有收到任何电子邮件验证。有人能帮我解决这个问题吗,我还是个新手。任何帮助都将不胜感激 如果有人想知道: import React, { Component } from 'react'; import {Redirect, Link, router } from 'react-router-dom'; import
import React, { Component } from 'react';
import {Redirect, Link, router } from 'react-router-dom';
import './SignUp.css';
import axios from 'axios';
export default class Login extends Component {
componentDidMount() {
window.scrollTo(0, 0)
}
constructor(props) {
super(props);
this.state={
company: '',
province: '',
city: '',
website: '',
address: '',
contact:'',
password:'',
email:'',
errors: {}
}
this.handleChangeCompany = this.handleChangeCompany.bind(this);
this.handleChangeWebsite = this.handleChangeWebsite.bind(this);
this.handleChangeProvince = this.handleChangeProvince.bind(this);
this.handleChangeCity= this.handleChangeCity.bind(this);
this.handleChangeAddress = this.handleChangeAddress.bind(this);
this.handleChangeMobile = this.handleChangeMobile.bind(this);
this.handleChangeEmail = this.handleChangeEmail.bind(this);
this.handleChangePassword = this.handleChangePassword.bind(this);
this.submituserRegistrationForm = this.submituserRegistrationForm.bind(this);
}
handleChangeWebsite(e) {
this.setState({website:e.target.value});
}
handleChangeProvince(e) {
this.setState({province:e.target.value});
}
handleChangeCity(e) {
this.setState({city:e.target.value});
}
handleChangeCompany(e) {
this.setState({company:e.target.value});
}
handleChangeAddress(e) {
this.setState({address:e.target.value});
}
handleChangeEmail(e) {
this.setState({email:e.target.value});
}
handleChangeMobile(e) {
this.setState({contact:e.target.value});
}
handleChangePassword(e) {
this.setState({password:e.target.value});
}
submituserRegistrationForm(e) {
e.preventDefault();
if (this.validateForm()) {
var apiBaseUrl = "http://THIS_IS_MY_API_:3000";
var data={
"query":"mutation{ createProfile( profileInput :{company: \""+this.state.company+"\", address: \""+this.state.address+"\", email: \""+this.state.email+"\", contact: \""+this.state.contact+"\", province: \""+this.state.province+"\", city: \""+this.state.city+"\", website: \"\", operational: 24, password: \""+this.state.password+"\"}){ _id company address city province email contact website logo createdAt updatedAt } }"
}
/*console.log(data);*/
var headers = {
'Content-Type': 'application/json',
}
axios.post(apiBaseUrl, data, {headers: headers}).then(function (response) {
if(response.data.data){
console.log(response.data.data);
localStorage.setItem("u_code", encodeURIComponent(JSON.stringify(response.data.data)));
localStorage.setItem('is_done', true);
window.location.href = "/login";
console.log("Sign Up successfull");
}else{
alert(response.data.message);
}
}).catch(function (error) {
console.log(error);
});
}
}
validateForm() {
let errors = {};
let formIsValid = true;
return formIsValid;
}
render() {
return (
<div className="container-fluid">
<div className="row no-gutter">
<div className="d-none d-md-flex col-md-4 col-lg-6 bg-image" />
<div className="col-md-8 col-lg-6">
<div className="login d-flex align-items-center py-5">
<div className="container">
<div className="row">
<div className="col-md-9 col-lg-8 mx-auto">
<h3 className="login-heading mb-4">Sign Up Now!</h3>
<form method="post" name="userRegistrationForm" onSubmit= {this.submituserRegistrationForm}>
<br></br>
<h5 className="login-heading mb-4"><u>Company</u></h5>
<div className="form-label-group">
<input name="company" value={this.state.company} onChange={this.handleChangeCompany} id="company" className="form-control" placeholder="Company" required autofocus />
<label htmlFor="company">Company</label>
</div>
<br></br>
<h5 className="login-heading mb-4"><u>City</u></h5>
<div className="form-label-group">
<input name="City" value={this.state.city} onChange={this.handleChangeCity} className="form-control" placeholder="City" required autofocus />
<label>City</label>
</div>
<br></br>
<h5 className="login-heading mb-4"><u>Address</u></h5>
<div className="form-label-group">
<input name="address" value={this.state.address} onChange={this.handleChangeAddress} className="form-control" placeholder="Address" required autofocus />
<label>Address</label>
</div>
<br></br>
<h5 className="login-heading mb-4"><u>Province</u></h5>
<div className="form-label-group">
<input name="Province" value={this.state.province} onChange={this.handleChangeProvince} className="form-control" placeholder="Province" required autofocus />
<label >Province</label>
</div>
<br></br>
<h5 className="login-heading mb-4"><u>Email Address</u></h5>
<div className="form-label-group">
<input name="email" value={this.state.email} onChange={this.handleChangeEmail} className="form-control" placeholder="Email" required autofocus />
<label>Email</label>
</div>
<br></br>
<h5 className="login-heading mb-4"><u>Contact</u></h5>
<div className="form-label-group">
<input name="contact" value={this.state.contact} onChange={this.handleChangeMobile} className="form-control" placeholder="Contact Number" required autofocus />
<label>Contact</label>
</div>
<br></br>
<h5 className="login-heading mb-4"><u>Password</u></h5>
<div className="form-label-group">
<input type="password" value={this.state.password} onChange={this.handleChangePassword} name="password" id="inputPassword" className="form-control" placeholder="Password" required />
<label htmlFor="inputPassword">Password</label>
</div>
<br></br>
<button value="Login" className="btn btn-lg btn-primary btn-block btn-login text-uppercase font-weight-bold mb-2" type="submit">Sign Up</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
}
import React,{Component}来自'React';
从“react router dom”导入{重定向、链接、路由器};
导入“./SignUp.css”;
从“axios”导入axios;
导出默认类登录扩展组件{
componentDidMount(){
滚动到(0,0)
}
建造师(道具){
超级(道具);
这个州={
公司:'',
省:'',
城市:'',
网站:'',
地址:'',
联系人:'',
密码:“”,
电子邮件:“”,
错误:{}
}
this.handleChangeCompany=this.handleChangeCompany.bind(this);
this.handleChangeWebsite=this.handleChangeWebsite.bind(this);
this.handleChangeProvince=this.handleChangeProvince.bind(this);
this.handleChangeCity=this.handleChangeCity.bind(this);
this.handleChangeAddress=this.handleChangeAddress.bind(this);
this.handleChangeMobile=this.handleChangeMobile.bind(this);
this.handlechangemail=this.handlechangemail.bind(this);
this.handleChangePassword=this.handleChangePassword.bind(this);
this.submituserRegistrationForm=this.submituserRegistrationForm.bind(this);
}
HandleChange网站(e){
this.setState({website:e.target.value});
}
汉德尔昌省(东){
this.setState({province:e.target.value});
}
汉德尔昌市(东){
this.setState({city:e.target.value});
}
HandleChange公司(e){
this.setState({company:e.target.value});
}
handleChangeAddress(e){
this.setState({地址:e.target.value});
}
HandleChange电子邮件(e){
this.setState({email:e.target.value});
}
手提电话(e){
this.setState({contact:e.target.value});
}
handleChangePassword(e){
this.setState({密码:e.target.value});
}
提交注册表格(e){
e、 预防默认值();
if(this.validateForm()){
var apiBaseUrl=”http://THIS_IS_MY_API_:3000";
var数据={
“查询:”{createProfile(profileInput:{company:\”“+this.state.company+“\”,地址:\”“+this.state.address+“\”,电子邮件:\”“+this.state.email+“\”,联系人:\”“+this.state.contact+“\”,省份:\”“+this.state.province+“\”,城市:\”“+this.state.city+“\”,网站:\“\”,操作:24,密码:\”“+this.state.password+”){{u id公司地址城市省电子邮件联系网站logo createdAt updatedAt}”
}
/*控制台日志(数据)*/
变量头={
“内容类型”:“应用程序/json”,
}
post(apiBaseUrl,data,{headers:headers}).then(函数(响应){
if(response.data.data){
日志(response.data.data);
setItem(“u_代码”,encodeURIComponent(JSON.stringify(response.data.data));
setItem('is_done',true);
window.location.href=“/login”;
console.log(“注册成功”);
}否则{
警报(响应、数据、消息);
}
}).catch(函数(错误){
console.log(错误);
});
}
}
validateForm(){
让错误={};
让formIsValid=true;
返回formIsValid;
}
render(){
返回(
现在就报名吧!
单位
单位
城市
城市
地址
地址
省
省
电子邮件地址
电子邮件
接触
接触
密码
密码
注册
);
}
}
代码似乎没什么问题,只是我把Json web令牌放错了位置。
正确的答案是这样的:
const getJWT = () => {
return localStorage.getItem('token');
};
const jwt = getJWT();
if (!jwt){
window.location.href = "/";
};
'Authorization' : 'Tesla '+jwt+''
相反,它创建了另一个令牌,这就是服务器无法识别令牌的原因:
localStorage.setItem("u_code", encodeURIComponent(JSON.stringify(response.data.data)));
localStorage.setItem('is_done', true);
在标题中,我只是将jwt放在如下位置:
const getJWT = () => {
return localStorage.getItem('token');
};
const jwt = getJWT();
if (!jwt){
window.location.href = "/";
};
'Authorization' : 'Tesla '+jwt+''
电子邮件发送方法在哪里?在你的代码中,只有一个API的帖子。电子邮件发送方法在你的API上吗?@silentw另外,当我填写所有表单时,我尝试使用电子邮件登录,但它不起作用。我总是收到电子邮件和密码错误,就像服务器无法识别我刚才输入的电子邮件和密码一样input@silentw我的