You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
9.0 KiB

2 years ago
  1. <template>
  2. <v-dialog fullscreen v-model="isSettingDialogActive" @click:outside="$emit('closeSettingDialog')">
  3. <v-card class="border-radius-20">
  4. <v-spacer class="px-7 pt-7 pt-15">
  5. <v-spacer class="d-flex align-center pt-10">
  6. <div class="circle-decoration me-2"></div>
  7. <div class="circle-decoration me-2"></div>
  8. <span class="font-weight-bold text-size-20 ms-7 text-height-26">{{ $t("userProfile.setting") }}</span>
  9. </v-spacer>
  10. <v-spacer class="mt-10 mb-5">
  11. <span class="font-weight-bold text-size-18">{{ $t("userProfile.settingEmail") }}</span>
  12. </v-spacer>
  13. <v-spacer class="input-wrap mb-7">
  14. <v-text-field v-model="userMail" disabled solo flat hide-details dense class="input-border"></v-text-field>
  15. </v-spacer>
  16. <v-spacer class="mb-5">
  17. <span class="font-weight-bold text-size-18">{{ $t("Reset Password") }}</span>
  18. </v-spacer>
  19. <v-form v-model="valid">
  20. <v-spacer class="input-wrap mb-2">
  21. <div class="text-size-12 mb-1">
  22. {{ $t('Old password') }}
  23. </div>
  24. <v-text-field v-model="userPass.user_old_pass" :rules="[rules.require]" outlined dense></v-text-field>
  25. </v-spacer>
  26. <v-spacer class="input-wrap mb-2">
  27. <div class="text-size-12 mb-1">
  28. {{ $t('New password') }}
  29. </div>
  30. <v-text-field
  31. v-model="userPass.user_new_pass"
  32. :append-icon=" showPass ? 'mdi-eye' : 'mdi-eye-off'" @click:append="showPass = !showPass"
  33. dense outlined
  34. :type=" showPass ? 'text' : 'password'"
  35. :rules="[rules.checkPassword,rules.require]"
  36. :hint="this.$t('Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter')"
  37. ></v-text-field>
  38. </v-spacer>
  39. <v-spacer class="input-wrap mb-2">
  40. <div class="text-size-12 mb-1">
  41. {{ $t('Confirm password') }}
  42. </div>
  43. <v-text-field
  44. v-model="confirmPass"
  45. :append-icon=" showConfirmPass ? 'mdi-eye' : 'mdi-eye-off'" @click:append="showConfirmPass = !showConfirmPass"
  46. dense outlined
  47. :type=" showConfirmPass ? 'text' : 'password'"
  48. :rules="[rules.checkPassword,rules.require]"
  49. :hint="this.$t('Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter')"
  50. ></v-text-field>
  51. </v-spacer>
  52. </v-form>
  53. <v-btn @click.stop="resetPassword" width="95px" class="border-radius-16 mb-7 text-capitalize" color="primary">
  54. {{ $t('save') }}
  55. </v-btn>
  56. <v-spacer class="mb-5">
  57. <span class="font-weight-bold text-size-18">{{ $t("userProfile.manageSSO") }}</span>
  58. </v-spacer>
  59. <v-spacer class="mb-10 d-sm-flex">
  60. <div class="SSO-wrap d-flex align-center me-7 ps-7 py-8 mb-5">
  61. <span>Facebook</span>
  62. <v-btn v-if="facebook.social_schema" @click="removeSocialRelation(facebook)" style="margin-left:125px" text color="primary border-radius-10 text-capitalize"><span>{{ $t("userProfile.SSOUnLink") }}</span></v-btn>
  63. <v-btn v-else @click="facebookLogin" style="margin-left:125px" color="primary border-radius-10 text-capitalize"><span>{{ $t("userProfile.SSOLink") }}</span></v-btn>
  64. </div>
  65. <div class="SSO-wrap d-flex align-center ps-7 py-8">
  66. <span>Google</span>
  67. <v-btn v-if="google.social_schema" @click="removeSocialRelation(google)" style="margin-left:125px" text color="primary border-radius-10 text-capitalize"><span>{{ $t("userProfile.SSOUnLink") }}</span></v-btn>
  68. <v-btn v-else @click="googleLogin" style="margin-left:145px" color="primary border-radius-10 text-capitalize"><span>{{ $t("userProfile.SSOLink") }}</span></v-btn>
  69. </div>
  70. </v-spacer>
  71. <v-btn @click="deleteDialogActive = !deleteDialogActive" text color="primary" class="px-0 mb-10">
  72. <span class="text-size-18 text-capitalize" style="text-decoration-line:underline">{{ $t("userProfile.deleteAccount") }}</span>
  73. </v-btn>
  74. <v-dialog v-model="deleteDialogActive" width="294px" height="325px" @click:outside="deleteDialogActive = !deleteDialogActive">
  75. <v-card class="pa-5">
  76. <v-spacer class="d-flex align-center">
  77. <v-spacer>
  78. {{ $t('Delete account') }}
  79. </v-spacer>
  80. <v-btn icon @click="deleteDialogActive = !deleteDialogActive">
  81. <v-icon>
  82. mdi-close
  83. </v-icon>
  84. </v-btn>
  85. </v-spacer>
  86. <v-spacer class="d-flex justify-center mb-6 mt-4">
  87. <v-img :src="deleteAccountImg" max-width="130px" max-height="95px"></v-img>
  88. </v-spacer>
  89. <v-spacer class="py-3 mb-3">
  90. {{ $t("We’re sorry to see you go. If you want to permanently delete your account, click “Delete” button.") }}
  91. </v-spacer>
  92. <v-spacer class="d-flex justify-space-between">
  93. <v-btn @click="deleteAccount" color="white" class="border-radius-16 primary--text text-capitalize" width="112px">
  94. {{ $t('Delete') }}
  95. </v-btn>
  96. <v-btn color="primary" class="border-radius-16 text-capitalize" width="112px" @click="deleteDialogActive = !deleteDialogActive">
  97. {{ $t('Keep') }}
  98. </v-btn>
  99. </v-spacer>
  100. </v-card>
  101. </v-dialog>
  102. </v-spacer>
  103. </v-card>
  104. </v-dialog>
  105. </template>
  106. <script>
  107. export default {
  108. name:"settingDialog",
  109. props: {
  110. isSettingDialogActive: {
  111. type: Boolean,
  112. required: true,
  113. default: false
  114. },
  115. userMail: {
  116. type: String,
  117. required: true,
  118. default: ''
  119. },
  120. userSocialRelation: {
  121. type: Array,
  122. required: true,
  123. default: () => []
  124. }
  125. },
  126. data() {
  127. return {
  128. google:{},
  129. facebook:{},
  130. deleteDialogActive: false,
  131. valid:false,
  132. showPass: false,
  133. showConfirmPass: false,
  134. userPass: {
  135. user_old_pass: '',
  136. user_new_pass: '',
  137. },
  138. confirmPass: '',
  139. deleteAccountImg:require('~/assets/img/deleteAccount.png'),
  140. rules: {
  141. require: value => !!value || this.$t('Required.'),
  142. email: v => /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(v) || this.$t('Invalid email'),
  143. checkPassword: v => /(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) && v.length >= 8 && v.length <= 20 || this.$t('Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter'),
  144. },
  145. }
  146. },
  147. created() {
  148. this.facebook = this.userSocialRelation.filter(item=>item.social_schema === 'facebook')[0] || {}
  149. this.google = this.userSocialRelation.filter(item=>item.social_schema === 'google')[0] || {}
  150. },
  151. methods: {
  152. resetPassword() {
  153. if (this.valid && this.userPass.user_old_pass !== this.userPass.user_new_pass) {
  154. this.$axios.post(`/member/users/pass?jwt=${this.$auth.$storage.getUniversal('jwt').token || ''}`,this.userPass)
  155. .then((result) => {
  156. this.$auth.$storage.removeUniversal('jwt')
  157. this.$auth.$storage.removeUniversal('userPicture')
  158. this.$auth.$storage.removeUniversal('userLastName')
  159. this.$auth.logout()
  160. }).catch((err) => {
  161. console.log(err)
  162. });
  163. }
  164. },
  165. removeSocialRelation(schema) {
  166. delete schema.social_id
  167. this.$axios.put(`/member/users/social?jwt=${this.$auth.$storage.getUniversal('jwt').token || ''}`,schema)
  168. .then((result) => {
  169. this.$emit('refetch-user')
  170. }).catch((err) => {
  171. console.log(err)
  172. });
  173. this.$nextTick(()=>{
  174. schema.social_schema === 'google' ? this.google = {} : this.facebook = {}
  175. })
  176. },
  177. deleteAccount() {
  178. this.$axios.delete(`/member/users?jwt=${this.$auth.$storage.getUniversal('jwt').token || ''}`)
  179. .then((result) => {
  180. this.$auth.$storage.removeUniversal('jwt')
  181. this.$auth.$storage.removeUniversal('userPicture')
  182. this.$auth.$storage.removeUniversal('userLastName')
  183. this.$auth.logout()
  184. }).catch((err) => {
  185. console.log(err)
  186. });
  187. },
  188. facebookLogin() {
  189. this.$auth.loginWith('facebook')
  190. },
  191. googleLogin() {
  192. this.$auth.loginWith('google')
  193. },
  194. },
  195. watch: {
  196. isSettingDialogActive: {
  197. handler:function() {
  198. this.facebook = this.userSocialRelation.filter(item=>item.social_schema === 'facebook')[0] || {}
  199. this.google = this.userSocialRelation.filter(item=>item.social_schema === 'google')[0] || {}
  200. }
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .SSO-wrap {
  207. width: 100%;
  208. border: 1px solid #E5E5E5;
  209. border-radius: 10px;
  210. }
  211. </style>