user.service.ts 892 B

1234567891011121314151617181920212223242526272829303132
  1. import { Injectable } from '@angular/core';
  2. import * as Parse from "parse";
  3. @Injectable({
  4. providedIn: 'root'
  5. })
  6. export class UserService {
  7. get currentUser() {
  8. try {
  9. let currentUser = JSON.parse(localStorage.getItem("USER_AUTH") || ""); // 从本地存储中获取当前用户信息
  10. return currentUser;
  11. } catch (err) { }
  12. return {};
  13. }
  14. set currentUser(v) {
  15. localStorage.setItem("USER_AUTH", JSON.stringify(v)); // 将当前用户信息存储到本地存储中
  16. }
  17. constructor() { }
  18. async checkUserPassword(user: {
  19. username: string;
  20. password: string;
  21. }) {
  22. let exists = await Parse.User.logIn(user?.username, user?.password); // 使用 Parse.User.logIn() 方法验证用户的用户名和密码
  23. if (exists?.id) {
  24. return true; // 如果验证成功,返回 true
  25. }
  26. return false; // 如果验证失败,返回 false
  27. }
  28. }