/** * 用户登录 * * @param uname * @param pwd * @return */ @RequestMapping(value = "/user/login") public void userLogin( String uname, String pwd, String code, HttpServletRequest request, HttpServletResponse response) { // TODO 验证码系统 try { PrintWriter out = response.getWriter(); UserInfo user = this.userService.getUserInfoByName(uname); if (user != null) { if (pwd.equals(user.getPassword())) { WebUtil.setLoginCookie(user.getId() + "", response); out.print("0"); // 登陆成功 return; } else { out.print("1"); // 密码错误 return; } } else { out.print("2"); // 用户不存在 return; } } catch (Exception ex) { ex.printStackTrace(); } }
/** * 用户注册 * * @param uid * @param name * @param age * @param sex * @param create_time * @param last_login_date * @param STATUS * @param request */ @RequestMapping(value = "/user/reg") public String userRegister( String uid, String age, String sex, String email, String pwd, HttpServletRequest request, HttpServletResponse response) { try { if (request instanceof MultipartHttpServletRequest) { request = (MultipartHttpServletRequest) request; } else { } System.out.println("in user reg.." + uid + ":" + pwd + ":" + age); UserInfo user = new UserInfo(); user.setName(uid); user.setAge(Integer.parseInt(age)); user.setPassword(pwd); user.setCreateTime(new Date()); user.setLastLoginDate(new Date()); user.setHeadImg("/res/img/head.jpg"); userService.registerUser(user, null); WebUtil.setLoginCookie(user.getId() + "", response); return "/user/list.do?page=0&size=10"; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return "/pages/user/login.jsp"; }