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