|
@@ -0,0 +1,48 @@
|
|
|
+package cn.minbb.edu.controller;
|
|
|
+
|
|
|
+import cn.minbb.edu.model.User;
|
|
|
+import cn.minbb.edu.service.UserService;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/user")
|
|
|
+public class UserController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
|
+ public String login(
|
|
|
+ @RequestParam(value = "username") String username,
|
|
|
+ @RequestParam(value = "password") String password,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ User user = userService.findUserByUsername(username);
|
|
|
+ if (user == null) {
|
|
|
+ // 用户不存在
|
|
|
+ result.put("result", 404);
|
|
|
+ result.put("summary", "用户不存在");
|
|
|
+ } else {
|
|
|
+ if (password.equals(user.getPassword())) {
|
|
|
+ // OK
|
|
|
+ result.put("result", 200);
|
|
|
+ result.put("summary", "登录成功");
|
|
|
+ result.put("data", user);
|
|
|
+ } else {
|
|
|
+ // 密码错误
|
|
|
+ result.put("result", 404);
|
|
|
+ result.put("summary", "密码错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return JSONObject.toJSONString(result);
|
|
|
+ }
|
|
|
+}
|