admin
2021-11-13 5ac194b4319c4f1e1e0e167243ffcc20d8924961
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.ks.app.controller.admin;
 
import com.ks.app.entity.AdminUser;
import com.ks.app.service.inter.AdminUserService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.NotEmpty;
 
@Controller
@RequestMapping("/admin/api/user")
public class AdminUserController {
 
    @Resource
    private AdminUserService adminUserService;
 
    @ResponseBody
    @RequestMapping("login")
    public String login(@NotEmpty(message = "账号不能为空") String account, @NotEmpty(message = "密码不能为空") String pwd, @NotEmpty(message = "验证码不能为空") String code, BindingResult bindingResult, HttpSession session) {
        if (bindingResult.hasErrors()) {
            String msg = bindingResult.getFieldError().getDefaultMessage();
            return JsonUtil.loadFalseResult(msg);
        }
 
        String captcha = session.getAttribute("captcha") + "";
        if (StringUtil.isNullOrEmpty(captcha) || !captcha.equalsIgnoreCase(code)) {
            return JsonUtil.loadFalseResult("验证码错误");
        }
 
        AdminUser adminUser = adminUserService.selectByAccount(account);
        if (adminUser == null) {
            return JsonUtil.loadFalseResult("账号不存在");
        }
 
        if (!StringUtil.Md5(pwd).equalsIgnoreCase(adminUser.getPwd())) {
            return JsonUtil.loadFalseResult("密码错误");
        }
 
        session.setAttribute("ADMIN_USER", adminUser);
        return JsonUtil.loadTrueResult("登录成功");
    }
 
 
}