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.

341 lines
9.9 KiB

2 years ago
  1. <template>
  2. <v-card
  3. class="border-radius-20 elevation-0"
  4. min-width="900px"
  5. max-width="900px"
  6. >
  7. <v-spacer class="px-7 pt-7">
  8. <v-spacer class="d-flex align-center">
  9. <div class="circle-decoration me-2"></div>
  10. <div class="circle-decoration me-2"></div>
  11. <span class="font-weight-bold text-size-20 ms-7 text-height-26">{{
  12. $t("userProfile.setting")
  13. }}</span>
  14. </v-spacer>
  15. <v-spacer class="mt-10 mb-5">
  16. <span class="font-weight-bold text-size-18">{{
  17. $t("userProfile.settingEmail")
  18. }}</span>
  19. </v-spacer>
  20. <v-spacer class="input-wrap mb-7">
  21. <v-text-field
  22. v-model="userMail"
  23. disabled
  24. class="input-border"
  25. solo
  26. flat
  27. hide-details
  28. dense
  29. ></v-text-field>
  30. </v-spacer>
  31. <v-spacer class="mb-5">
  32. <span class="font-weight-bold text-size-18">{{
  33. $t("Reset Password")
  34. }}</span>
  35. </v-spacer>
  36. <v-form v-model="valid">
  37. <v-spacer class="input-wrap mb-2">
  38. <div class="text-size-12 mb-1">
  39. {{ $t("Old password") }}
  40. </div>
  41. <v-text-field
  42. v-model="userPass.user_old_pass"
  43. :rules="[rules.require]"
  44. outlined
  45. dense
  46. ></v-text-field>
  47. </v-spacer>
  48. <v-spacer class="input-wrap mb-2">
  49. <div class="text-size-12 mb-1">
  50. {{ $t("New password") }}
  51. </div>
  52. <v-text-field
  53. v-model="userPass.user_new_pass"
  54. :append-icon="showPass ? 'mdi-eye' : 'mdi-eye-off'"
  55. @click:append="showPass = !showPass"
  56. dense
  57. outlined
  58. :type="showPass ? 'text' : 'password'"
  59. :rules="[rules.checkPassword, rules.require]"
  60. :hint="
  61. this.$t(
  62. 'Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter'
  63. )
  64. "
  65. ></v-text-field>
  66. </v-spacer>
  67. <v-spacer class="input-wrap mb-2">
  68. <div class="text-size-12 mb-1">
  69. {{ $t("Confirm password") }}
  70. </div>
  71. <v-text-field
  72. v-model="confirmPass"
  73. :append-icon="showConfirmPass ? 'mdi-eye' : 'mdi-eye-off'"
  74. @click:append="showConfirmPass = !showConfirmPass"
  75. dense
  76. outlined
  77. :type="showConfirmPass ? 'text' : 'password'"
  78. :rules="[rules.checkPassword, rules.require]"
  79. :hint="
  80. this.$t(
  81. 'Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter'
  82. )
  83. "
  84. ></v-text-field>
  85. </v-spacer>
  86. </v-form>
  87. <v-btn
  88. @click.stop="resetPassword"
  89. width="95px"
  90. class="border-radius-16 mb-7 text-capitalize"
  91. color="primary"
  92. >
  93. {{ $t("save") }}
  94. </v-btn>
  95. <v-spacer class="mb-5">
  96. <span class="font-weight-bold text-size-18">{{
  97. $t("userProfile.manageSSO")
  98. }}</span>
  99. </v-spacer>
  100. <v-spacer class="mb-10 d-flex">
  101. <div class="SSO-wrap d-flex align-center me-7 ps-7 py-8">
  102. <span>Facebook</span>
  103. <v-btn
  104. v-if="facebook.social_schema"
  105. @click="removeSocialRelation(facebook)"
  106. style="margin-left: 125px"
  107. text
  108. color="primary border-radius-10 text-capitalize"
  109. ><span>{{ $t("userProfile.SSOUnLink") }}</span></v-btn
  110. >
  111. <v-btn
  112. v-else
  113. @click="facebookLogin"
  114. style="margin-left: 125px"
  115. color="primary border-radius-10 text-capitalize"
  116. ><span>{{ $t("userProfile.SSOLink") }}</span></v-btn
  117. >
  118. </div>
  119. <div class="SSO-wrap d-flex align-center ps-7 py-8">
  120. <span>Google</span>
  121. <v-btn
  122. v-if="google.social_schema"
  123. @click.prevent="removeSocialRelation(google)"
  124. style="margin-left: 125px"
  125. text
  126. color="primary border-radius-10 text-capitalize"
  127. ><span>{{ $t("userProfile.SSOUnLink") }}</span></v-btn
  128. >
  129. <v-btn
  130. v-else
  131. @click="googleLogin"
  132. style="margin-left: 125px"
  133. color="primary border-radius-10 text-capitalize"
  134. ><span>{{ $t("userProfile.SSOLink") }}</span></v-btn
  135. >
  136. </div>
  137. </v-spacer>
  138. <v-btn text color="#ef5a5a" class="px-0 mb-10">
  139. <span
  140. @click="deleteDialogActive = !deleteDialogActive"
  141. class="text-size-18 text-capitalize"
  142. style="text-decoration-line: underline"
  143. >{{ $t("userProfile.deleteAccount") }}</span
  144. >
  145. </v-btn>
  146. <v-dialog
  147. v-model="deleteDialogActive"
  148. width="294px"
  149. height="325px"
  150. @click:outside="deleteDialogActive = !deleteDialogActive"
  151. >
  152. <v-card class="pa-5">
  153. <v-spacer class="d-flex align-center">
  154. <v-spacer>
  155. {{ $t("Delete account") }}
  156. </v-spacer>
  157. <v-btn icon @click="deleteDialogActive = !deleteDialogActive">
  158. <v-icon> mdi-close </v-icon>
  159. </v-btn>
  160. </v-spacer>
  161. <v-spacer class="d-flex justify-center mb-6 mt-4">
  162. <v-img
  163. :src="deleteAccountImg"
  164. max-width="130px"
  165. max-height="95px"
  166. ></v-img>
  167. </v-spacer>
  168. <v-spacer class="py-3 mb-3">
  169. {{
  170. $t(
  171. "We’re sorry to see you go. If you want to permanently delete your account, click “Delete” button."
  172. )
  173. }}
  174. </v-spacer>
  175. <v-spacer class="d-flex justify-space-between">
  176. <v-btn
  177. @click="deleteAccount"
  178. color="white"
  179. class="border-radius-16 primary--text text-capitalize"
  180. width="112px"
  181. >
  182. {{ $t("Delete") }}
  183. </v-btn>
  184. <v-btn
  185. color="primary"
  186. class="border-radius-16 text-capitalize"
  187. width="112px"
  188. @click="deleteDialogActive = !deleteDialogActive"
  189. >
  190. {{ $t("Keep") }}
  191. </v-btn>
  192. </v-spacer>
  193. </v-card>
  194. </v-dialog>
  195. </v-spacer>
  196. </v-card>
  197. </template>
  198. <script>
  199. export default {
  200. name: "Setting",
  201. props: {
  202. userMail: {
  203. type: String,
  204. required: true,
  205. default: "",
  206. },
  207. userSocialRelation: {
  208. type: Array,
  209. required: true,
  210. default: () => [],
  211. },
  212. },
  213. data() {
  214. return {
  215. google: {},
  216. facebook: {},
  217. deleteDialogActive: false,
  218. valid: false,
  219. showPass: false,
  220. showConfirmPass: false,
  221. userPass: {
  222. user_old_pass: "",
  223. user_new_pass: "",
  224. },
  225. confirmPass: "",
  226. deleteAccountImg: require("~/assets/img/deleteAccount.png"),
  227. rules: {
  228. require: (value) => !!value || this.$t("Required."),
  229. email: (v) =>
  230. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  231. v
  232. ) || this.$t("Invalid email"),
  233. checkPassword: (v) =>
  234. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  235. v.length >= 8 &&
  236. v.length <= 20) ||
  237. this.$t(
  238. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  239. ),
  240. },
  241. };
  242. },
  243. created() {
  244. this.facebook =
  245. this.$props.userSocialRelation.filter(
  246. (item) => item.social_schema === "facebook"
  247. )[0] || {};
  248. this.google =
  249. this.$props.userSocialRelation.filter(
  250. (item) => item.social_schema === "google"
  251. )[0] || {};
  252. },
  253. methods: {
  254. resetPassword() {
  255. if (
  256. this.valid &&
  257. this.userPass.user_old_pass !== this.userPass.user_new_pass
  258. ) {
  259. this.$axios
  260. .post(
  261. `/member/users/pass?jwt=${
  262. this.$auth.$storage.getUniversal("jwt").token || ""
  263. }`,
  264. this.userPass
  265. )
  266. .then((result) => {
  267. this.$auth.$storage.removeUniversal("jwt");
  268. this.$auth.$storage.removeUniversal("userPicture");
  269. this.$auth.$storage.removeUniversal("userLastName");
  270. this.$auth.logout();
  271. })
  272. .catch((err) => {
  273. console.log(err);
  274. });
  275. }
  276. },
  277. removeSocialRelation(schema) {
  278. delete schema.social_id;
  279. this.$axios
  280. .put(
  281. `/member/users/social?jwt=${
  282. this.$auth.$storage.getUniversal("jwt").token || ""
  283. }`,
  284. schema
  285. )
  286. .then((result) => {
  287. this.$emit("refetch-user");
  288. })
  289. .catch((err) => {
  290. console.log(err);
  291. });
  292. this.$nextTick(() => {
  293. schema.social_schema === "google"
  294. ? (this.google = {})
  295. : (this.facebook = {});
  296. });
  297. },
  298. deleteAccount() {
  299. this.$axios
  300. .delete(
  301. `/member/users?jwt=${
  302. this.$auth.$storage.getUniversal("jwt").token || ""
  303. }`
  304. )
  305. .then((result) => {
  306. this.$auth.$storage.removeUniversal("jwt");
  307. this.$auth.$storage.removeUniversal("userPicture");
  308. this.$auth.$storage.removeUniversal("userLastName");
  309. this.$auth.logout();
  310. })
  311. .catch((err) => {
  312. console.log(err);
  313. });
  314. },
  315. facebookLogin() {
  316. this.$auth.loginWith("facebook");
  317. },
  318. googleLogin() {
  319. this.$auth.loginWith("google");
  320. },
  321. },
  322. };
  323. </script>
  324. <style lang="scss" scoped>
  325. .SSO-wrap {
  326. width: 100%;
  327. border: 1px solid #e5e5e5;
  328. border-radius: 10px;
  329. }
  330. .input-wrap {
  331. @media screen and (max-width: 600px) {
  332. width: 73%;
  333. }
  334. @media screen and (min-width: 600px) and (max-width: 960px) {
  335. width: 33%;
  336. }
  337. @media screen and (min-width: 961px) {
  338. width: 38%;
  339. }
  340. }
  341. </style>