Search in sources :

Example 1 with Member

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;
}
Also used : TbMemberExample(cn.exrick.manager.pojo.TbMemberExample) TbMember(cn.exrick.manager.pojo.TbMember) Gson(com.google.gson.Gson) TbMember(cn.exrick.manager.pojo.TbMember) Member(cn.exrick.manager.dto.front.Member)

Example 2 with 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;
}
Also used : TbMember(cn.exrick.manager.pojo.TbMember) Gson(com.google.gson.Gson) XmallException(cn.exrick.common.exception.XmallException) TbMember(cn.exrick.manager.pojo.TbMember) Member(cn.exrick.manager.dto.front.Member)

Example 3 with Member

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;
}
Also used : Member(cn.exrick.manager.dto.front.Member)

Example 4 with 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);
}
Also used : HashMap(java.util.HashMap) GeetestLib(cn.exrick.common.utils.GeetestLib) Member(cn.exrick.manager.dto.front.Member) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with 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;
}
Also used : Gson(com.google.gson.Gson) TbMember(cn.exrick.manager.pojo.TbMember) Member(cn.exrick.manager.dto.front.Member)

Aggregations

Member (cn.exrick.manager.dto.front.Member)5 TbMember (cn.exrick.manager.pojo.TbMember)3 Gson (com.google.gson.Gson)3 XmallException (cn.exrick.common.exception.XmallException)1 GeetestLib (cn.exrick.common.utils.GeetestLib)1 TbMemberExample (cn.exrick.manager.pojo.TbMemberExample)1 ApiOperation (io.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1