|
|
@@ -1,57 +0,0 @@
|
|
|
-package com.mokamrp.privates.service.impl;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.mokamrp.privates.constant.RedisKey;
|
|
|
-import com.mokamrp.privates.mapper.UserMapper;
|
|
|
-import com.mokamrp.privates.mapper.pojo.Corp;
|
|
|
-import com.mokamrp.privates.mapper.pojo.User;
|
|
|
-import com.mokamrp.privates.service.LoginService;
|
|
|
-import com.mokamrp.privates.service.UserService;
|
|
|
-import com.mokamrp.privates.utils.StringUtils;
|
|
|
-import com.mokamrp.privates.utils.sign.Md5Utils;
|
|
|
-import com.mokamrp.privates.constant.Constants;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 企微小平台临时登录 服务实现类
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author leon
|
|
|
- * @since 2021-04-17
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class LoginServiceImpl extends ServiceImpl<UserMapper, User> implements LoginService {
|
|
|
- @Autowired
|
|
|
- public StringRedisTemplate redis;
|
|
|
-
|
|
|
- public Map<String, Object> doLogin(String phone, String password) {
|
|
|
- Map<String, Object> res =this.getMap(new QueryWrapper<User>().eq("phone", phone));
|
|
|
- //.验证账户名和密码
|
|
|
- if (res.isEmpty()) {
|
|
|
- res.put("loginStatus", "phoneNull");
|
|
|
- return res;
|
|
|
- }
|
|
|
- Object nowPass = res.get("password");
|
|
|
- if (!nowPass.toString().equals(password)) {
|
|
|
- res.put("loginStatus", "passwordErr");
|
|
|
- return res;
|
|
|
- }
|
|
|
- //.登录信息缓存到redis,过期时间5小时
|
|
|
- String userMd5 = Md5Utils.hash(phone);
|
|
|
- String token = userMd5 + "_" + StringUtils.getRandomString(10);
|
|
|
- res.remove("password");
|
|
|
- String userInfoStr = JSON.toJSONString(res);
|
|
|
- redis.opsForValue().set(RedisKey.AuthToken + token, userInfoStr);
|
|
|
- redis.expire(RedisKey.AuthToken + token, Constants.TOKEN_EXPIRATION, TimeUnit.SECONDS);
|
|
|
- res.put("token", token);
|
|
|
- res.put("loginStatus", "loginSuccess");
|
|
|
- return res;
|
|
|
- }
|
|
|
-}
|