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;
}
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();
}
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);
}
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());
}
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;
}
Aggregations