| | |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.configurations.properties.ApplicationProperties; |
| | | import com.xcong.farmer.cms.configurations.properties.SecurityProperties; |
| | | import com.xcong.farmer.cms.modules.member.entity.MemberEntity; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminLoginDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.UserMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.ICommonService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.utils.MessageSourceUtils; |
| | | import com.xcong.farmer.cms.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | if(ObjectUtil.isEmpty(userEntity)){ |
| | | return Result.fail("请输入正确的账号和密码"); |
| | | } |
| | | Integer status = userEntity.getStatus(); |
| | | if(UserEntity.STATUS_DISABLED.equals(status)){ |
| | | return Result.fail("账号禁止登陆,请联系管理员"); |
| | | } |
| | | //生成UUID作为token |
| | | String token = IdUtil.simpleUUID(); |
| | | String redisToken = AppContants.APP_LOGIN_PREFIX + token; |
| | |
| | | return Result.ok("登录成功", authInfo); |
| | | } |
| | | |
| | | @Override |
| | | public Result memberLogout() { |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | //获取用户ID |
| | | UserEntity userEntity = userMapper.selectById(id); |
| | | if (ObjectUtil.isEmpty(userEntity)) { |
| | | return Result.fail("用户不存在"); |
| | | } |
| | | |
| | | String redisMember = AppContants.APP_LOGIN_PREFIX + userEntity.getId(); |
| | | String token = redisUtils.getString(redisMember); |
| | | redisUtils.del(AppContants.APP_LOGIN_PREFIX + token); |
| | | SecurityContextHolder.clearContext(); |
| | | return Result.ok("退出成功"); |
| | | } |
| | | |
| | | public String generateAsaToken(String token) { |
| | | RSA rsa = new RSA(null, securityProperties.getPublicKey()); |
| | | return rsa.encryptBase64(token + "_" + System.currentTimeMillis(), KeyType.PublicKey); |