//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.luozhihui.project.controller;

import com.luozhihui.project.common.LoginResponse;
import com.luozhihui.project.entity.User;
import com.luozhihui.project.mapper.UserLoginMapper;
import com.luozhihui.project.util.JwtUtil;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/api"})
@CrossOrigin
public class UserLoginController {
    @Resource
    UserLoginMapper userLoginMapper;

    public UserLoginController() {
    }

    @PostMapping({"/login"})
    public LoginResponse login(@RequestParam("Phone") String Phone, @RequestParam("PassWord") String PassWord) {
        List<User> userList = this.userLoginMapper.findByPhone(Phone);
        System.out.println(userList);
        if (userList.isEmpty()) {
            return new LoginResponse((Object)null, (Object)null, 500, "用户不存在");
        } else {
            User user = (User)userList.get(0);
            if (user.getPassWord().equals(PassWord)) {
                JwtUtil jwtUtil = new JwtUtil();
                String token = JwtUtil.createToken(((User)userList.get(0)).getPhone());
                return new LoginResponse(token, user.getUserId(), 200, "登录成功");
            } else {
                return new LoginResponse((Object)null, (Object)null, 500, "账号或密码错误");
            }
        }
    }
}
