import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class UserService {

  constructor() { }

  UserList = [
    {username:"123",password:"123"},
    {username:"qian",password:"duoduo"},
  ]
  /**
   * 检查用户密码是否正确
   */
  checkUserPassword(user:{
    username:string
    password:string
  }){
    // 根据username查询用户信息
    let exists = this.UserList.find(item=>item.username == user.username)
    if(!exists){
      throw "该用户不存在"
    }
    // 验证该用户密码是否正确
    if(exists.password != user.password){
      throw "用户密码错误"
    }

    localStorage.setItem("USER_AUTH",JSON.stringify(exists))
    return true
  }
}
