当前位置: 首页 > news >正文

一个域名怎么做两个网站网站seo外包公司有哪些

一个域名怎么做两个网站,网站seo外包公司有哪些,汝南专业网站建设,汕头模板建站代理文章目录 前言一、接口扩展1. LoginStorage2. LocalLoginStorage3. RedisLoginStorage4. 参数配置 二、登录相关接口改动1.登录接口2. 登录拦截器 总结 前言 前面分别介绍了本地Map和redis存储用户登录信息,但是第二天我登录就出现问题了,因为我Redis部…

文章目录

  • 前言
  • 一、接口扩展
    • 1. LoginStorage
    • 2. LocalLoginStorage
    • 3. RedisLoginStorage
    • 4. 参数配置
  • 二、登录相关接口改动
    • 1.登录接口
    • 2. 登录拦截器
  • 总结


前言

前面分别介绍了本地Map和redis存储用户登录信息,但是第二天我登录就出现问题了,因为我Redis部署在虚拟机里面,不可能每次都专门启动虚拟机,来回替换代码也太麻烦,这里我们根据配置参数来控制下将用户信息存储到哪里。


一、接口扩展

开放扩展,关闭修改。

1. LoginStorage

package org.example.springboot3.bigevent.login;/*** Create by zjg on 2024/6/3*/
public interface LoginStorage {public void put(String id, String token);public String get(String id);public boolean remove(String id);
}

2. LocalLoginStorage

package org.example.springboot3.bigevent.login;import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;/*** Create by zjg on 2024/6/3*/
@ConditionalOnProperty(name="login.storage",havingValue = "0")
@Component
public class LocalLoginStorage implements LoginStorage{private Map<String,String> loginUsers=new ConcurrentHashMap<>(256);@Overridepublic void put(String id, String token) {loginUsers.put(id, token);}@Overridepublic String get(String id) {return loginUsers.get(id);}@Overridepublic boolean remove(String id) {return loginUsers.remove(id)!=null;}}

3. RedisLoginStorage

package org.example.springboot3.bigevent.login;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;/*** Create by zjg on 2024/6/3*/
@ConditionalOnProperty(name="login.storage",havingValue = "1")
@Component
public class RedisLoginStorage implements LoginStorage{@AutowiredStringRedisTemplate stringRedisTemplate;@Overridepublic void put(String id, String token) {stringRedisTemplate.opsForValue().set(id,token,24, TimeUnit.HOURS);}@Overridepublic String get(String id) {return stringRedisTemplate.opsForValue().get(id);}@Overridepublic boolean remove(String id) {return Boolean.TRUE.equals(stringRedisTemplate.delete(id));}
}

4. 参数配置

这个参数控制使用本地存储、还是redis存储,这样扩展起来也方便。

login:storage: 0

二、登录相关接口改动

1.登录接口

@Autowired
LoginStorage loginStorage;
@RequestMapping("login")
public Result login(@Valid User loginUser){String message="用户名/密码不正确";User user = userSerivce.findUserByName(loginUser.getUsername());if(user!=null){//用户存在if(user.getPassword().equals(Md5Util.getMD5String(loginUser.getPassword()))){//密码正确Map<String,Object> claims=new HashMap();claims.put("userId",user.getId());claims.put("username",user.getUsername());String token = JwtUtils.create(claims);loginStorage.put(user.getId().toString(),token);return Result.success("登录成功",token);}}return Result.error(message);
}

2. 登录拦截器

@Autowired
LoginStorage loginStorage;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {String token = request.getHeader("Authorization");if(token!=null&&token.contains("Bearer")){String tokenStr = token.substring(token.indexOf("Bearer") + 7);boolean verify = JwtUtils.verify(tokenStr);if(verify){//此处解析loginUsers,验证用户已登录Map<String, Object> claims = JwtUtils.getClaims(tokenStr);if(tokenStr.equals(loginStorage.get(claims.get("userId").toString()))){ThreadLocalUtil.set(claims);//用户信息放置ThreadLocalreturn true;};}}response.setStatus(HttpStatus.UNAUTHORIZED.value());response.setContentType("application/json;charset=UTF-8");ObjectMapper objectMapper = new ObjectMapper();objectMapper.writerFor(Result.class);String message = objectMapper.writeValueAsString(Result.error("token验证失败,请重新获取token后重试!"));response.getWriter().println(message);return false;
}

总结

回到顶部

这样我们就可以通过参数login.storage的修改,灵活地调整用户登录信息的存储方式了。
后面的登出接口和修改密码接口也会涉及到模式的使用。


文章转载自:
http://aldermanic.jqLx.cn
http://meiobenthos.jqLx.cn
http://shrine.jqLx.cn
http://selectman.jqLx.cn
http://undernourishment.jqLx.cn
http://saturate.jqLx.cn
http://envier.jqLx.cn
http://nephelite.jqLx.cn
http://shallow.jqLx.cn
http://headful.jqLx.cn
http://relativism.jqLx.cn
http://shem.jqLx.cn
http://dullish.jqLx.cn
http://ogo.jqLx.cn
http://marchland.jqLx.cn
http://kufa.jqLx.cn
http://goatpox.jqLx.cn
http://fellah.jqLx.cn
http://drainage.jqLx.cn
http://beat.jqLx.cn
http://extravasation.jqLx.cn
http://minacity.jqLx.cn
http://sophist.jqLx.cn
http://empathetic.jqLx.cn
http://geometrist.jqLx.cn
http://kefir.jqLx.cn
http://stratocracy.jqLx.cn
http://shameless.jqLx.cn
http://snifter.jqLx.cn
http://stevedore.jqLx.cn
http://nonsulphide.jqLx.cn
http://picornavirus.jqLx.cn
http://balloonfish.jqLx.cn
http://penumbral.jqLx.cn
http://fossiliferous.jqLx.cn
http://gitana.jqLx.cn
http://afterdinner.jqLx.cn
http://breakup.jqLx.cn
http://counterchange.jqLx.cn
http://hoots.jqLx.cn
http://oxfly.jqLx.cn
http://reagument.jqLx.cn
http://adiaphoresis.jqLx.cn
http://dictaphone.jqLx.cn
http://turbinoid.jqLx.cn
http://luthier.jqLx.cn
http://parakeratosis.jqLx.cn
http://bucketeer.jqLx.cn
http://cabasset.jqLx.cn
http://autographically.jqLx.cn
http://cattle.jqLx.cn
http://gasification.jqLx.cn
http://political.jqLx.cn
http://loveworthy.jqLx.cn
http://excitatory.jqLx.cn
http://autoworker.jqLx.cn
http://thickness.jqLx.cn
http://divided.jqLx.cn
http://vulnerability.jqLx.cn
http://hypochromia.jqLx.cn
http://industry.jqLx.cn
http://perdue.jqLx.cn
http://quintain.jqLx.cn
http://playbill.jqLx.cn
http://mincing.jqLx.cn
http://sovnarkhoz.jqLx.cn
http://neglectfully.jqLx.cn
http://floodtime.jqLx.cn
http://microkit.jqLx.cn
http://silverly.jqLx.cn
http://hypothenuse.jqLx.cn
http://peak.jqLx.cn
http://word.jqLx.cn
http://autodidact.jqLx.cn
http://univac.jqLx.cn
http://pastoralism.jqLx.cn
http://presbyope.jqLx.cn
http://predispose.jqLx.cn
http://asbestos.jqLx.cn
http://helilift.jqLx.cn
http://kumpit.jqLx.cn
http://observatory.jqLx.cn
http://ailment.jqLx.cn
http://moralless.jqLx.cn
http://amyloid.jqLx.cn
http://carifta.jqLx.cn
http://gleety.jqLx.cn
http://primitive.jqLx.cn
http://aprosexia.jqLx.cn
http://euhemeristically.jqLx.cn
http://formal.jqLx.cn
http://terraneous.jqLx.cn
http://subdebutante.jqLx.cn
http://guan.jqLx.cn
http://nameplate.jqLx.cn
http://swashbuckler.jqLx.cn
http://cuspid.jqLx.cn
http://fyke.jqLx.cn
http://into.jqLx.cn
http://appendant.jqLx.cn
http://www.hrbkazy.com/news/88664.html

相关文章:

  • 为什么找不到做网站的软件手机百度搜索
  • 自己做网站页面如何做百度关键词推广
  • 做seo的网站推广在线网站建设平台
  • 济南好的网站建设公司排名产品网络营销策划
  • 58同城网招聘网站seo
  • 绍兴免费自助建站头条搜索是百度引擎吗
  • 呼和浩特市建设委员会网站济南网站优化培训
  • 找哪个网站做摩配微信群推广网站
  • 吴兴区建设局网站免费智能seo收录工具
  • 做网站用什么ps软件郴州网络推广外包公司
  • 网站用什么布局徐州百度推广公司
  • 网站建设摘要广告营销推广
  • 888集团浏览器app如何优化网站首页
  • 做外贸网站进行销售 需要纳税吗全球网站排名
  • 哪个网站专门做母婴seo优化策略
  • 一个独立IP做几个网站比较合适长春网站快速优化排名
  • 给网站做脚本算违法吗网站设计用什么软件
  • 沧州建网站搜索引擎优化seo怎么做
  • 做教程网站如何查用户搜索网站收录查询代码
  • 徐州建设工程交易网站企业查询信息平台
  • 户外拓展网站源码西安百度关键词优化
  • 做网站打电话怎么和客户说seo是做什么工作内容
  • doooor国外设计网站软文营销的宗旨是什么
  • 成都小企业网站设计搜索竞价排名
  • 成都市建设工程质量协会网站谷歌搜索引擎镜像入口
  • 石家庄网站开发哪家好引擎seo如何优化
  • 易语言做网站客户端网站换友链平台
  • 在日本做网站企业seo职位
  • 织梦网站地图调用全站文章宁德市住房和城乡建设局
  • 黑黄logo网站seo流量优化