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.

288 lines
11 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
  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.localePath("/")) : that.$auth.redirect('login');
  164. }
  165. } catch(err) {
  166. // err.response.status === 403 ? this.resendDialog = !this.resendDialog : err.response.status === 401 ? this.wrongMessageActive = true : this.resendDialog
  167. }
  168. },
  169. resendVerifyEmail() {
  170. },
  171. updateValid(){
  172. if(this.userData.Account !=='' && this.userData.Password !==''){
  173. this.valid = true;
  174. }else{
  175. this.valid = false;
  176. }
  177. }
  178. },
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. $border-style: 1px solid #E5E5E5;
  183. .title {
  184. font-weight: 700;
  185. font-size: 26px;
  186. line-height: 34px;
  187. letter-spacing: 0.02em;
  188. color: #232323;
  189. }
  190. .btn-border {
  191. border: $border-style;
  192. }
  193. .seperator {
  194. border-bottom: $border-style;
  195. text-align: center;
  196. height: 12px;
  197. margin: 20px 0 30px;
  198. }
  199. :deep(.v-text-field.v-text-field--enclosed .v-text-field__details) {
  200. margin-bottom: 0;
  201. padding: 0;
  202. .v-messages {
  203. display: none;
  204. }
  205. .v-messages.error--text {
  206. display: block;
  207. margin-top: 4px;
  208. margin-bottom: 16px;
  209. }
  210. }
  211. /* The container */
  212. .container-checkbox {
  213. display: block;
  214. position: relative;
  215. padding-left: 28px;
  216. cursor: pointer;
  217. -webkit-user-select: none;
  218. -moz-user-select: none;
  219. -ms-user-select: none;
  220. user-select: none;
  221. }
  222. /* Hide the browser's default checkbox */
  223. .container-checkbox input {
  224. position: absolute;
  225. opacity: 0;
  226. cursor: pointer;
  227. }
  228. /* Create a custom checkbox */
  229. .container-checkbox .checkmark {
  230. position: absolute;
  231. top: 0;
  232. left: 0;
  233. height: 18px;
  234. width: 18px;
  235. background-color: transparent;
  236. border: 1px solid #f48800;
  237. border-radius: 4px;
  238. }
  239. /* On mouse-over, add a grey background color */
  240. .container-checkbox:hover input~.checkmark {
  241. border-color: #f48800;
  242. }
  243. /* When the checkbox is checked, add a blue background */
  244. .container-checkbox input:checked~.checkmark {
  245. background-color: #f48800;
  246. border-color: #f48800;
  247. }
  248. /* Create the checkmark/indicator (hidden when not checked) */
  249. .container-checkbox .checkmark:after {
  250. content: "";
  251. position: absolute;
  252. display: none;
  253. }
  254. /* Show the checkmark when checked */
  255. .container-checkbox input:checked~.checkmark:after {
  256. display: block;
  257. }
  258. /* Style the checkmark/indicator */
  259. .container-checkbox .checkmark:after {
  260. left: 5px;
  261. top: 2px;
  262. width: 5px;
  263. height: 10px;
  264. border: solid #ffffff;
  265. border-width: 0 2px 2px 0;
  266. -webkit-transform: rotate(45deg);
  267. -ms-transform: rotate(45deg);
  268. transform: rotate(45deg);
  269. }
  270. </style>