use of cn.exrick.manager.dto.front.Member in project xmall by Exrick.
the class LoginServiceImpl method userLogin.
@Override
public Member userLogin(String username, String password) {
TbMemberExample example = new TbMemberExample();
TbMemberExample.Criteria criteria = example.createCriteria();
criteria.andStateEqualTo(1);
criteria.andUsernameEqualTo(username);
List<TbMember> list = tbMemberMapper.selectByExample(example);
if (list == null || list.size() == 0) {
Member member = new Member();
member.setState(0);
member.setMessage("用户名或密码错误");
return member;
}
TbMember tbMember = list.get(0);
// md5加密
if (!DigestUtils.md5DigestAsHex(password.getBytes()).equals(tbMember.getPassword())) {
Member member = new Member();
member.setState(0);
member.setMessage("用户名或密码错误");
return member;
}
String token = UUID.randomUUID().toString();
Member member = DtoUtil.TbMemer2Member(tbMember);
member.setToken(token);
member.setState(1);
// 用户信息写入redis:key:"SESSION:token" value:"user"
jedisClient.set("SESSION:" + token, new Gson().toJson(member));
jedisClient.expire("SESSION:" + token, SESSION_EXPIRE);
return member;
}
use of cn.exrick.manager.dto.front.Member in project xmall by Exrick.
the class MemberServiceImpl method imageUpload.
@Override
public String imageUpload(Long userId, String token, String imgData) {
// 过滤data:URL
String base64 = QiniuUtil.base64Data(imgData);
String imgPath = QiniuUtil.qiniuBase64Upload(base64);
TbMember tbMember = tbMemberMapper.selectByPrimaryKey(userId);
if (tbMember == null) {
throw new XmallException("通过id获取用户失败");
}
tbMember.setFile(imgPath);
if (tbMemberMapper.updateByPrimaryKey(tbMember) != 1) {
throw new XmallException("更新用户头像失败");
}
// 更新缓存
Member member = loginService.getUserByToken(token);
member.setFile(imgPath);
jedisClient.set("SESSION:" + token, new Gson().toJson(member));
return imgPath;
}
use of cn.exrick.manager.dto.front.Member in project xmall by Exrick.
the class DtoUtil method TbMemer2Member.
public static Member TbMemer2Member(TbMember tbMemer) {
Member member = new Member();
member.setId(tbMemer.getId());
member.setUsername(tbMemer.getUsername());
member.setEmail(tbMemer.getEmail());
member.setPhone(tbMemer.getPhone());
member.setAddress(tbMemer.getAddress());
member.setBalance(tbMemer.getBalance());
member.setFile(tbMemer.getFile());
member.setPoints(tbMemer.getPoints());
member.setSex(tbMemer.getSex());
member.setDescription(tbMemer.getDescription());
return member;
}
use of cn.exrick.manager.dto.front.Member in project xmall by Exrick.
the class MemberController method login.
@RequestMapping(value = "/member/login", method = RequestMethod.POST)
@ApiOperation(value = "用户登录")
public Result<Member> login(@RequestBody MemberLoginRegist memberLoginRegist, HttpServletRequest request) {
// 极验验证
GeetestLib gtSdk = new GeetestLib(GeetestLib.id, GeetestLib.key, GeetestLib.newfailback);
String challenge = memberLoginRegist.getChallenge();
String validate = memberLoginRegist.getValidate();
String seccode = memberLoginRegist.getSeccode();
// 从session中获取gt-server状态
int gt_server_status_code = (Integer) request.getSession().getAttribute(gtSdk.gtServerStatusSessionKey);
// 自定义参数,可选择添加
HashMap<String, String> param = new HashMap<String, String>();
int gtResult = 0;
if (gt_server_status_code == 1) {
// gt-server正常,向gt-server进行二次验证
gtResult = gtSdk.enhencedValidateRequest(challenge, validate, seccode, param);
System.out.println(gtResult);
} else {
// gt-server非正常情况下,进行failback模式验证
System.out.println("failback:use your own server captcha validate");
gtResult = gtSdk.failbackValidateRequest(challenge, validate, seccode);
System.out.println(gtResult);
}
Member member = new Member();
if (gtResult == 1) {
// 验证成功
member = loginService.userLogin(memberLoginRegist.getUserName(), memberLoginRegist.getUserPwd());
} else {
// 验证失败
member.setState(0);
member.setMessage("验证失败");
}
return new ResultUtil<Member>().setData(member);
}
use of cn.exrick.manager.dto.front.Member in project xmall by Exrick.
the class LoginServiceImpl method getUserByToken.
@Override
public Member getUserByToken(String token) {
String json = jedisClient.get("SESSION:" + token);
if (json == null) {
Member member = new Member();
member.setState(0);
member.setMessage("用户登录已过期");
return member;
}
// 重置过期时间
jedisClient.expire("SESSION:" + token, SESSION_EXPIRE);
Member member = new Gson().fromJson(json, Member.class);
return member;
}
Aggregations