Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <template>
  2. <div class="dos-login-container" ref="qsnds">
  3. <h1>Create your own room !</h1>
  4.  
  5. <StatusInput
  6. ref="loginField"
  7. v-model="login"
  8. placeholder="Login"
  9. :checkMethod="checkExisting">
  10. </StatusInput>
  11.  
  12. <ConfirmedPassword v-model="c_password" @validation="createRoom"></ConfirmedPassword>
  13.  
  14. <button class="dos-button dos-form-button" @click="createRoom" :disabled="!inputValid">Create</button>
  15. </div>
  16. </template>
  17.  
  18. <script>
  19.  
  20. import Rooms from '@/utils/rooms'
  21. import StatusInput from '@/components/InputWithStatus'
  22. import ConfirmedPassword from '@/components/ConfirmedPassword'
  23.  
  24. export default {
  25. data: () => ({
  26. login: '',
  27. password: '',
  28. passConfirmed: false,
  29. }),
  30. methods: {
  31. createRoom() {
  32. Rooms.create(this.login, this.password).thenJSON(
  33. (val,obj) => this.processResponse(obj)
  34. )
  35. },
  36. processResponse(res) {
  37. if(res.status === 'ERROR') {
  38. return this.$refs.loginField.status.msg = res.text
  39. }
  40. Rooms.connect(this.login, this.password).then( () => this.$router.push('/room') )
  41. },
  42. checkExisting(login) {
  43. let to_return = { msg: '', color: 'red' }
  44. if(login === '') return to_return
  45. Rooms.exists(login).then( (val) => {
  46. if(val) return to_return.msg = 'This name is already in use !'
  47. });
  48. return to_return
  49. },
  50. },
  51. computed: {
  52. inputValid() {
  53. return ( this.login !== '' ) && ( this.passConfirmed )
  54. },
  55. c_password: {
  56. get: () => ({ password: this.password, confirmed: this.passConfirmed}),
  57. set(newValue) {
  58. this.password = newValue.password
  59. this.passConfirmed = newValue.confirmed
  60. }
  61. }
  62. },
  63. components: {
  64. StatusInput, ConfirmedPassword
  65. }
  66. }
  67.  
  68. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement