完成用户登录
This commit is contained in:
parent
589d37fd75
commit
6b2ef02919
|
|
@ -84,6 +84,12 @@
|
||||||
<artifactId>easyexcel</artifactId>
|
<artifactId>easyexcel</artifactId>
|
||||||
<version>2.2.6</version>
|
<version>2.2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
<version>0.7.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,20 @@
|
||||||
package com.ruoyi.business.ajax;
|
package com.ruoyi.business.ajax;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.business.domain.BizMember;
|
||||||
import com.ruoyi.business.service.IBizMemberService;
|
import com.ruoyi.business.service.IBizMemberService;
|
||||||
|
import com.ruoyi.business.utils.Encrypt;
|
||||||
|
import com.ruoyi.business.utils.JWTUtil;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前端用户登录
|
* 前端用户登录
|
||||||
|
|
@ -22,7 +28,32 @@ public class AjaxLoginController extends BaseController {
|
||||||
private IBizMemberService bizMemberService;
|
private IBizMemberService bizMemberService;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public AjaxResult login(@Param("loginName") String loginName, @Param("password") String password) {
|
public AjaxResult login(String mobile, String password) {
|
||||||
return super.success();
|
if (StringUtils.isBlank(mobile) || StringUtils.isBlank(password)) {
|
||||||
|
return AjaxResult.warn("请输入用户名密码");
|
||||||
|
}
|
||||||
|
|
||||||
|
BizMember member = bizMemberService.selectBizMemberByMobile(mobile);
|
||||||
|
if (Objects.isNull(member)) {
|
||||||
|
return AjaxResult.warn("用户名或密码错误");
|
||||||
|
}
|
||||||
|
// DES加密
|
||||||
|
String encryptPassword = Encrypt.encrypt(password);
|
||||||
|
if (!encryptPassword.equals(member.getPassword())) {
|
||||||
|
return AjaxResult.warn("用户名或密码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member.getIsEnable() == 0) {
|
||||||
|
return AjaxResult.warn("账户已禁用,请联系系统管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
object.put("id", member.getId());
|
||||||
|
object.put("name", member.getMemberName());
|
||||||
|
object.put("mobile", member.getMobile());
|
||||||
|
|
||||||
|
Long day = 1000L * 60L * 60L;
|
||||||
|
String token = JWTUtil.createJWT(object.toJSONString(), day);
|
||||||
|
return super.success(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,14 @@ public interface BizMemberMapper
|
||||||
*/
|
*/
|
||||||
public BizMember selectBizMemberSimple(Long id);
|
public BizMember selectBizMemberSimple(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员
|
||||||
|
*
|
||||||
|
* @param mobile 手机号
|
||||||
|
* @return 会员
|
||||||
|
*/
|
||||||
|
public BizMember selectBizMemberByMobile(String mobile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询会员列表
|
* 查询会员列表
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,13 @@ public interface IBizMemberService
|
||||||
*/
|
*/
|
||||||
public BizMember selectBizMemberSimple(Long id);
|
public BizMember selectBizMemberSimple(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员
|
||||||
|
* @param mobile 手机号
|
||||||
|
* @return 会员
|
||||||
|
*/
|
||||||
|
public BizMember selectBizMemberByMobile(String mobile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询会员列表
|
* 查询会员列表
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ import com.ruoyi.business.domain.BizMember;
|
||||||
import com.ruoyi.business.service.IBizMemberService;
|
import com.ruoyi.business.service.IBizMemberService;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员Service业务层处理
|
* 会员Service业务层处理
|
||||||
*
|
*
|
||||||
|
|
@ -26,10 +28,10 @@ import com.ruoyi.common.core.text.Convert;
|
||||||
@Service
|
@Service
|
||||||
public class BizMemberServiceImpl implements IBizMemberService
|
public class BizMemberServiceImpl implements IBizMemberService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Resource
|
||||||
private BizMemberMapper bizMemberMapper;
|
private BizMemberMapper bizMemberMapper;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private BizAccountMapper bizAccountMapper;
|
private BizAccountMapper bizAccountMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,6 +58,11 @@ public class BizMemberServiceImpl implements IBizMemberService
|
||||||
return bizMemberMapper.selectBizMemberSimple(id);
|
return bizMemberMapper.selectBizMemberSimple(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BizMember selectBizMemberByMobile(String mobile) {
|
||||||
|
return bizMemberMapper.selectBizMemberByMobile(mobile);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询会员列表
|
* 查询会员列表
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public class UserDataListener extends AnalysisEventListener<UserData> {
|
||||||
member.setIsEnable("Y".equals(userData.getEnable()) ? 1 : 0);
|
member.setIsEnable("Y".equals(userData.getEnable()) ? 1 : 0);
|
||||||
member.setCreateTime(DateUtils.parseDate(userData.getAddtim()));
|
member.setCreateTime(DateUtils.parseDate(userData.getAddtim()));
|
||||||
member.setUpdateTime(DateUtils.parseDate(userData.getAddtim()));
|
member.setUpdateTime(DateUtils.parseDate(userData.getAddtim()));
|
||||||
member.setMobile(userData.getReferrerTelephone());
|
member.setMobile(userData.getUserTelephone());
|
||||||
member.setRecommendMobile(userData.getReferrerTelephone());
|
member.setRecommendMobile(userData.getReferrerTelephone());
|
||||||
member.setRecommendName(userData.getReferrer());
|
member.setRecommendName(userData.getReferrer());
|
||||||
member.setId(Long.valueOf(userData.getId()));
|
member.setId(Long.valueOf(userData.getId()));
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public class Encrypt {
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
//System.out.println(encrypt("x123456"));
|
//System.out.println(encrypt("x123456"));
|
||||||
//System.out.println(decrypt("248E135E28C103B4"));
|
System.out.println(decrypt("83A0D00DA5194E0E88CDC5FCADED588F"));
|
||||||
|
|
||||||
//System.out.println(DictUtils.getDictLabel("busi_recommend_award", "1"));
|
//System.out.println(DictUtils.getDictLabel("busi_recommend_award", "1"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.ruoyi.business.utils;
|
||||||
|
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.JwtBuilder;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
import io.jsonwebtoken.impl.crypto.MacProvider;
|
||||||
|
|
||||||
|
import java.security.Key;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jwt-token 加、解密工具类 Created by wubei on 16/12/11.
|
||||||
|
*/
|
||||||
|
public class JWTUtil {
|
||||||
|
static final Key KEY = MacProvider.generateKey();
|
||||||
|
|
||||||
|
public static final String AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
|
public static String createJWT(String subject) {
|
||||||
|
return JWTUtil.createJWT(subject, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createJWT(String subject, Long ttlMillis) {
|
||||||
|
long nowMillis = System.currentTimeMillis();
|
||||||
|
Date now = new Date(nowMillis);
|
||||||
|
|
||||||
|
JwtBuilder builder =
|
||||||
|
Jwts.builder().setIssuedAt(now).setSubject(subject).signWith(SignatureAlgorithm.HS256, AUTHORIZATION);
|
||||||
|
if (ttlMillis != null) {
|
||||||
|
long expMillis = nowMillis + ttlMillis;
|
||||||
|
Date exp = new Date(expMillis);
|
||||||
|
builder.setExpiration(exp);
|
||||||
|
}
|
||||||
|
return builder.compact();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Claims parseJWT(String compactJws) {
|
||||||
|
Jwts.parser().isSigned(compactJws);
|
||||||
|
Claims claims = Jwts.parser().setSigningKey(AUTHORIZATION).parseClaimsJws(compactJws).getBody();
|
||||||
|
return claims;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public static SysUserBean getSysUser(HttpServletRequest request, RedisTemplate redisTemplate,
|
||||||
|
boolean flag) {
|
||||||
|
String token = request.getHeader(AUTHORIZATION);
|
||||||
|
|
||||||
|
// 取值attr里面予值
|
||||||
|
if (StringUtils.isBlank(token)) {
|
||||||
|
Object tToken = request.getAttribute(AUTHORIZATION);
|
||||||
|
if (tToken != null) {
|
||||||
|
token = tToken.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(token)) {
|
||||||
|
if (flag) {
|
||||||
|
throw new AuthorizationException();
|
||||||
|
} else {
|
||||||
|
return new SysUserBean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Claims claims = parseJWT(token);
|
||||||
|
String hasKey = claims.getSubject();
|
||||||
|
if (redisTemplate.hasKey(hasKey)) {
|
||||||
|
String conpanyUserStr = (String)redisTemplate.opsForValue().get(hasKey);
|
||||||
|
SysUserBean sysUseBean = JSONObject.parseObject(conpanyUserStr, SysUserBean.class);
|
||||||
|
if (token.equals(sysUseBean.getToken())) {
|
||||||
|
return sysUseBean;
|
||||||
|
} else {
|
||||||
|
throw new AuthorizationException();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new AuthorizationException();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AuthorizationException();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
@ -54,6 +54,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
from biz_member where id = #{id}
|
from biz_member where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectBizMemberByMobile" resultMap="BizMemberResult">
|
||||||
|
select id, mobile, member_name, password, recommend_id, recommend_mobile, recommend_name, member_type, is_delete, is_enable, create_by, create_time, update_by, update_time
|
||||||
|
from biz_member where mobile = #{mobile}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertBizMember" parameterType="BizMember" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertBizMember" parameterType="BizMember" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into biz_member
|
insert into biz_member
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
|
@ -126,4 +131,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
select count(id) from biz_member a where recommend_id = #{memberID}
|
select count(id) from biz_member a where recommend_id = #{memberID}
|
||||||
and exists(select id from biz_order b where b.member_id = a.id and is_team = 1)
|
and exists(select id from biz_order b where b.member_id = a.id and is_team = 1)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue