Commit d336d472 authored by ysongq's avatar ysongq

密码修改

parent 58e75822
...@@ -2,9 +2,11 @@ package com.jz.dm.mall.moduls.controller.customer; ...@@ -2,9 +2,11 @@ package com.jz.dm.mall.moduls.controller.customer;
import com.baomidou.mybatisplus.extension.api.R; import com.baomidou.mybatisplus.extension.api.R;
import com.jz.common.base.BaseController; import com.jz.common.base.BaseController;
import com.jz.common.base.CurrentUser;
import com.jz.common.constant.RedisMessageConstant; import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.constant.ResultCode; import com.jz.common.constant.ResultCode;
import com.jz.common.constant.ResultMsg; import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.SessionUtils;
import com.jz.dm.mall.moduls.entity.MallCustomer; import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode; import com.jz.common.utils.StatusCode;
...@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map; import java.util.Map;
/** /**
...@@ -72,14 +75,38 @@ public class MallCustomerController extends BaseController { ...@@ -72,14 +75,38 @@ public class MallCustomerController extends BaseController {
return new Result(false, "注册失败!", StatusCode.ERROR); return new Result(false, "注册失败!", StatusCode.ERROR);
} }
/**
* 获取用户信息
* @return
*/
@GetMapping("/getLoginUserName")
@ApiOperation(value = "注册用户", notes = "添加用户")
public Result getLoginUserName (HttpServletRequest request) {
// 从session中获取id
try {
MallCustomer mallCustomer = (MallCustomer) SessionUtils.getUserCurrent(request,"mallCustomer");
Long customerId = 1L;
// Long customerId = mallCustomer.getCustomerId();
MallCustomer user = mallCustomerService.selectByUser(customerId);
return new Result(true, "获取用户信息成功!", StatusCode.OK, user);
}catch (Exception e) {
e.printStackTrace();
return new Result(false, "获取用户信息失败");
}
}
@PostMapping(value = "/updatePassword") @PostMapping(value = "/updatePassword")
public Result updatePassword(String username, String password) throws Exception { public Result updatePassword(String oldPassword, String newPassword,HttpServletRequest request) throws Exception {
if (username != null && password != null) { // 获取用户信息
mallCustomerService.updatePassword(username, password); MallCustomer mallCustomer = (MallCustomer) getLoginUserName(request).getData();
return new Result(true, "密码修改成功!"); // 如果密码一致
if (mallCustomer.getPassword().equals(oldPassword)) {
// 修改密码
Long customerId = mallCustomer.getCustomerId();
mallCustomerService.updatePassword(customerId, newPassword);
return new Result(true, "密码修改成功");
} }
return new Result(false, "密码修改失败!"); return new Result(false, "密码修改失败");
} }
} }
\ No newline at end of file
...@@ -2,14 +2,10 @@ package com.jz.dm.mall.moduls.mapper; ...@@ -2,14 +2,10 @@ package com.jz.dm.mall.moduls.mapper;
import com.jz.common.base.BaseMapper; import com.jz.common.base.BaseMapper;
import com.jz.dm.mall.moduls.entity.MallCustomer; import com.jz.dm.mall.moduls.entity.MallCustomer;
<<<<<<< HEAD
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
=======
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
>>>>>>> 4f2273addb37e5eb2f1b255fb4f521ccb462856f
import java.util.Map; import java.util.Map;
...@@ -59,6 +55,7 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> { ...@@ -59,6 +55,7 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> {
MallCustomer findById(@Param("customerId") Long customerId); MallCustomer findById(@Param("customerId") Long customerId);
@Update(" update t_mall_customer set password = #{password} where customer_account = #{customer_account}") void updatePassword(Map map);
void updatePassword(@Param("customer_account") String username, @Param("password") String password);
MallCustomer selectByCustomerId(Long customerId);
} }
\ No newline at end of file
...@@ -43,8 +43,15 @@ public interface MallCustomerService { ...@@ -43,8 +43,15 @@ public interface MallCustomerService {
/** /**
* 修改密码 * 修改密码
* @param username * @param customerId
* @param password * @param password
*/ */
void updatePassword(@Param("customer_account") String username, @Param("password") String password); void updatePassword(Long customerId, String password);
/**
* 通过id查找用户信息
* @param customerId
* @return
*/
MallCustomer selectByUser(Long customerId);
} }
\ No newline at end of file
...@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; ...@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -133,16 +134,31 @@ public class MallCustomerServiceImpl implements MallCustomerService { ...@@ -133,16 +134,31 @@ public class MallCustomerServiceImpl implements MallCustomerService {
/** /**
* 修改密码 * 修改密码
* *
* @param username * @param customerId
* @param password * @param password
*/ */
@Override @Override
public void updatePassword(String username, String password) { public void updatePassword(Long customerId, String password) {
MallCustomer mallCustomer = tMallCustomerDao.selectByPhone(username); MallCustomer mallCustomer = tMallCustomerDao.selectByCustomerId(customerId);
if (mallCustomer != null) { if (mallCustomer != null) {
tMallCustomerDao.updatePassword(username, password); Map map = new HashMap();
map.put("password", password);
map.put("customerId", customerId);
tMallCustomerDao.updatePassword(map);
} }
} }
/**
* 通过id查找用户信息
*
* @param customerId
* @return
*/
@Override
public MallCustomer selectByUser(Long customerId) {
MallCustomer mallCustomer = tMallCustomerDao.selectByCustomerId(customerId);
return mallCustomer;
}
} }
\ No newline at end of file
...@@ -66,4 +66,4 @@ mybatis: ...@@ -66,4 +66,4 @@ mybatis:
logging: logging:
level: level:
com.jz.manage: debug com.jz.dm.mall: debug
...@@ -194,4 +194,15 @@ ...@@ -194,4 +194,15 @@
WHERE customer_id =#{customerId} WHERE customer_id =#{customerId}
AND del_flag ='N'" AND del_flag ='N'"
</select> </select>
<select id="selectByCustomerId" resultMap="TMallCustomerMap">
select
customer_id, department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag
from t_mall_customer
where customer_id = #{customerId};
</select>
<update id="updatePassword" parameterType="map">
update t_mall_customer set password =#{password} where customer_id = #{customerId};
</update>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment