Search in sources :

Example 1 with Member

use of com.whoiszxl.entity.Member in project shopzz by whoiszxl.

the class MemberServiceImpl method passwordRegister.

@Override
public boolean passwordRegister(String username, String password) {
    long memberId = idWorker.nextId();
    Member member = new Member();
    member.setId(memberId);
    member.setUsername(username);
    member.setPhone(username);
    member.setPassword(passwordEncoder.encode(password));
    this.save(member);
    MemberInfo memberInfo = new MemberInfo();
    memberInfo.setMemberId(memberId);
    memberInfoService.save(memberInfo);
    return true;
}
Also used : MemberInfo(com.whoiszxl.entity.MemberInfo) Member(com.whoiszxl.entity.Member)

Example 2 with Member

use of com.whoiszxl.entity.Member in project shopzz by whoiszxl.

the class MemberController method updateMemberInfo.

@SaCheckLogin
@PutMapping
@Transactional
@ApiOperation(value = "更新当前登录用户的详细信息", notes = "更新当前登录用户的详细信息", response = Boolean.class)
public ResponseResult<Boolean> updateMemberInfo(@RequestBody MemberDetailVO memberDetailVO) {
    long memberId = StpUtil.getLoginIdAsLong();
    // 1. 更新用户信息
    MemberVO memberVO = memberDetailVO.getMember();
    Member member = dozerUtils.map(memberVO, Member.class);
    member.setId(memberId);
    memberService.updateById(member);
    // 2. 更新用户详细信息
    MemberInfoVO memberInfoVO = memberDetailVO.getMemberInfo();
    MemberInfo memberInfo = dozerUtils.map(memberInfoVO, MemberInfo.class);
    memberInfo.setMemberId(memberId);
    memberInfoService.updateByMemberId(memberInfo);
    return ResponseResult.buildSuccess();
}
Also used : MemberInfo(com.whoiszxl.entity.MemberInfo) Member(com.whoiszxl.entity.Member) SaCheckLogin(cn.dev33.satoken.annotation.SaCheckLogin) ApiOperation(io.swagger.annotations.ApiOperation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Member

use of com.whoiszxl.entity.Member in project shopzz by whoiszxl.

the class MemberController method passwordRegister.

@Transactional
@PostMapping("/password/register")
@ApiOperation(value = "账号密码注册", notes = "账号密码注册", response = ResponseResult.class)
public ResponseResult<Boolean> passwordRegister(@RequestBody PasswordRegisterQuery registerQuery) {
    // 1. 校验参数
    if (RegexUtils.checkMobile(registerQuery.getUsername())) {
        return ResponseResult.buildError("手机号不正确");
    }
    // 2. 校验密码是否一致
    if (!StringUtils.equals(registerQuery.getPassword(), registerQuery.getRePassword())) {
        return ResponseResult.buildError("两次输入密码不一致");
    }
    // 3. 校验密码
    if (CheckPasswordUtils.getPasswordLevel(registerQuery.getPassword()).equals(CheckPasswordUtils.LEVEL.EASY)) {
        return ResponseResult.buildError("密码太简单了");
    }
    // 4. 判断是否在数据库中已存在
    QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("phone", registerQuery.getUsername());
    Member member = memberService.getOne(queryWrapper);
    if (member != null) {
        return ResponseResult.buildError("用户已存在");
    }
    // 5. 新增用户
    boolean registerFlag = memberService.passwordRegister(registerQuery.getUsername(), registerQuery.getPassword());
    return ResponseResult.buildByFlag(registerFlag);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Member(com.whoiszxl.entity.Member) ApiOperation(io.swagger.annotations.ApiOperation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Member

use of com.whoiszxl.entity.Member in project shopzz by whoiszxl.

the class MemberController method login.

@Transactional
@PostMapping("/login")
@ApiOperation(value = "账号密码登录", notes = "账号密码登录", response = ResponseResult.class)
public ResponseResult<String> login(@RequestBody LoginQuery loginQuery) {
    // 1. 从数据库查询用户名和密码是否匹配
    Member member = memberService.getOne(new QueryWrapper<Member>().eq("username", loginQuery.getUsername()));
    if (member == null || !passwordEncoder.matches(loginQuery.getPassword(), member.getPassword())) {
        return ResponseResult.buildError("账号或密码错误");
    }
    // 2. 登录并获取token
    StpUtil.login(member.getId());
    // 3. 更新最后登录时间
    MemberInfo memberInfo = new MemberInfo();
    memberInfo.setMemberId(member.getId());
    memberInfo.setLastLogin(new Date());
    memberInfoService.updateByMemberId(memberInfo);
    return ResponseResult.buildSuccess("登录成功", StpUtil.getTokenValue());
}
Also used : MemberInfo(com.whoiszxl.entity.MemberInfo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Member(com.whoiszxl.entity.Member) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Member

use of com.whoiszxl.entity.Member in project shopzz by whoiszxl.

the class MemberServiceImpl method memberInfo.

@Override
public MemberDetailVO memberInfo() {
    // 1. 获取到当前登录用户的ID
    long memberId = StpUtil.getLoginIdAsLong();
    // 2. 分别从会员、会员信息表中查询出
    Member member = this.getById(memberId);
    MemberVO memberVO = dozerUtils.map(member, MemberVO.class);
    MemberInfo memberInfo = memberInfoService.getByMemberId(memberId);
    MemberInfoVO memberInfoVO = dozerUtils.map(memberInfo, MemberInfoVO.class);
    MemberDetailVO memberDetailVO = new MemberDetailVO();
    memberDetailVO.setMemberInfo(memberInfoVO);
    memberDetailVO.setMember(memberVO);
    return memberDetailVO;
}
Also used : MemberInfo(com.whoiszxl.entity.MemberInfo) MemberVO(com.whoiszxl.entity.vo.MemberVO) MemberInfoVO(com.whoiszxl.entity.vo.MemberInfoVO) Member(com.whoiszxl.entity.Member) MemberDetailVO(com.whoiszxl.entity.vo.MemberDetailVO)

Aggregations

Member (com.whoiszxl.entity.Member)5 MemberInfo (com.whoiszxl.entity.MemberInfo)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Transactional (org.springframework.transaction.annotation.Transactional)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 SaCheckLogin (cn.dev33.satoken.annotation.SaCheckLogin)1 MemberDetailVO (com.whoiszxl.entity.vo.MemberDetailVO)1 MemberInfoVO (com.whoiszxl.entity.vo.MemberInfoVO)1 MemberVO (com.whoiszxl.entity.vo.MemberVO)1 Date (java.util.Date)1