|
|
|
@ -4,6 +4,7 @@ import com.zhiyun.zhiyun03.user.entity.User;
|
|
|
|
|
import com.zhiyun.zhiyun03.user.service.UserService;
|
|
|
|
|
import com.zhiyun.zhiyun03.user.vo.UserVo;
|
|
|
|
|
import com.zhiyun.zhiyun03.utils.common.JsonResult;
|
|
|
|
|
import com.zhiyun.zhiyun03.utils.common.ResultCode;
|
|
|
|
|
import com.zhiyun.zhiyun03.utils.exception.ServiceException;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
@ -23,61 +24,22 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/user")
|
|
|
|
|
public class UserController {
|
|
|
|
|
@Autowired
|
|
|
|
|
UserService userService;
|
|
|
|
|
|
|
|
|
|
@RequestMapping(path = "/login")
|
|
|
|
|
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = "username") String username, @RequestParam(name = "password") String password, Model model) {
|
|
|
|
|
// //1、讲页面提交的密码进行md5加密
|
|
|
|
|
// password = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
|
|
|
|
|
|
|
//2、根据用户名查数据库
|
|
|
|
|
public JsonResult<User> login(HttpServletRequest request, @RequestParam(name = "userCode") String username, @RequestParam(name = "password") String password) {
|
|
|
|
|
if (username.isEmpty() || password.isEmpty()) {
|
|
|
|
|
return JsonResult.error(ResultCode.NO_NULL_ERROR, "账号或密码不能为空");
|
|
|
|
|
}
|
|
|
|
|
User login = userService.login(username, password);
|
|
|
|
|
String url="";
|
|
|
|
|
//3、判断是否查询到
|
|
|
|
|
if (login != null) {
|
|
|
|
|
//(2)成功 1.把数据保存到session中 2.跳转页面到index.html
|
|
|
|
|
request.getSession().setAttribute("USER", login);
|
|
|
|
|
url="layui-v2.6.8/index";
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// response.sendRedirect("/static/layui-v2.6.8/index.html");
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
//(3)失败 1.把异常信息保存到model中 2.跳转到login.html
|
|
|
|
|
model.addAttribute("msg","登录名或者密码错误");
|
|
|
|
|
url = "layui-v2.6.8/login";
|
|
|
|
|
return JsonResult.success(ResultCode.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
//经过视图解析器,最终路径解析为 前缀(/templates/)+url+后缀(.html)
|
|
|
|
|
return url;
|
|
|
|
|
|
|
|
|
|
return JsonResult.error(ResultCode.USER_ACCOUNT_ERROR, "账号或密码错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @RequestMapping("/login1")
|
|
|
|
|
// public JsonResult login1(HttpRequest request,HttpServletResponse response, @RequestBody UserVo userVo){
|
|
|
|
|
// if (userVo.getUsername().isEmpty()&userVo.getPassword().isEmpty())
|
|
|
|
|
// {
|
|
|
|
|
// throw new ServiceException("300","账号密码不为空");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// User user =userService.login(userVo.getUsername(), userVo.getPassword());
|
|
|
|
|
// if (user!=null)
|
|
|
|
|
// {
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return JsonResult.success();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|