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.

317 lines
12 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="tw-bg-white tw-mt-[30px] md:tw-rounded-[24px] md:tw-pt-[60px] md:tw-pb-[150px] md:tw-px-[30px]">
  3. <h1 class="tw-text-[40px] tw-font-bold tw-mb-[20px] md:tw-text-[24px]">{{ $t('Login') }}</h1>
  4. <p class="tw-body-3 tw-text-neutral-400 tw-mb-[16px] md:tw-mb-[12px]">
  5. {{ $t('Welcome back! Please enter your details') }}
  6. </p>
  7. <p class="tw-body-3 tw-mb-[24px] md:tw-mb-[32px]">{{ $t('Not a member?') }} <nuxt-link
  8. :to="localePath('/user/signup')" class="primary--text text-decoration-none">{{ $t('Sign up') }}</nuxt-link>
  9. </p>
  10. <!-- <div class="tw-grid tw-grid-cols-1 tw-gap-[10px] tw-mb-[30px] md:tw-gap-[12px] md:tw-mb-[12px]">
  11. <button @click="googleLogin"
  12. class="tw-block tw-w-full tw-py-[8px] tw-rounded-[16px] tw-border tw-border-solid tw-text-black tw-border-neutrals-200"><img
  13. width="20px" height="20px" src="~/assets/img/g-normal.png" class="mr-5" />{{ $t('Login with Google')
  14. }}</button>
  15. <button @click="facebookLogin"
  16. class="tw-block tw-w-full tw-py-[8px] tw-rounded-[16px] tw-border tw-border-solid tw-text-black tw-border-neutrals-200"><img
  17. width="20px" height="20px" src="~/assets/img/f_logo_RGB-Blue_72.png" class="mr-5" />
  18. {{ $t("Login with Facebook")
  19. }}</button>
  20. </div>
  21. <div class="tw-grid tw-grid-cols-[auto_16px_auto] tw-gap-[28px] tw-mb-[6px]">
  22. <div class="tw-flex tw-justify-center tw-items-center">
  23. <div class="tw-w-full tw-h-[1px] tw-bg-neutral-200"></div>
  24. </div>
  25. <div class="tw-text-neutral-400 tw-body-3 tw-font-normal">{{ $t("or") }}</div>
  26. <div class="tw-flex tw-justify-center tw-items-center">
  27. <div class="tw-w-full tw-h-[1px] tw-bg-neutral-200"></div>
  28. </div>
  29. </div> -->
  30. <div v-if="wrongMessageActive" class="warning--text text-size-14 ps-1 mb-3">
  31. {{ $t('The username or password entered is incorrect') }}
  32. </div>
  33. <v-form ref="loginFormRef" lazy-validation>
  34. <v-text-field
  35. v-model="userData.Account" background-color="neutrals darken-1" :label="this.$t('Email')"
  36. :placeholder="this.$t('Email')" height="40px" filled rounded dense single-line persistent-placeholder
  37. :rules="[rules.email,rules.require]" v-on:input="updateValid"
  38. />
  39. <v-text-field
  40. v-model="userData.Password" background-color="neutrals darken-1" :label="this.$t('Password')"
  41. :type=" showPass ? 'text' : 'password'" :placeholder="this.$t('Password')" filled rounded dense single-line
  42. persistent-placeholder :append-icon=" showPass ? 'mdi-eye' : 'mdi-eye-off'" @click:append="showPass = !showPass"
  43. :rules="[rules.checkPassword,rules.require]" v-on:input="updateValid"
  44. />
  45. </v-form>
  46. <div class="tw-flex tw-justify-between tw-items-center tw-mb-[28px] md:tw-mb-[32px]">
  47. <div class="tw-flex tw-items-center">
  48. <div class="tw-flex tw-items-center">
  49. <div class="tw-flex tw-flex-col">
  50. <label class="tw-body-4 container-checkbox" for="remember">
  51. {{ $t('Remember me')
  52. }}
  53. <input id="remember" type="checkbox" value="remember" v-model="remember" />
  54. <span class="checkmark"></span>
  55. </label>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="tw-flex tw-items-center">
  60. <nuxt-link class="complementary--text text-decoration-none text-size-14" :to="localePath('/user/forgot')">{{
  61. $t('Forgot Password?') }}</nuxt-link>
  62. </div>
  63. </div>
  64. <div class="md:tw-flex md:tw-justify-center md:tw-items-center"> <button @click="userLogin" :disabled="!valid"
  65. :class="['tw-block tw-w-full tw-py-[10px] tw-rounded-[16px] tw-border tw-border-solid tw-body-3 tw-font-normal tw-transition-all tw-duration-200 tw-ease-in-out',valid?'tw-text-white tw-bg-primary-default tw-border-primary-default':'tw-text-base-disable tw-bg-neutral-100 tw-border-neutral-100']">{{
  66. $t("Login")
  67. }}</button></div>
  68. <v-dialog v-model="resendDialog" :width=" $vuetify.breakpoint.smAndUp ? 423 : 294 "
  69. @click:outside="$router.push(localePath('/user'))">
  70. <v-card class="pa-7 " v-if="!verifyEmailSent" :height=" $vuetify.breakpoint.smAndUp ? 249 : 206 ">
  71. <v-spacer class="d-flex">
  72. <v-spacer class="text-size-20 neutrals--text text--darken-5">{{ $t('Verify your email') }}</v-spacer>
  73. <v-btn icon @click="resendDialog = !resendDialog">
  74. <v-icon>mdi-close</v-icon>
  75. </v-btn>
  76. </v-spacer>
  77. <v-spacer class="text-size-16 my-7 neutrals--text text--darken-4">
  78. {{ $t("We've sent a verification email to")}}
  79. <br />
  80. <span class="primary--text">
  81. {{ userData.Password }}
  82. </span>. {{ $t("Please click the link within to activate your account.") }}
  83. </v-spacer>
  84. <v-btn @click="resendVerifyEmail" class="primary no-text-transform" width="100%" rounded>
  85. {{ $t("Resend verification email") }}
  86. </v-btn>
  87. </v-card>
  88. <v-card class="pa-7 " v-else :height=" $vuetify.breakpoint.smAndUp ? 249 : 206 ">
  89. <v-spacer class="text-size-20 neutrals--text text--darken-5">
  90. {{ $t('Verify your email') }}
  91. </v-spacer>
  92. <v-spacer class="text-size-16 my-7 neutrals--text text--darken-4">
  93. {{ $t("We've sent a verification email to")
  94. }}
  95. <br />
  96. <span class="primary--text">
  97. {{ userData.Password }}
  98. </span>. {{ $t("Please click the link within to activate your account.") }}
  99. </v-spacer>
  100. <v-btn @click="resendVerifyEmail" class="primary no-text-transform" width="100%" rounded
  101. :disabled="countdown > 0">
  102. {{ $t("Resend") }}
  103. <span v-if="countdown > 0">
  104. {{ `(${this.countdown})` }}
  105. </span>
  106. </v-btn>
  107. </v-card>
  108. </v-dialog>
  109. </div>
  110. </template>
  111. <script>
  112. import { getCurrentTime } from "~/utils/assist";
  113. export default {
  114. name: "login",
  115. layout: "login",
  116. auth: false,
  117. data() {
  118. return {
  119. showPass: false,
  120. resendDialog: false,
  121. wrongMessageActive: false,
  122. verifyEmailSent: false,
  123. valid: false,
  124. remember: false,
  125. countdown: 60,
  126. userData: {
  127. Account: '',
  128. Password: '',
  129. },
  130. rules: {
  131. require: value => !!value || this.$t('Required.'),
  132. email: v => /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(v) || this.$t('Invalid email'),
  133. // checkPassword: v => (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) && v.length >= 8 && v.length <= 20) || '請輸入密碼',
  134. checkPassword: v => v.length >= 1 || '請輸入密碼',
  135. },
  136. }
  137. },
  138. watch: {
  139. remember: {
  140. handler: function () {
  141. if (this.remember == true) {
  142. this.$auth.$storage.setUniversal("userPassword", this.userData.Password);
  143. }else{
  144. this.$auth.$storage.removeUniversal("userPassword");
  145. }
  146. },
  147. },
  148. },
  149. methods: {
  150. async userLogin() {
  151. let that = this;
  152. if (!that.$refs.loginFormRef.validate()) return;
  153. console.log("測試登錄接口請求開始:" + getCurrentTime());
  154. try {
  155. const response =await that.$auth.loginWith('local', { data: that.userData });
  156. console.log("測試登錄接口請求結束:" + getCurrentTime());
  157. let data = response.data.DATA;
  158. console.log(JSON.stringify(data.authtoken));
  159. if(data.authtoken){
  160. const authtoken = data.authtoken;
  161. that.$auth.$storage.removeUniversal('authtoken');
  162. that.$auth.$storage.setUniversal('authtoken', authtoken);
  163. that.$auth.loggedIn ? that.$router.push(that.$auth.$storage.getUniversal('userBeforePath')) : that.$auth.redirect('login');
  164. }
  165. } catch(err) {
  166. if(err && err.response && err.response.status){
  167. err.response.status === 403 ? that.resendDialog = !that.resendDialog : err.response.status === 401 ? that.wrongMessageActive = true : that.resendDialog;
  168. }
  169. }
  170. },
  171. resendVerifyEmail() {
  172. this.countdown = 60
  173. // this.$axios.get(`/member/users/resend/${this.userData.email}?lang=${this.$i18n.locale}`)
  174. // .then((res) => {
  175. // clearInterval(this.timer)
  176. // this.verifyEmailSent = true
  177. // this.timer = setInterval(() => {
  178. // if (this.countdown > 0) { this.countdown-- }
  179. // if (this.countdown === 0) { clearInterval(this.timer) }
  180. // }, 1000)
  181. // })
  182. // .catch((err) => { console.log(err); })
  183. },
  184. updateValid(){
  185. if(this.userData.Account !=='' && this.userData.Password !==''){
  186. this.valid = true;
  187. }else{
  188. this.valid = false;
  189. }
  190. },
  191. },
  192. beforeUnmount() {
  193. clearInterval(this.timer)
  194. },
  195. beforeRouteEnter(to, from, next) {
  196. next(vm => {
  197. if (from.name) {
  198. if (!from.path.includes('user')) {
  199. vm.$auth.$storage.setUniversal("userBeforePath", from.fullPath, true)
  200. }
  201. }
  202. if (vm.$auth.loggedIn) {
  203. vm.$router.push(vm.$auth.$storage.getUniversal('userBeforePath') || '/')
  204. }
  205. else {
  206. next()
  207. }
  208. })
  209. },
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. $border-style: 1px solid #E5E5E5;
  214. .title {
  215. font-weight: 700;
  216. font-size: 26px;
  217. line-height: 34px;
  218. letter-spacing: 0.02em;
  219. color: #232323;
  220. }
  221. .btn-border {
  222. border: $border-style;
  223. }
  224. .seperator {
  225. border-bottom: $border-style;
  226. text-align: center;
  227. height: 12px;
  228. margin: 20px 0 30px;
  229. }
  230. :deep(.v-text-field.v-text-field--enclosed .v-text-field__details) {
  231. margin-bottom: 0;
  232. padding: 0;
  233. .v-messages {
  234. display: none;
  235. }
  236. .v-messages.error--text {
  237. display: block;
  238. margin-top: 4px;
  239. margin-bottom: 16px;
  240. }
  241. }
  242. /* The container */
  243. .container-checkbox {
  244. display: block;
  245. position: relative;
  246. padding-left: 28px;
  247. cursor: pointer;
  248. -webkit-user-select: none;
  249. -moz-user-select: none;
  250. -ms-user-select: none;
  251. user-select: none;
  252. }
  253. /* Hide the browser's default checkbox */
  254. .container-checkbox input {
  255. position: absolute;
  256. opacity: 0;
  257. cursor: pointer;
  258. }
  259. /* Create a custom checkbox */
  260. .container-checkbox .checkmark {
  261. position: absolute;
  262. top: 0;
  263. left: 0;
  264. height: 18px;
  265. width: 18px;
  266. background-color: transparent;
  267. border: 1px solid #f48800;
  268. border-radius: 4px;
  269. }
  270. /* On mouse-over, add a grey background color */
  271. .container-checkbox:hover input~.checkmark {
  272. border-color: #f48800;
  273. }
  274. /* When the checkbox is checked, add a blue background */
  275. .container-checkbox input:checked~.checkmark {
  276. background-color: #f48800;
  277. border-color: #f48800;
  278. }
  279. /* Create the checkmark/indicator (hidden when not checked) */
  280. .container-checkbox .checkmark:after {
  281. content: "";
  282. position: absolute;
  283. display: none;
  284. }
  285. /* Show the checkmark when checked */
  286. .container-checkbox input:checked~.checkmark:after {
  287. display: block;
  288. }
  289. /* Style the checkmark/indicator */
  290. .container-checkbox .checkmark:after {
  291. left: 5px;
  292. top: 2px;
  293. width: 5px;
  294. height: 10px;
  295. border: solid #ffffff;
  296. border-width: 0 2px 2px 0;
  297. -webkit-transform: rotate(45deg);
  298. -ms-transform: rotate(45deg);
  299. transform: rotate(45deg);
  300. }
  301. </style>