signup.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script>
  2. const { jwt } = require('./security')
  3. const api = require('./api')
  4. export default {
  5. data() {
  6. return {
  7. valid: false,
  8. saving: false,
  9. error: null,
  10. model: {
  11. name: 'a@a', //null,
  12. email: 'a@a', //null,
  13. password: 'a@a', //null, // https://www.dashlane.com/hellointernet
  14. confirmPassword: 'a@a', //null
  15. },
  16. rules: {
  17. name: [
  18. v => !!v || 'Name is required'
  19. ],
  20. email: [
  21. v => !!v || 'E-mail is required',
  22. v => /.+@.+/.test(v) || 'Valid email required'
  23. ],
  24. password: [
  25. v => (v.length > 8
  26. && /[A-Z]/.test(v)
  27. && /[a-z]/.test(v)
  28. && /\d/.test(v)
  29. && /\W/.test(v))
  30. || `Hey, your password is pretty weak. But whatever. I'm not your mother... I'm not going to force you. You should know better by now. Have you considered using <a href="https://www.dashlane.com/hellointernet">dashlane</a> for password management? Just think about it.`
  31. ],
  32. confirmPassword: [
  33. v => v === this.model.password || 'Passwords do not match'
  34. ]
  35. }
  36. }
  37. },
  38. computed: {
  39. passwordMessages() {
  40. const password = this.model.password || null
  41. const weakPassword = password && (
  42. password.length < 8
  43. || !/[A-Z]/.test(password)
  44. || !/[a-z]/.test(password)
  45. || !/\d/.test(password)
  46. || !/\W/.test(password)
  47. )
  48. return weakPassword
  49. ? [`Hey, your password is pretty weak. But whatever. I'm not your mother... I'm not going to force you. You should know better by now. Have you considered using <a href="https://www.dashlane.com/hellointernet">dashlane</a> for password management? Just think about it.`]
  50. : []
  51. }
  52. },
  53. updated() {
  54. // console.log('Validating', this.$refs.form.validate())
  55. },
  56. methods: {
  57. async submit() {
  58. try {
  59. this.saving = true
  60. const result = await api.post('signup', this.model)
  61. if (result.error) {
  62. throw new Error(result.error)
  63. }
  64. this.$router.push('/confirm/' + this.model.email)
  65. } catch (err) {
  66. this.saving = false
  67. this.error = err.stack || err
  68. }
  69. }
  70. }
  71. }
  72. </script>
  73. <template>
  74. <div>
  75. <h1>Sign up</h1>
  76. <v-form v-model="valid" ref="form">
  77. <v-text-field v-model="model.name" :rules="rules.name" label="Your name" required />
  78. <v-text-field v-model="model.email" :rules="rules.email" label="Email" required />
  79. <v-text-field v-model="model.password" :messages="passwordMessages" label="Password" required type="password" />
  80. <v-text-field v-model="model.confirmPassword" :rules="rules.confirmPassword" label="Confirm Password" required type="password" />
  81. <v-btn :disabled="!valid || saving" color="success" @click="submit">
  82. Create Account
  83. </v-btn>
  84. <v-alert :value="true" v-if="error" type="error" dismissible>{{error}}</v-alert>
  85. </v-form>
  86. </div>
  87. </template>