Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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
- })
- })
- }
- })
- }
- })
- })
Add Comment
Please, Sign In to add comment