import { Injectable } from '@angular/core'; import * as Parse from "parse"; @Injectable({ providedIn: 'root' }) export class UserService { get currentUser() { try { let currentUser = JSON.parse(localStorage.getItem("USER_AUTH") || ""); // 从本地存储中获取当前用户信息 return currentUser; } catch (err) { } return {}; } set currentUser(v) { localStorage.setItem("USER_AUTH", JSON.stringify(v)); // 将当前用户信息存储到本地存储中 } constructor() { } async checkUserPassword(user: { username: string; password: string; }) { let exists = await Parse.User.logIn(user?.username, user?.password); // 使用 Parse.User.logIn() 方法验证用户的用户名和密码 if (exists?.id) { return true; // 如果验证成功,返回 true } return false; // 如果验证失败,返回 false } }