Commit e0c98ce6 authored by zhangc's avatar zhangc

Merge branch 'dm_dev' of gitlab.ioubuy.cn:yaobenzhang/dm_project into dm_dev

 Conflicts:
	jz-dm-common/pom.xml
	jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/mapper/MallCustomerDao.java
parents c5df897f a5de1461
package com.jz.common.utils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* @ClassName: 将数据从session存储/取出
* @Author: Carl
* @Date: 2020/12/2
* @Version:
*/
public class UserContextUtil {
/**
* 从session中获取数据
* @param objName 存储到session中的对象的变量名
*/
public static Object pop(String objName) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
return request.getSession().getAttribute(objName);
}
/**
* 把数据存储到session中
* @param objName 存储到session中的对象的变量名
* @param o 存储的任意数据
*/
public static void push(String objName, Object o) {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
request.getSession().setAttribute(objName, o);
}
}
......@@ -2,15 +2,21 @@ package com.jz.dm.mall.moduls.controller.customer;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
import com.jz.common.utils.UserContextUtil;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.dm.mall.moduls.service.MallCustomerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @ClassName:
* @Author: Carl
......@@ -35,15 +41,18 @@ public class LoginController {
* @param password 密码
* @return
*/
@GetMapping(value = "/login")
public Result<MallCustomer> login(String username, String password) {
@PostMapping(value = "/login")
public Result<MallCustomer> login(String username, String password, HttpServletRequest request) {
// 手机
String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证
if (username.matches(username)) {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(username);
if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(username) && mallCustomer.getPassword().equals(password)){
session.setAttribute("customer_id", mallCustomer.getCustomerId());
session.setAttribute("customer_account", mallCustomer.getCustomerAccount());
return new Result<>(true, "登录成功!", StatusCode.OK);
}
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
......@@ -52,9 +61,13 @@ public class LoginController {
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username) && mallCustomer.getPassword().equals(password)){
session.setAttribute("customer_id", mallCustomer.getCustomerId());
session.setAttribute("customer_account", mallCustomer.getCustomerAccount());
return new Result<>(true, "登录成功!", StatusCode.OK);
}
}
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
}
}
......@@ -32,20 +32,14 @@ public class MallCustomerController extends BaseController {
@Autowired
private RedisTemplate redisTemplate;
@PostMapping(value = "/saveCustomer")
public Result saveCustomer(Map<String, String> paramMap) {
return null;
}
/**
* 手机号码校验
* @param paramMap
* @param res
* @return
*/
@PostMapping(value = "/check")
public Result loginCheck(@RequestBody Map<String, String> paramMap, HttpServletResponse res) {
public Result loginCheck(@RequestBody Map<String, String> paramMap) {
// 获取手机号码
String telephone = paramMap.get("telephone");
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
......
......@@ -3,6 +3,8 @@ package com.jz.dm.mall.moduls.mapper;
import com.jz.common.base.BaseMapper;
import com.jz.common.entity.MallCustomer;
import java.util.Map;
/**
* 商城用户(TMallCustomer)表数据库访问层
*
......@@ -10,9 +12,19 @@ import com.jz.common.entity.MallCustomer;
* @since 2020-12-01 10:41:39
*/
public interface MallCustomerDao extends BaseMapper<MallCustomer> {
/**
* 根据账号查询用户信息
* @param username
* @return
*/
MallCustomer selectByAccount(String username);
/**
* 根据手机号查询用户信息
* @param username
* @return
*/
MallCustomer selectByPhone(String username);
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ package com.jz.dm.mall.moduls.service;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import java.util.Map;
/**
* 商城用户(TMallCustomer)表服务接口
*
......@@ -24,4 +26,5 @@ public interface MallCustomerService {
*/
MallCustomer selectByPhone(String username);
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ import com.jz.dm.mall.moduls.service.MallCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 商城用户(TMallCustomer)表服务实现类
*
......@@ -40,4 +42,6 @@ public class MallCustomerServiceImpl implements MallCustomerService {
public MallCustomer selectByPhone(String username) {
return tMallCustomerDao.selectByPhone(username);
}
}
\ No newline at end of file
......@@ -13,7 +13,9 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.security.auth.Subject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;
@RestController
......@@ -32,15 +34,18 @@ public class LoginController extends BaseController {
* @param password 密码
* @return
*/
@GetMapping(value = "login")
public Result login(String username, String password) {
@PostMapping(value = "login")
public Result login(String username, String password, HttpServletRequest request) {
// 手机
String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证
if (username.matches(username)) {
SysUser sysUser = sysUserService.selectByPhone(username);
if (sysUser != null) {
if (sysUser.getTelephone().equals(username) && sysUser.getPassword().equals(password)){
session.setAttribute("account", sysUser.getAccount());
session.setAttribute("password", sysUser.getPassword());
return new Result<>(true, "登录成功!", StatusCode.OK);
}
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
......@@ -49,6 +54,8 @@ public class LoginController extends BaseController {
SysUser sysUser = sysUserService.selectByUsername(username);
if (sysUser != null) {
if (sysUser.getAccount().equals(username) && sysUser.getPassword().equals(password)){
session.setAttribute("account", sysUser.getAccount());
session.setAttribute("password", sysUser.getPassword());
return new Result<>(true, "登录成功!", StatusCode.OK);
}
}
......
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