Commit a5de1461 authored by ysongq's avatar ysongq

no message

parent 85e41fe9
...@@ -74,5 +74,17 @@ ...@@ -74,5 +74,17 @@
<version>RELEASE</version> <version>RELEASE</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.39</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
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; ...@@ -2,15 +2,21 @@ package com.jz.dm.mall.moduls.controller.customer;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode; 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.entity.MallCustomer;
import com.jz.dm.mall.moduls.service.MallCustomerService; import com.jz.dm.mall.moduls.service.MallCustomerService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; 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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/** /**
* @ClassName: * @ClassName:
* @Author: Carl * @Author: Carl
...@@ -35,15 +41,18 @@ public class LoginController { ...@@ -35,15 +41,18 @@ public class LoginController {
* @param password 密码 * @param password 密码
* @return * @return
*/ */
@GetMapping(value = "/login") @PostMapping(value = "/login")
public Result<MallCustomer> login(String username, String password) { public Result<MallCustomer> login(String username, String password, HttpServletRequest request) {
// 手机 // 手机
String ph = "^[1][34578]\\d{9}$"; String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证 // 如果是手机验证
if (username.matches(username)) { if (username.matches(username)) {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(username); MallCustomer mallCustomer = mallCustomerService.selectByPhone(username);
if (mallCustomer != null) { if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(username) && mallCustomer.getPassword().equals(password)){ 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<>(true, "登录成功!", StatusCode.OK);
} }
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR); return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
...@@ -52,9 +61,13 @@ public class LoginController { ...@@ -52,9 +61,13 @@ public class LoginController {
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username); MallCustomer mallCustomer = mallCustomerService.selectByAccount(username);
if (mallCustomer != null) { if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username) && mallCustomer.getPassword().equals(password)){ 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<>(true, "登录成功!", StatusCode.OK);
} }
} }
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR); return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
} }
} }
...@@ -32,20 +32,14 @@ public class MallCustomerController extends BaseController { ...@@ -32,20 +32,14 @@ public class MallCustomerController extends BaseController {
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@PostMapping(value = "/saveCustomer")
public Result saveCustomer(Map<String, String> paramMap) {
return null;
}
/** /**
* 手机号码校验 * 手机号码校验
* @param paramMap * @param paramMap
* @param res
* @return * @return
*/ */
@PostMapping(value = "/check") @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 telephone = paramMap.get("telephone");
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone; String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
......
...@@ -3,6 +3,8 @@ package com.jz.dm.mall.moduls.mapper; ...@@ -3,6 +3,8 @@ 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;
import java.util.Map;
/** /**
* 商城用户(TMallCustomer)表数据库访问层 * 商城用户(TMallCustomer)表数据库访问层
* *
...@@ -10,8 +12,18 @@ import com.jz.dm.mall.moduls.entity.MallCustomer; ...@@ -10,8 +12,18 @@ import com.jz.dm.mall.moduls.entity.MallCustomer;
* @since 2020-12-01 10:41:39 * @since 2020-12-01 10:41:39
*/ */
public interface MallCustomerDao extends BaseMapper<MallCustomer> { public interface MallCustomerDao extends BaseMapper<MallCustomer> {
/**
* 根据账号查询用户信息
* @param username
* @return
*/
MallCustomer selectByAccount(String username); MallCustomer selectByAccount(String username);
/**
* 根据手机号查询用户信息
* @param username
* @return
*/
MallCustomer selectByPhone(String username); MallCustomer selectByPhone(String username);
} }
\ No newline at end of file
...@@ -2,6 +2,8 @@ package com.jz.dm.mall.moduls.service; ...@@ -2,6 +2,8 @@ package com.jz.dm.mall.moduls.service;
import com.jz.dm.mall.moduls.entity.MallCustomer; import com.jz.dm.mall.moduls.entity.MallCustomer;
import java.util.Map;
/** /**
* 商城用户(TMallCustomer)表服务接口 * 商城用户(TMallCustomer)表服务接口
* *
...@@ -24,4 +26,5 @@ public interface MallCustomerService { ...@@ -24,4 +26,5 @@ public interface MallCustomerService {
*/ */
MallCustomer selectByPhone(String username); MallCustomer selectByPhone(String username);
} }
\ No newline at end of file
...@@ -7,6 +7,8 @@ import com.jz.dm.mall.moduls.service.MallCustomerService; ...@@ -7,6 +7,8 @@ import com.jz.dm.mall.moduls.service.MallCustomerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map;
/** /**
* 商城用户(TMallCustomer)表服务实现类 * 商城用户(TMallCustomer)表服务实现类
* *
...@@ -40,4 +42,6 @@ public class MallCustomerServiceImpl implements MallCustomerService { ...@@ -40,4 +42,6 @@ public class MallCustomerServiceImpl implements MallCustomerService {
public MallCustomer selectByPhone(String username) { public MallCustomer selectByPhone(String username) {
return tMallCustomerDao.selectByPhone(username); return tMallCustomerDao.selectByPhone(username);
} }
} }
\ No newline at end of file
...@@ -13,7 +13,9 @@ import org.springframework.util.StringUtils; ...@@ -13,7 +13,9 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.security.auth.Subject; import javax.security.auth.Subject;
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;
@RestController @RestController
...@@ -32,15 +34,18 @@ public class LoginController extends BaseController { ...@@ -32,15 +34,18 @@ public class LoginController extends BaseController {
* @param password 密码 * @param password 密码
* @return * @return
*/ */
@GetMapping(value = "login") @PostMapping(value = "login")
public Result login(String username, String password) { public Result login(String username, String password, HttpServletRequest request) {
// 手机 // 手机
String ph = "^[1][34578]\\d{9}$"; String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证 // 如果是手机验证
if (username.matches(username)) { if (username.matches(username)) {
SysUser sysUser = sysUserService.selectByPhone(username); SysUser sysUser = sysUserService.selectByPhone(username);
if (sysUser != null) { if (sysUser != null) {
if (sysUser.getTelephone().equals(username) && sysUser.getPassword().equals(password)){ 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<>(true, "登录成功!", StatusCode.OK);
} }
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR); return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
...@@ -49,6 +54,8 @@ public class LoginController extends BaseController { ...@@ -49,6 +54,8 @@ public class LoginController extends BaseController {
SysUser sysUser = sysUserService.selectByUsername(username); SysUser sysUser = sysUserService.selectByUsername(username);
if (sysUser != null) { if (sysUser != null) {
if (sysUser.getAccount().equals(username) && sysUser.getPassword().equals(password)){ 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); 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