Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VerifyView.vue 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template lang="pug">
  2. .wait-message
  3. p.verify-message Thanks for authenticating your email!
  4. p.verify-message Please give us a moment to redirect you back to the survey
  5. </template>
  6. <script>
  7. // NOTE: If the httponly flag is to be used with these cookies,
  8. // this file will need to be rewritten as an .html file due to the way
  9. // that Hapi sets cookies via the h.state() method
  10. import { Authenticator } from '../services/auth.service.js'
  11. export default {
  12. name: 'VerifyView',
  13. data: () => ({
  14. authenticator: {},
  15. answers: {},
  16. }),
  17. async created() {
  18. this.authenticator = new Authenticator()
  19. const hashEmail = this.$route.params.email
  20. // TODO: generate a token on the backend here and have it sent over in
  21. // the headers intead of setting it directly with document.cookie (see note above)
  22. const hashesMatch = await this.authenticator.verifyAuthEmail(hashEmail)
  23. const siimeeToken = this.grabToken(document.cookie)
  24. // TODO: Then send this token and receive a different token
  25. const jwt = await this.authenticator.validateJwt(siimeeToken)
  26. this.answers = jwt.payload
  27. const accessToken = await this.generateAccessToken()
  28. if (jwt.isValid && hashesMatch) {
  29. const siimeeAnswers = JSON.stringify(this.answers)
  30. document.cookie = `siimee_answered=${siimeeAnswers}; max-age=360 ; path=/onboarding; secure`
  31. document.cookie = `siimee_session=${siimeeToken} ; max-age=360 ; path=/onboarding; secure`
  32. document.cookie = `siimee_access=${accessToken}; max-age=360 ; path=/onboarding; secure`
  33. this.$router.push('/onboarding')
  34. }
  35. // else {
  36. // render ERROR message above or redirect to 404 (or both?)
  37. },
  38. methods: {
  39. grabToken(cookieString) {
  40. const cookies = cookieString.split('; ').reduce((prev, current) => {
  41. const [name, ...value] = current.split('=')
  42. prev[name] = value.join('=')
  43. return prev
  44. }, {})
  45. return 'siimee_jwt' in cookies ? cookies['siimee_jwt'] : undefined
  46. },
  47. async generateAccessToken() {
  48. const accessJwt = await this.authenticator.generateJwt({
  49. ...this.answers,
  50. expiration: 60 * 3, // testing for now... extend to 1 hour?
  51. })
  52. return accessJwt
  53. },
  54. },
  55. }
  56. </script>
  57. <style>
  58. .wait-message {
  59. margin: 5rem auto;
  60. text-align: center;
  61. width: 90%;
  62. max-width: 35rem;
  63. font-size: 150%;
  64. font-weight: bold;
  65. }
  66. </style>