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.

388 lines
14 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
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="dialog" :width="$vuetify.breakpoint.smAndUp ? 423 : 294"
  71. @click:outside="$router.push(localePath('/user'))">
  72. <v-card class="tw-p-[30px]" :height="$vuetify.breakpoint.smAndUp ? 289 : 290">
  73. <v-spacer class="d-flex align-center tw-justify-between tw-mb-[30px]">
  74. <div class="tw-text-[20px] tw-font-bold tw-text-black">
  75. {{ $t("Verify your email") }}
  76. </div>
  77. <v-btn @click="$router.push(localePath('/user'))" icon>
  78. <v-icon> mdi-close </v-icon>
  79. </v-btn>
  80. </v-spacer>
  81. <v-spacer class="tw-mb-[40px]">
  82. <div class="tw-text-[16px] tw-text-neutrals-800">
  83. {{ $t("Oops! Seems like you haven't verified your email,please click the button below to resend a verification email.")}}
  84. </div>
  85. </v-spacer>
  86. <button @click="resendVerifyEmail()" class="tw-bg-primary-1 hover:tw-bg-primary-light tw-text-white tw-text-[18px] tw-rounded-[16px] tw-px-[77px] tw-py-[13px]">
  87. {{ $t("Resend verification email") }}
  88. </button>
  89. <!-- <v-btn @click="resendVerifyEmail" class="primary tw-text-[18px] tw-w-auto" rounded
  90. :disabled="countdown > 0">
  91. <span v-if="countdown > 0">
  92. {{ `(${this.countdown})` }}
  93. </span>
  94. </v-btn> -->
  95. </v-card>
  96. </v-dialog>
  97. <v-dialog v-model="deleteDialog" :width="$vuetify.breakpoint.smAndUp ? 423 : 294"
  98. @click:outside="$router.push(localePath('/user'))">
  99. <v-card class="tw-p-[30px]" :height="$vuetify.breakpoint.smAndUp ? 289 : 290">
  100. <v-spacer class="d-flex tw-justify-between align-center tw-mb-[30px]">
  101. <div class="tw-text-[20px] tw-text-black tw-font-bold">
  102. {{ $t("Reactivate your account") }}
  103. </div>
  104. <v-btn @click="$router.push(localePath('/user'))" icon>
  105. <v-icon> mdi-close </v-icon>
  106. </v-btn>
  107. </v-spacer>
  108. <v-spacer class="tw-mb-[40px]">
  109. <div class="tw-text-[16px] tw-text-neutrals-800 tw-font-bold">
  110. {{ $t("Welcome back!")}}
  111. </div>
  112. <div class="tw-text-[16px] tw-text-neutrals-800">
  113. {{ $t("Looks like your account has been deactivated.")}}
  114. <br />
  115. {{ $t("Would you like to reactivate this account?")}}
  116. </div>
  117. </v-spacer>
  118. <button class="tw-bg-primary-1 tw-text-white hover:tw-bg-primary-light tw-text-[18px] tw-rounded-[16px] tw-px-[86px] tw-py-[13px]">
  119. {{ $t("Reactivate my account") }}
  120. </button>
  121. <!-- <v-btn class="primary tw-w-auto" rounded
  122. :disabled="countdown > 0">
  123. <span v-if="countdown > 0">
  124. {{ `(${this.countdown})` }}
  125. </span>
  126. </v-btn> -->
  127. </v-card>
  128. </v-dialog>
  129. </div>
  130. </template>
  131. <script>
  132. import { getCurrentTime } from "~/utils/assist";
  133. export default {
  134. name: "login",
  135. layout: "login",
  136. auth: false,
  137. data() {
  138. return {
  139. timer: null,
  140. showPass: false,
  141. resendDialog: false,
  142. wrongMessageActive: false,
  143. verifyEmailSent: false,
  144. valid: false,
  145. remember: false,
  146. countdown: 0,
  147. userData: {
  148. Account: '',
  149. Password: '',
  150. },
  151. rules: {
  152. require: value => !!value || this.$t('Required.'),
  153. email: v => /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(v) || this.$t('Invalid email'),
  154. // checkPassword: v => (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) && v.length >= 8 && v.length <= 20) || '請輸入密碼',
  155. checkPassword: v => v.length >= 1 || '請輸入密碼',
  156. },
  157. deleteDialog: false,
  158. dialog: false,
  159. }
  160. },
  161. watch: {
  162. remember: {
  163. handler: function () {
  164. if (this.remember == true) {
  165. this.$auth.$storage.setUniversal("userPassword", this.userData.Password);
  166. this.$auth.$storage.setUniversal("userAccount", this.userData.Account);
  167. }else{
  168. this.$auth.$storage.removeUniversal("userPassword");
  169. this.$auth.$storage.removeUniversal("userAccount", this.userData.Account);
  170. }
  171. },
  172. },
  173. },
  174. mounted(){
  175. var userAccount = this.$auth.$storage.getUniversal('userAccount');
  176. var userPassword = this.$auth.$storage.getUniversal('userPassword');
  177. this.userData.Account = userAccount ? userAccount : '';
  178. this.userData.Password = userPassword ? userPassword : '';
  179. if(this.userData.Account !=='' && this.userData.Password !==''){
  180. this.valid = true;
  181. }else{
  182. this.valid = false;
  183. }
  184. },
  185. methods: {
  186. async userLogin() {
  187. let that = this;
  188. if (!that.$refs.loginFormRef.validate()) return;
  189. console.log("測試登錄接口請求開始:" + getCurrentTime());
  190. try {
  191. const response =await that.$auth.loginWith('local', { data: that.userData });
  192. that.$auth.$storage.removeUniversal('authtoken');
  193. console.log("測試登錄接口請求結束:" + getCurrentTime());
  194. if(response.data.STATUSCODE==200){
  195. let data = response.data.DATA;
  196. console.log(JSON.stringify(data.authtoken));
  197. if(data.authtoken){
  198. const authtoken = data.authtoken;
  199. that.$auth.$storage.setUniversal('authtoken', authtoken);
  200. that.$auth.loggedIn ? that.$router.push(that.$auth.$storage.getUniversal('userBeforePath')) : that.$auth.redirect('login');
  201. }
  202. }else if(response.data.STATUSCODE==500){
  203. that.$auth.redirect('login');
  204. }else if(response.data.STATUSCODE==401){
  205. if(response.data.MSG == "0"){
  206. this.dialog = true;
  207. }else if(response.data.MSG == "2"){
  208. this.deleteDialog = true;
  209. }else if(response.data.MSG == "帳號或密碼不正確"){
  210. this.wrongMessageActive = true;
  211. }
  212. }else{
  213. // that.resendDialog = !that.resendDialog;
  214. that.wrongMessageActive = true;
  215. }
  216. } catch(err) {
  217. console.log(err);
  218. // if(err && err.response && err.response.status){
  219. // err.response.status === 403 ? that.resendDialog = !that.resendDialog : err.response.status === 401 ? that.wrongMessageActive = true : that.resendDialog;
  220. // }
  221. }
  222. },
  223. resendVerifyEmail() {
  224. this.countdown = 60;
  225. this.$axios
  226. .post(
  227. `/trending/api/Signup/ReSendVerifyMail?Email=${this.userData.Account}`
  228. )
  229. .then((response) => {
  230. //console.log(JSON.stringify(response))
  231. if(response && response.data){
  232. clearInterval(this.timer);
  233. this.timer = setInterval(() => {
  234. if (this.countdown > 0) {
  235. this.countdown--;
  236. }
  237. if (this.countdown === 0) {
  238. clearInterval(this.timer);
  239. }
  240. }, 1000);
  241. }
  242. })
  243. .catch((error) => {
  244. console.log(error);
  245. });
  246. },
  247. updateValid(){
  248. if(this.userData.Account !=='' && this.userData.Password !==''){
  249. this.valid = true;
  250. }else{
  251. this.valid = false;
  252. }
  253. },
  254. },
  255. beforeUnmount() {
  256. if(this.timer!=null){
  257. clearInterval(this.timer);
  258. }
  259. },
  260. beforeRouteEnter(to, from, next) {
  261. next(vm => {
  262. if (from.name) {
  263. if (!from.path.includes('user')) {
  264. vm.$auth.$storage.setUniversal("userBeforePath", from.fullPath, true)
  265. }
  266. }
  267. if (vm.$auth.loggedIn) {
  268. vm.$router.push(vm.$auth.$storage.getUniversal('userBeforePath') || '/')
  269. }
  270. else {
  271. next()
  272. }
  273. })
  274. },
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. $border-style: 1px solid #E5E5E5;
  279. .title {
  280. font-weight: 700;
  281. font-size: 26px;
  282. line-height: 34px;
  283. letter-spacing: 0.02em;
  284. color: #232323;
  285. }
  286. .btn-border {
  287. border: $border-style;
  288. }
  289. .seperator {
  290. border-bottom: $border-style;
  291. text-align: center;
  292. height: 12px;
  293. margin: 20px 0 30px;
  294. }
  295. :deep(.v-text-field.v-text-field--enclosed .v-text-field__details) {
  296. margin-bottom: 0;
  297. padding: 0;
  298. .v-messages {
  299. display: none;
  300. }
  301. .v-messages.error--text {
  302. display: block;
  303. margin-top: 4px;
  304. margin-bottom: 16px;
  305. }
  306. }
  307. /* The container */
  308. .container-checkbox {
  309. display: block;
  310. position: relative;
  311. padding-left: 28px;
  312. cursor: pointer;
  313. -webkit-user-select: none;
  314. -moz-user-select: none;
  315. -ms-user-select: none;
  316. user-select: none;
  317. }
  318. /* Hide the browser's default checkbox */
  319. .container-checkbox input {
  320. position: absolute;
  321. opacity: 0;
  322. cursor: pointer;
  323. }
  324. /* Create a custom checkbox */
  325. .container-checkbox .checkmark {
  326. position: absolute;
  327. top: 0;
  328. left: 0;
  329. height: 18px;
  330. width: 18px;
  331. background-color: transparent;
  332. border: 1px solid #f48800;
  333. border-radius: 4px;
  334. }
  335. /* On mouse-over, add a grey background color */
  336. .container-checkbox:hover input~.checkmark {
  337. border-color: #f48800;
  338. }
  339. /* When the checkbox is checked, add a blue background */
  340. .container-checkbox input:checked~.checkmark {
  341. background-color: #f48800;
  342. border-color: #f48800;
  343. }
  344. /* Create the checkmark/indicator (hidden when not checked) */
  345. .container-checkbox .checkmark:after {
  346. content: "";
  347. position: absolute;
  348. display: none;
  349. }
  350. /* Show the checkmark when checked */
  351. .container-checkbox input:checked~.checkmark:after {
  352. display: block;
  353. }
  354. /* Style the checkmark/indicator */
  355. .container-checkbox .checkmark:after {
  356. left: 5px;
  357. top: 2px;
  358. width: 5px;
  359. height: 10px;
  360. border: solid #ffffff;
  361. border-width: 0 2px 2px 0;
  362. -webkit-transform: rotate(45deg);
  363. -ms-transform: rotate(45deg);
  364. transform: rotate(45deg);
  365. }
  366. </style>