Делал регистрацию в интенет-магазин.Если через Postman делать то все хорошо, а если через сайт то пошучаю ошибку http://localhost:8081/user/signup 500 (Internal Server Error)
. Вот мой код:
<b-modal id="modal2" title="SignUp" size="lg" hide-header hide-footer ok-disabled cancel-disabled>
<p class="my-4">
<b-form-input id="input-default" type="text" placeholder="Enter your email" v-model="regEmail"></b-form-input>
<b-form-input id="input-default" type="password" placeholder="Enter your password" v-model="regPassword"></b-form-input>
<b-form-input id="input-default" type="password" placeholder="Repeat you password" v-model="regSecPassword"></b-form-input>
<b-button @click="regIn()">SignUp</b-button>
</p>
</b-modal>
import axios from 'axios';
export default {
data () {
return {
isLogged : false,
regEmail:'',
regPassword:'',
regSecPassword:'',
authEmail:'',
authPassword:'',
errors:[]
}
},
methods:{
register: function (){
if (!this.regEmail) this.errors.push('Укажите почту')
if (!this.regPassword) this.errors.push('Укажите пароль')
if (!this.regSecPassword) this.errors.push('Укажите повторно пароль')
if (!this.regPassword != this.regSecPassword) this.errors.push('Пароли не совпадают')
},
auth:function (){
if (!this.authEmail) this.errors.push('Укажите почту')
if (!this.authPassword) this.errors.push('Укажите пароль')
},
validEmail: function(email) {
const expression = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return expression.test(email)
},
regIn: function() {
const email = this.regEmail
const password = this.regPassword
axios.post('http://localhost:8081/user/signup', {
body: {
email: email,
password: password
}
}).then(res => {
this.$store.state.Logged = true
}).catch(err => {
console.log(err)
})
}
},
computed:{
getUserEmail(){
return this.$store.getters.getUser.email
}
}
}
</script>
Серверная часть:
router.post('/signup',(req, res, next)=>{
User.find({email:req.body.email})
.then(user => {
if(user.length >= 1){
return res.status(409).json({
message: 'Email exists'
})
}else{
bcrypt.hash(req.body.password, 10, (err,hash) =>{
if (err) {
return res.status(500).json({
error:err
})
} else {
const user = new User({
_id: new mongoose.Types.ObjectId(),
email: req.body.email,
password: hash
})
user.save()
.then(result => {
res.status(200).json({
message: 'user created'
})
})
.catch(err => {
res.status(500).json({
error: err
})
})
}
})
}
})
})
Подскажите пожалуста что не так и как исправить?
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Мне пришлось работать со специалистом в команде, который пытается подбить меня использовать построенные им сервисыНо что-то мне синтаксис...
У меня есть таблицаНе подскажете, как при нажатии на Save сделать так, чтобы страница обновлялась? Используется Datatables
Сайт на aspnet mvc, нужно сделать звуковое сопровождение если новые данные добавились в таблицу
Как на картинке нужно чтобы стрелки находились в каком-либо блоке оберткеА этот сам блок был в контейнере контента