Commit 1b07e7d8 by XiaHou

权星登录注册

parent 580f861b
......@@ -8,12 +8,10 @@ import com.macro.mall.domain.dto.member.UmsMemberTagParam;
import com.macro.mall.domain.vo.UmsMemberVo;
import com.macro.mall.domain.vo.member.UmsMemberTagVo;
import com.macro.mall.model.UmsMember;
import com.macro.mall.model.common.ResultMsg;
import com.macro.mall.service.member.UmsMemberService;
import com.macro.mall.service.member.UmsMemberTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
......@@ -105,4 +103,25 @@ public class UmsMemberController {
memberTagService.updateMemberTags(param);
return CommonResult.success("更改成功");
}
@ApiOperation("后台插入会员")
@RequestMapping(value = "/insertMember", method = RequestMethod.POST)
@ResponseBody
public CommonResult insertMember(@ApiParam("手机号") @RequestParam("phone") String phone,@ApiParam("用户名") @RequestParam("username") String username,
@ApiParam("名字") @RequestParam("name") String name,@ApiParam("账户类型(0管理员1供应商2分销商)") @RequestParam("accouuntType") Integer accouuntType
,@ApiParam("密码") @RequestParam("password") String password){
UmsMember umsMember = new UmsMember();
umsMember.setPhone(phone);
umsMember.setUsername(username);
umsMember.setName(name);
umsMember.setAccouuntType(accouuntType);
umsMember.setPassword(password);
ResultMsg res = this.memberService.insertMember(umsMember);
if(res.isFlag()){
return CommonResult.success(null,res.getMsg());
}
return CommonResult.failed(res.getMsg());
}
}
......@@ -54,7 +54,7 @@ public class ProductAttributeGroupServiceImpl implements ProductAttributeGroupSe
PmsProductAttributeType type = pmsProductAttributeTypeMapper.selectByPrimaryKey(pmsProductAttributeGroupParam.getPmsProductAttributeGroup().getProductAttributeTypeId());
type.setParamCount(type.getParamCount()+typeNames.size());
type.setUpdateDate(new Date());
pmsProductAttributeTypeMapper.insertSelective(type);
pmsProductAttributeTypeMapper.updateByPrimaryKeySelective(type);
return 1;
}
......
......@@ -124,6 +124,9 @@ public class UmsMember implements Serializable {
@ApiModelProperty(value = "分销层级")
private Integer distributionLevel;
@ApiModelProperty(value = "账户类型(0管理员1供应商2分销商)")
private Integer accouuntType;
@ApiModelProperty(value = "最后登录时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date loginTime;
......@@ -426,6 +429,14 @@ public class UmsMember implements Serializable {
this.distributionLevel = distributionLevel;
}
public Integer getAccouuntType() {
return accouuntType;
}
public void setAccouuntType(Integer accouuntType) {
this.accouuntType = accouuntType;
}
public Date getLoginTime() {
return loginTime;
}
......@@ -477,6 +488,7 @@ public class UmsMember implements Serializable {
sb.append(", unionId=").append(unionId);
sb.append(", label=").append(label);
sb.append(", distributionLevel=").append(distributionLevel);
sb.append(", accouuntType=").append(accouuntType);
sb.append(", loginTime=").append(loginTime);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
......
......@@ -2532,6 +2532,66 @@ public class UmsMemberExample {
return (Criteria) this;
}
public Criteria andAccouuntTypeIsNull() {
addCriterion("accouunt_type is null");
return (Criteria) this;
}
public Criteria andAccouuntTypeIsNotNull() {
addCriterion("accouunt_type is not null");
return (Criteria) this;
}
public Criteria andAccouuntTypeEqualTo(Integer value) {
addCriterion("accouunt_type =", value, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeNotEqualTo(Integer value) {
addCriterion("accouunt_type <>", value, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeGreaterThan(Integer value) {
addCriterion("accouunt_type >", value, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeGreaterThanOrEqualTo(Integer value) {
addCriterion("accouunt_type >=", value, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeLessThan(Integer value) {
addCriterion("accouunt_type <", value, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeLessThanOrEqualTo(Integer value) {
addCriterion("accouunt_type <=", value, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeIn(List<Integer> values) {
addCriterion("accouunt_type in", values, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeNotIn(List<Integer> values) {
addCriterion("accouunt_type not in", values, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeBetween(Integer value1, Integer value2) {
addCriterion("accouunt_type between", value1, value2, "accouuntType");
return (Criteria) this;
}
public Criteria andAccouuntTypeNotBetween(Integer value1, Integer value2) {
addCriterion("accouunt_type not between", value1, value2, "accouuntType");
return (Criteria) this;
}
public Criteria andLoginTimeIsNull() {
addCriterion("login_time is null");
return (Criteria) this;
......
package com.macro.mall.model.common;
import java.io.Serializable;
public class ResultMsg implements Serializable{
/**
* 增删改查等提示消息类
*/
private static final long serialVersionUID = 1L;
private boolean flag;
private String code;
private String msg;
private Object context;
public ResultMsg(boolean flag, String code, String msg, Object context){
super();
this.flag = flag;
this.code = code;
this.msg = msg;
this.context = context;
}
public ResultMsg(boolean flag, String msg, Object context) {
super();
this.flag = flag;
this.msg = msg;
this.context = context;
}
public ResultMsg(boolean flag, String code, String msg) {
super();
this.flag = flag;
this.code = code;
this.msg = msg;
}
public ResultMsg(boolean flag, Object context) {
super();
this.flag = flag;
this.context = context;
}
public ResultMsg(boolean flag, String msg) {
super();
this.flag = flag;
this.msg = msg;
}
public ResultMsg(String code, String msg) {
super();
this.code = code;
this.msg = msg;
}
public ResultMsg(String msg) {
super();
this.msg = msg;
}
public ResultMsg() {
// TODO Auto-generated constructor stub
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getContext() {
return context;
}
public void setContext(Object context) {
this.context = context;
}
}
......@@ -39,6 +39,7 @@
<result column="union_id" jdbcType="VARCHAR" property="unionId" />
<result column="label" jdbcType="VARCHAR" property="label" />
<result column="distribution_level" jdbcType="INTEGER" property="distributionLevel" />
<result column="accouunt_type" jdbcType="INTEGER" property="accouuntType" />
<result column="login_time" jdbcType="TIMESTAMP" property="loginTime" />
</resultMap>
<sql id="Example_Where_Clause">
......@@ -105,7 +106,7 @@
create_by, update_date, update_by, delete_status, name, create_time, luckey_count,
history_integration, email, identity_number, identity_photo_a, identity_photo_b,
identity_review_opinion, identity_review_status, identity_review_time, invitation_code,
invitation_code_id, union_id, label, distribution_level, login_time
invitation_code_id, union_id, label, distribution_level, accouunt_type, login_time
</sql>
<select id="selectByExample" parameterType="com.macro.mall.model.UmsMemberExample" resultMap="BaseResultMap">
select
......@@ -153,8 +154,8 @@
identity_photo_b, identity_review_opinion,
identity_review_status, identity_review_time,
invitation_code, invitation_code_id, union_id,
label, distribution_level, login_time
)
label, distribution_level, accouunt_type,
login_time)
values (#{memberLevelId,jdbcType=BIGINT}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{nickname,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{icon,jdbcType=VARCHAR}, #{gender,jdbcType=INTEGER}, #{birthday,jdbcType=DATE},
......@@ -167,8 +168,8 @@
#{identityPhotoB,jdbcType=VARCHAR}, #{identityReviewOpinion,jdbcType=VARCHAR},
#{identityReviewStatus,jdbcType=VARCHAR}, #{identityReviewTime,jdbcType=TIMESTAMP},
#{invitationCode,jdbcType=VARCHAR}, #{invitationCodeId,jdbcType=BIGINT}, #{unionId,jdbcType=VARCHAR},
#{label,jdbcType=VARCHAR}, #{distributionLevel,jdbcType=INTEGER}, #{loginTime,jdbcType=TIMESTAMP}
)
#{label,jdbcType=VARCHAR}, #{distributionLevel,jdbcType=INTEGER}, #{accouuntType,jdbcType=INTEGER},
#{loginTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.macro.mall.model.UmsMember">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
......@@ -284,6 +285,9 @@
<if test="distributionLevel != null">
distribution_level,
</if>
<if test="accouuntType != null">
accouunt_type,
</if>
<if test="loginTime != null">
login_time,
</if>
......@@ -397,6 +401,9 @@
<if test="distributionLevel != null">
#{distributionLevel,jdbcType=INTEGER},
</if>
<if test="accouuntType != null">
#{accouuntType,jdbcType=INTEGER},
</if>
<if test="loginTime != null">
#{loginTime,jdbcType=TIMESTAMP},
</if>
......@@ -522,6 +529,9 @@
<if test="record.distributionLevel != null">
distribution_level = #{record.distributionLevel,jdbcType=INTEGER},
</if>
<if test="record.accouuntType != null">
accouunt_type = #{record.accouuntType,jdbcType=INTEGER},
</if>
<if test="record.loginTime != null">
login_time = #{record.loginTime,jdbcType=TIMESTAMP},
</if>
......@@ -569,6 +579,7 @@
union_id = #{record.unionId,jdbcType=VARCHAR},
label = #{record.label,jdbcType=VARCHAR},
distribution_level = #{record.distributionLevel,jdbcType=INTEGER},
accouunt_type = #{record.accouuntType,jdbcType=INTEGER},
login_time = #{record.loginTime,jdbcType=TIMESTAMP}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
......@@ -685,6 +696,9 @@
<if test="distributionLevel != null">
distribution_level = #{distributionLevel,jdbcType=INTEGER},
</if>
<if test="accouuntType != null">
accouunt_type = #{accouuntType,jdbcType=INTEGER},
</if>
<if test="loginTime != null">
login_time = #{loginTime,jdbcType=TIMESTAMP},
</if>
......@@ -729,6 +743,7 @@
union_id = #{unionId,jdbcType=VARCHAR},
label = #{label,jdbcType=VARCHAR},
distribution_level = #{distributionLevel,jdbcType=INTEGER},
accouunt_type = #{accouuntType,jdbcType=INTEGER},
login_time = #{loginTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
......
......@@ -56,12 +56,12 @@ public class UmsMemberController {
return memberService.register(username, password, telephone, authCode , code ,unionid);
}
@ApiOperation("会员登录")
@ApiOperation("会员根据手机号登录")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestParam String username,
public CommonResult login(@RequestParam String phone,
@RequestParam String password) {
return memberService.login(username, password);
return memberService.login(phone, password);
}
// @ApiOperation("获取验证码")
......
......@@ -27,6 +27,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired(required = false)
private DynamicSecurityService dynamicSecurityService;
private static String[] WHITE_LIST = {"/pmsSupplierAudit/auditSupplier"};//添加注册接口为白名单
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity
......@@ -40,6 +42,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 任何请求需要身份认证
registry.and()
.authorizeRequests()
//加载白名单列表,放行
.antMatchers(WHITE_LIST).permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest()
.authenticated()
// 关闭跨站请求防护及不使用session
......
......@@ -7,6 +7,7 @@ import com.macro.mall.domain.dto.UmsMemberReview;
import com.macro.mall.domain.vo.UmsMemberVo;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.model.UmsMember;
import com.macro.mall.model.common.ResultMsg;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.transaction.annotation.Transactional;
......@@ -28,6 +29,14 @@ public interface UmsMemberService {
UmsMember getById(Long id);
/**
* 根据手机号 查询一个会员用户
* @param phone
* @return
*/
UmsMember getByPhone(String phone);
/**
* 根据会员编号获取会员
*/
UmsMemberVo getUmsMemberVoById(Long id);
......@@ -69,9 +78,16 @@ public interface UmsMemberService {
UserDetails loadUserByUsername(String username);
/**
* 获取用户信息 根据手机号
* @param phone
* @return
*/
UserDetails loadUserByPhone(String phone);
/**
* 登录后获取token
*/
CommonResult login(String username, String password);
CommonResult login(String phone, String password);
/**
* 刷新token
......@@ -151,4 +167,10 @@ public interface UmsMemberService {
List<Long> getMemberIdList(UmsMemberParam umsMemberParam);
Integer setAccount(Long memberId,Integer flag);
/**
* 后台新增一个会员
* @return
*/
ResultMsg insertMember(UmsMember umsMember);
}
......@@ -14,10 +14,12 @@ import com.macro.mall.mapper.UmsMemberLevelMapper;
import com.macro.mall.mapper.UmsMemberMapper;
import com.macro.mall.model.*;
import com.macro.mall.domain.UmsMemberVerified;
import com.macro.mall.model.common.ResultMsg;
import com.macro.mall.service.member.UmsMemberAccountService;
import com.macro.mall.service.member.UmsMemberService;
import com.macro.mall.security.util.CodingUtil;
import com.macro.mall.security.util.JwtTokenUtil;
import com.macro.mall.service.quanxing.IPmsSupplierAuditService;
import com.macro.mall.service.system.RedisService;
import com.macro.mall.service.system.UmsAdminService;
import org.slf4j.Logger;
......@@ -66,10 +68,12 @@ public class UmsMemberServiceImpl implements UmsMemberService {
private UmsMemberAccountService memberAccountService;
@Resource
private UmsMemberDao memberDao;
@Autowired
@Resource
private UmsMemberMapper umsMemberMapper;
@Resource
private OmsOrderSonMapper orderSonMapper;
@Autowired
private IPmsSupplierAuditService pmsSupplierAuditService;
@Value("${redis.key.prefix.authCode}")
private String REDIS_KEY_PREFIX_AUTH_CODE;
......@@ -92,6 +96,17 @@ public class UmsMemberServiceImpl implements UmsMemberService {
}
@Override
public UmsMember getByPhone(String phone){
UmsMemberExample example = new UmsMemberExample();
example.createCriteria().andPhoneEqualTo(phone);
List<UmsMember> memberList = umsMemberMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(memberList)) {
return memberList.get(0);
}
return null;
}
@Override
public UmsMember getById(Long id) {
return umsMemberMapper.selectByPrimaryKey(id);
}
......@@ -276,17 +291,26 @@ public class UmsMemberServiceImpl implements UmsMemberService {
}
@Override
public CommonResult login(String username, String password) {
public UserDetails loadUserByPhone(String phone){
UmsMember member = this.getByPhone(phone);
if (member != null) {
return new MemberDetails(member);
}
throw new UsernameNotFoundException("手机号不存在或密码错误");
}
@Override
public CommonResult login(String phone, String password) {
String token = null;
//密码需要客户端加密后传递
try {
UmsMember member = getByUsername(username);
UmsMember member = getByPhone(phone);
if (member == null) {
return CommonResult.failed("用户未注册");
return CommonResult.failed("手机号不存在");
}
UserDetails userDetails = loadUserByUsername(username);
UserDetails userDetails = loadUserByPhone(phone);
if (!passwordEncoder.matches(password, userDetails.getPassword())) {
return CommonResult.failed("用户名或密码错误,请重新登录");
return CommonResult.failed("手机号不存在或密码错误,请重新登录");
}
Integer status = member.getStatus();
if (status.equals(0)) {
......@@ -646,4 +670,58 @@ public class UmsMemberServiceImpl implements UmsMemberService {
return count;
}
/**
* 插入会员
* @param umsMember
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public ResultMsg insertMember(UmsMember umsMember){
ResultMsg res = this.checkInsertMember(umsMember);
if(!res.isFlag()){
return new ResultMsg(false,res.getMsg());
}
//加密密码
umsMember.setPassword( passwordEncoder.encode(umsMember.getPassword()));
//插入到会员表
this.umsMemberMapper.insertSelective(umsMember);
return new ResultMsg(true,"操作成功");
}
/**
* 校验插入会员
* @return
*/
private ResultMsg checkInsertMember(UmsMember umsMember){
if(umsMember == null){
return new ResultMsg(false,"传入会员为空");
}
if(umsMember.getUsername() == null || "".equals(umsMember.getUsername())){
//如果没传入会员账号 默认设置
umsMember.setUsername(this.pmsSupplierAuditService.getUsername());
}
if(umsMember.getPhone() == null || "".equals(umsMember.getPhone())){
return new ResultMsg(false,"手机号为空");
}
if(umsMember.getPassword() == null || "".equals(umsMember.getPassword())){
return new ResultMsg(false,"密码为空");
}
if(umsMember.getBirthday() == null ){
umsMember.setBirthday(new Date());
}
if(umsMember.getCreateDate() == null){
umsMember.setCreateDate(new Date());
}
if(umsMember.getUpdateDate() == null){
umsMember.setUpdateDate(new Date());
}
if(umsMember.getCreateTime() == null){
umsMember.setCreateTime(new Date());
}
if(umsMember.getStatus() == null){
umsMember.setStatus(1);//帐号启用状态:0->禁用;1->启用
}
return new ResultMsg(true,"校验通过");
}
}
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