Java tutorial
/* * Copyright 2013-2015 cetvision.com. All rights reserved. * Support: http://www.cetvision.com * License: http://www.cetvision.com/license */ package com.dp2345.controller.mall.member; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.dp2345.Setting; import com.dp2345.controller.mall.BaseController; import com.dp2345.entity.Member; import com.dp2345.service.MemberService; import com.dp2345.util.SettingUtils; /** * Controller - - ? * * @author CETVISION CORP * @version 2.0.3 */ @Controller("shopMemberPasswordController") @RequestMapping("/member/password") public class PasswordController extends BaseController { @Resource(name = "memberServiceImpl") private MemberService memberService; /** * ??? */ @RequestMapping(value = "/check_current_password", method = RequestMethod.GET) public @ResponseBody boolean checkCurrentPassword(String currentPassword) { if (StringUtils.isEmpty(currentPassword)) { return false; } Member member = memberService.getCurrent(); if (StringUtils.equals(DigestUtils.md5Hex(currentPassword), member.getPassword())) { return true; } else { return false; } } /** * */ @RequestMapping(value = "/edit", method = RequestMethod.GET) public String edit() { return "shop/member/password/edit"; } /** * */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String currentPassword, String password, HttpServletRequest request, RedirectAttributes redirectAttributes) { if (StringUtils.isEmpty(password) || StringUtils.isEmpty(currentPassword)) { return ERROR_VIEW; } if (!isValid(Member.class, "password", password)) { return ERROR_VIEW; } Setting setting = SettingUtils.get(); if (password.length() < setting.getPasswordMinLength() || password.length() > setting.getPasswordMaxLength()) { return ERROR_VIEW; } Member member = memberService.getCurrent(); if (!StringUtils.equals(DigestUtils.md5Hex(currentPassword), member.getPassword())) { return ERROR_VIEW; } member.setPassword(DigestUtils.md5Hex(password)); memberService.update(member); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:edit.jhtml"; } }