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.

347 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. if(this.userData.Account !=='' && this.userData.Password !==''){
  160. this.valid = true;
  161. }else{
  162. this.valid = false;
  163. }
  164. },
  165. methods: {
  166. async userLogin() {
  167. let that = this;
  168. if (!that.$refs.loginFormRef.validate()) return;
  169. console.log("測試登錄接口請求開始:" + getCurrentTime());
  170. try {
  171. const response =await that.$auth.loginWith('local', { data: that.userData });
  172. that.$auth.$storage.removeUniversal('authtoken');
  173. console.log("測試登錄接口請求結束:" + getCurrentTime());
  174. if(response.data.STATUSCODE==200){
  175. let data = response.data.DATA;
  176. console.log(JSON.stringify(data.authtoken));
  177. if(data.authtoken){
  178. const authtoken = data.authtoken;
  179. that.$auth.$storage.setUniversal('authtoken', authtoken);
  180. that.$auth.loggedIn ? that.$router.push(that.$auth.$storage.getUniversal('userBeforePath')) : that.$auth.redirect('login');
  181. }
  182. }else if(response.data.STATUSCODE==500){
  183. that.$auth.redirect('login');
  184. }else{
  185. // that.resendDialog = !that.resendDialog;
  186. that.wrongMessageActive = true;
  187. }
  188. } catch(err) {
  189. console.log(err);
  190. // if(err && err.response && err.response.status){
  191. // err.response.status === 403 ? that.resendDialog = !that.resendDialog : err.response.status === 401 ? that.wrongMessageActive = true : that.resendDialog;
  192. // }
  193. }
  194. },
  195. resendVerifyEmail() {
  196. this.countdown = 60
  197. // this.$axios.get(`/member/users/resend/${this.userData.email}?lang=${this.$i18n.locale}`)
  198. // .then((res) => {
  199. // clearInterval(this.timer)
  200. // this.verifyEmailSent = true
  201. // this.timer = setInterval(() => {
  202. // if (this.countdown > 0) { this.countdown-- }
  203. // if (this.countdown === 0) { clearInterval(this.timer) }
  204. // }, 1000)
  205. // })
  206. // .catch((err) => { console.log(err); })
  207. },
  208. updateValid(){
  209. if(this.userData.Account !=='' && this.userData.Password !==''){
  210. this.valid = true;
  211. }else{
  212. this.valid = false;
  213. }
  214. },
  215. },
  216. beforeUnmount() {
  217. if(this.timer!=null){
  218. clearInterval(this.timer);
  219. }
  220. },
  221. beforeRouteEnter(to, from, next) {
  222. next(vm => {
  223. if (from.name) {
  224. if (!from.path.includes('user')) {
  225. vm.$auth.$storage.setUniversal("userBeforePath", from.fullPath, true)
  226. }
  227. }
  228. if (vm.$auth.loggedIn) {
  229. vm.$router.push(vm.$auth.$storage.getUniversal('userBeforePath') || '/')
  230. }
  231. else {
  232. next()
  233. }
  234. })
  235. },
  236. }
  237. </script>
  238. <style lang="scss" scoped>
  239. $border-style: 1px solid #E5E5E5;
  240. .title {
  241. font-weight: 700;
  242. font-size: 26px;
  243. line-height: 34px;
  244. letter-spacing: 0.02em;
  245. color: #232323;
  246. }
  247. .btn-border {
  248. border: $border-style;
  249. }
  250. .seperator {
  251. border-bottom: $border-style;
  252. text-align: center;
  253. height: 12px;
  254. margin: 20px 0 30px;
  255. }
  256. :deep(.v-text-field.v-text-field--enclosed .v-text-field__details) {
  257. margin-bottom: 0;
  258. padding: 0;
  259. .v-messages {
  260. display: none;
  261. }
  262. .v-messages.error--text {
  263. display: block;
  264. margin-top: 4px;
  265. margin-bottom: 16px;
  266. }
  267. }
  268. /* The container */
  269. .container-checkbox {
  270. display: block;
  271. position: relative;
  272. padding-left: 28px;
  273. cursor: pointer;
  274. -webkit-user-select: none;
  275. -moz-user-select: none;
  276. -ms-user-select: none;
  277. user-select: none;
  278. }
  279. /* Hide the browser's default checkbox */
  280. .container-checkbox input {
  281. position: absolute;
  282. opacity: 0;
  283. cursor: pointer;
  284. }
  285. /* Create a custom checkbox */
  286. .container-checkbox .checkmark {
  287. position: absolute;
  288. top: 0;
  289. left: 0;
  290. height: 18px;
  291. width: 18px;
  292. background-color: transparent;
  293. border: 1px solid #f48800;
  294. border-radius: 4px;
  295. }
  296. /* On mouse-over, add a grey background color */
  297. .container-checkbox:hover input~.checkmark {
  298. border-color: #f48800;
  299. }
  300. /* When the checkbox is checked, add a blue background */
  301. .container-checkbox input:checked~.checkmark {
  302. background-color: #f48800;
  303. border-color: #f48800;
  304. }
  305. /* Create the checkmark/indicator (hidden when not checked) */
  306. .container-checkbox .checkmark:after {
  307. content: "";
  308. position: absolute;
  309. display: none;
  310. }
  311. /* Show the checkmark when checked */
  312. .container-checkbox input:checked~.checkmark:after {
  313. display: block;
  314. }
  315. /* Style the checkmark/indicator */
  316. .container-checkbox .checkmark:after {
  317. left: 5px;
  318. top: 2px;
  319. width: 5px;
  320. height: 10px;
  321. border: solid #ffffff;
  322. border-width: 0 2px 2px 0;
  323. -webkit-transform: rotate(45deg);
  324. -ms-transform: rotate(45deg);
  325. transform: rotate(45deg);
  326. }
  327. </style>