admin
2021-02-06 6c09cbd70388ae53ec593de253f69cfa1a3eeda7
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
51
52
53
54
55
package com.ks.daylucky.controller.admin;
 
import com.ks.lucky.exception.LuckySponsorException;
import com.ks.lucky.pojo.DO.LuckySponsors;
import com.ks.lucky.remote.service.LuckySponsorService;
import org.apache.dubbo.config.annotation.Reference;
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 javax.servlet.http.HttpSession;
import javax.validation.constraints.NotEmpty;
import java.util.Date;
 
@Controller
@RequestMapping("/admin/api/user")
public class AdminUserController {
 
    @Reference(version = "1.0.0")
    private LuckySponsorService luckySponsorService;
 
    @ResponseBody
    @RequestMapping("login")
    public String login(@NotEmpty(message = "账号不能为空") String account, @NotEmpty(message = "密码不能为空") String pwd, BindingResult bindingResult, HttpSession session) {
        if (bindingResult.hasErrors()) {
            String msg = bindingResult.getFieldError().getDefaultMessage();
            return JsonUtil.loadFalseResult(msg);
        }
 
        LuckySponsors sponsors = luckySponsorService.getSponsorByAccount(account);
        if (sponsors == null) {
            return JsonUtil.loadFalseResult("赞助商不存在");
        }
 
        if (!sponsors.getPwd().equalsIgnoreCase(pwd)) {
            return JsonUtil.loadFalseResult("用户名账号或密码错误");
        }
 
        LuckySponsors update = new LuckySponsors();
        update.setId(sponsors.getId());
        update.setLatestLoginTime(new Date());
        try {
            luckySponsorService.updateSponsor(update);
        } catch (LuckySponsorException e) {
            e.printStackTrace();
        }
 
        session.setAttribute("SPONSOR_LOGIN", sponsors);
        return JsonUtil.loadTrueResult("登录成功");
    }
 
 
}