Guest User

Untitled

a guest
Jun 19th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. <b-modal id="modal2" title="SignUp" size="lg" hide-header hide-footer ok-disabled cancel-disabled>
  2. <p class="my-4">
  3. <b-form-input id="input-default" type="text" placeholder="Enter your email" v-model="regEmail"></b-form-input>
  4. <b-form-input id="input-default" type="password" placeholder="Enter your password" v-model="regPassword"></b-form-input>
  5. <b-form-input id="input-default" type="password" placeholder="Repeat you password" v-model="regSecPassword"></b-form-input>
  6. <b-button @click="regIn()">SignUp</b-button>
  7. </p>
  8. </b-modal>
  9.  
  10. import axios from 'axios';
  11.  
  12. export default {
  13. data () {
  14. return {
  15. isLogged : false,
  16. regEmail:'',
  17. regPassword:'',
  18. regSecPassword:'',
  19. authEmail:'',
  20. authPassword:'',
  21. errors:[]
  22.  
  23. }
  24. },
  25. methods:{
  26. register: function (){
  27. if (!this.regEmail) this.errors.push('Укажите почту')
  28. if (!this.regPassword) this.errors.push('Укажите пароль')
  29. if (!this.regSecPassword) this.errors.push('Укажите повторно пароль')
  30. if (!this.regPassword != this.regSecPassword) this.errors.push('Пароли не совпадают')
  31. },
  32. auth:function (){
  33. if (!this.authEmail) this.errors.push('Укажите почту')
  34. if (!this.authPassword) this.errors.push('Укажите пароль')
  35. },
  36. validEmail: function(email) {
  37. 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,}))$/
  38. return expression.test(email)
  39. },
  40. regIn: function() {
  41. const email = this.regEmail
  42. const password = this.regPassword
  43.  
  44. axios.post('http://localhost:8081/user/signup', {
  45. body: {
  46. email: email,
  47. password: password
  48. }
  49. }).then(res => {
  50. this.$store.state.Logged = true
  51. }).catch(err => {
  52. console.log(err)
  53. })
  54. }
  55. },
  56. computed:{
  57. getUserEmail(){
  58. return this.$store.getters.getUser.email
  59. }
  60. }
  61. }
  62. </script>
  63.  
  64. router.post('/signup',(req, res, next)=>{
  65. User.find({email:req.body.email})
  66. .then(user => {
  67. if(user.length >= 1){
  68. return res.status(409).json({
  69. message: 'Email exists'
  70. })
  71. }else{
  72. bcrypt.hash(req.body.password, 10, (err,hash) =>{
  73. if (err) {
  74. return res.status(500).json({
  75. error:err
  76. })
  77. } else {
  78. const user = new User({
  79. _id: new mongoose.Types.ObjectId(),
  80. email: req.body.email,
  81. password: hash
  82. })
  83. user.save()
  84. .then(result => {
  85. res.status(200).json({
  86. message: 'user created'
  87. })
  88. })
  89. .catch(err => {
  90. res.status(500).json({
  91. error: err
  92. })
  93. })
  94. }
  95. })
  96. }
  97. })
  98. })
Add Comment
Please, Sign In to add comment