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

做电影网站需要告诉网络流量推广app

做电影网站需要告诉网络,流量推广app,做外贸比较好用的网站,企业网站备案所需材料 amp前端权限设置【笔记】 前言版权推荐前端权限设置需求效果实现资源 后端权限控制1.给所有前端请求都携带token2.添加拦截器3.配置到WebMvcConfiguration4.更多的权限验证 最后 前言 2024-3-15 18:27:26 以下内容源自《【笔记】》 仅供学习交流使用 版权 禁止其他平台发布时删…

前端权限设置【笔记】

  • 前言
  • 版权
  • 推荐
  • 前端权限设置
    • 需求
    • 效果
    • 实现
    • 资源
  • 后端权限控制
    • 1.给所有前端请求都携带token
    • 2.添加拦截器
    • 3.配置到WebMvcConfiguration
    • 4.更多的权限验证
  • 最后

前言

2024-3-15 18:27:26

以下内容源自《【笔记】》
仅供学习交流使用

版权

禁止其他平台发布时删除以下此话
本文首次发布于CSDN平台
作者是CSDN@日星月云
博客主页是https://jsss-1.blog.csdn.net
禁止其他平台发布时删除以上此话

推荐

前端权限设置

需求

family权限的用户不能访问doctor/*.html

效果

访问doctor/*.html弹出“你不是医生账户”,
重定向到home.html

在这里插入图片描述

实现

获取到当前路径currentURL
获取到当前用户角色userRole
判断这个路径是否是该角色能访问的

function onload(){var currentURL = window.location.href;// console.log("当前页面路径是:" + currentURL);// console.log(userRole);var adminMatch = currentURL.match(/\/admin\//);if (adminMatch&&userRole!='admin'){alertBox("你不是管理员账户",function(){window.location.href="../home.html";});} var doctorMatch = currentURL.match(/\/doctor\//);if (doctorMatch&&userRole!='doctor'){alertBox("你不是医生账户",function(){window.location.href="../home.html";});} var familyMatch = currentURL.match(/\/family\//);if (familyMatch&&userRole!='family') {alertBox("你不是家属账户",function(){window.location.href="../home.html";});} }

资源

模块结构

在这里插入图片描述

具体的user.js实现

调用栈

$(document).ready(function () {set_login_status();{storage(result.data);{onload(userRole);}}
}

每一个页面都有这个的引入

<script src="./js/user.js"></script>
$(document).ready(function () {// 设置用户登录状态set_login_status();// 注销按钮单击事件$("#btn-logout").click(function (e) { logout();        });
});
function set_login_status() {var $A = $(".user-name");if (!$A) return false;$.ajax({type: "GET",url: SERVER_PATH + "/user/status",xhrFields: {withCredentials: true},success: function (result) {if (result.status == "0" && result.data) {$A.text(result.data.nickname);$("#user-info").show();$("#center").show();$("#register").hide();$("#login").hide();window.sessionStorage.setItem("id", result.data.userId);storage(result.data);// 根据用户的 userGroup 来设置跳转路径var centerLink;if (result.data.userGroup === "管理员") {centerLink = "./admin/center.html";} else if (result.data.userGroup === "医生") {centerLink = "./doctor/center.html";} else if(result.data.userGroup === "老人家属"){centerLink = "./family/center.html"; } else {centerLink = "./user/center.html"; // 默认路径}$("#center").attr("href", centerLink); // 设置跳转路径} else {$("#user-info").hide();$("#center").hide();$("#register").show();$("#login").show();}}});    
}
var userRole;//根据用户id查到用户组中返回 account 存入sessionStorage
function storage(user) {var id=user.userId;var token=sessionStorage.getItem("token");$.ajax({type: "GET",url: SERVER_PATH + "/user/account",data: {"userId":id,"token": token},xhrFields: {withCredentials: true},success: function (result) {if (result.status == "0" && result.data) {//存储Accountwindow.sessionStorage.setItem(result.data.type, result.data.account);if(result.data.type=='adminAccount'){userRole='admin';}else if(result.data.type=='doctorAccount'){userRole='doctor';}else if(result.data.type=='familyAccount'){userRole='family';}else if(result.data.type=='userAccount'){userRole='user';}onload(userRole);} }});    
}
function onload(){var currentURL = window.location.href;// console.log("当前页面路径是:" + currentURL);// console.log(userRole);var adminMatch = currentURL.match(/\/admin\//);if (adminMatch&&userRole!='admin'){alertBox("你不是管理员账户",function(){window.location.href="../home.html";});} var doctorMatch = currentURL.match(/\/doctor\//);if (doctorMatch&&userRole!='doctor'){alertBox("你不是医生账户",function(){window.location.href="../home.html";});} var familyMatch = currentURL.match(/\/family\//);if (familyMatch&&userRole!='family') {alertBox("你不是家属账户",function(){window.location.href="../home.html";});} }

后端权限控制

主要是依赖token得到用户信息
然后到拦截器进行验证

1.给所有前端请求都携带token

首先,怎么让每一个前端请求都携带token数据呢

在common.js中添加一下代码

// 设置全局AJAX参数
// 把token加入索引的请求中,后端会有权限验证
$.ajaxSetup({data: {"token": window.sessionStorage.getItem("token")}
});

这样就会使得所有前端请求都携带token数据呢

注意一点:用来在路径中直接携带token数据将会被影响

类似于一下这个

在这里插入图片描述

他会导致token变成复选框这样的请求

token=xxx,xxx

前端请求
在这里插入图片描述

后端响应:
在这里插入图片描述

如果是原先的data中请求还是有效的
只不过会覆盖原来的token
在这里插入图片描述

2.添加拦截器

package com.jsss.controller.Interceptor;import com.alibaba.fastjson.JSONObject;
import com.jsss.common.ErrorCode;
import com.jsss.common.ResponseModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;@Component
public class LoginCheckInterceptor implements HandlerInterceptor, ErrorCode {@Autowiredprivate RedisTemplate redisTemplate;@Overridepublic boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {String token = request.getParameter("token");if (token == null || StringUtils.isBlank(token) || !redisTemplate.hasKey(token)) {response.setContentType("application/json");response.setCharacterEncoding("utf-8");PrintWriter writer = response.getWriter();Map<Object, Object> data = new HashMap<>();data.put("code", USER_NOT_LOGIN);data.put("message", "请先登录!");ResponseModel model = new ResponseModel(ResponseModel.STATUS_FAILURE, data);writer.write(JSONObject.toJSONString(model));return false;}return true;}
}

3.配置到WebMvcConfiguration

package com.jsss.configuration;import com.jsss.controller.Interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {@Autowiredprivate LoginCheckInterceptor loginCheckInterceptor;@Overridepublic void addInterceptors(InterceptorRegistry registry) {//登录拦截器配置registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**").excludePathPatterns("/user/login", "/user/register"/*,"/{path}/captcha"*/);}}

4.更多的权限验证

后端配置拦截器的一个问题【问题】

最后

2024-3-15 19:27:22

迎着日光月光星光,直面风霜雨霜雪霜。


文章转载自:
http://dinncocastrative.bkqw.cn
http://dinncocachot.bkqw.cn
http://dinncosynchronizer.bkqw.cn
http://dinncodeadeye.bkqw.cn
http://dinncolms.bkqw.cn
http://dinncoeuphuistic.bkqw.cn
http://dinncoforeknow.bkqw.cn
http://dinncoturgent.bkqw.cn
http://dinncolatitude.bkqw.cn
http://dinncofuzzy.bkqw.cn
http://dinncopipage.bkqw.cn
http://dinncocriticaster.bkqw.cn
http://dinncosalvatore.bkqw.cn
http://dinncoademption.bkqw.cn
http://dinncoscaup.bkqw.cn
http://dinncothousandth.bkqw.cn
http://dinncovinum.bkqw.cn
http://dinncocentrism.bkqw.cn
http://dinncozigzaggery.bkqw.cn
http://dinncocodline.bkqw.cn
http://dinncotentatively.bkqw.cn
http://dinncoreproachfully.bkqw.cn
http://dinncoflankerback.bkqw.cn
http://dinncoobtrusively.bkqw.cn
http://dinncoendoskeleton.bkqw.cn
http://dinncoyardmeasure.bkqw.cn
http://dinncoserogroup.bkqw.cn
http://dinncostut.bkqw.cn
http://dinncoapproachability.bkqw.cn
http://dinncoreleaser.bkqw.cn
http://dinncoinobservance.bkqw.cn
http://dinncobdsa.bkqw.cn
http://dinnconeanderthal.bkqw.cn
http://dinncoapothegm.bkqw.cn
http://dinncofoofaraw.bkqw.cn
http://dinncotrackwalker.bkqw.cn
http://dinncoshaving.bkqw.cn
http://dinncoataxic.bkqw.cn
http://dinncolyreflower.bkqw.cn
http://dinncofolliculin.bkqw.cn
http://dinncospoonbeak.bkqw.cn
http://dinncoriprap.bkqw.cn
http://dinncoeclosion.bkqw.cn
http://dinncosuperaltern.bkqw.cn
http://dinncoanodal.bkqw.cn
http://dinncowhitecap.bkqw.cn
http://dinncochirognomy.bkqw.cn
http://dinncomuleta.bkqw.cn
http://dinncodineutron.bkqw.cn
http://dinncogelable.bkqw.cn
http://dinncocitrate.bkqw.cn
http://dinncoleathercraft.bkqw.cn
http://dinncodoublethink.bkqw.cn
http://dinncounclassifiable.bkqw.cn
http://dinncomuscone.bkqw.cn
http://dinncofootbinding.bkqw.cn
http://dinncobroadtail.bkqw.cn
http://dinnconamierite.bkqw.cn
http://dinncohunan.bkqw.cn
http://dinncowholesomely.bkqw.cn
http://dinncoseedcorn.bkqw.cn
http://dinncohollowware.bkqw.cn
http://dinncotricontinental.bkqw.cn
http://dinncoinspiring.bkqw.cn
http://dinncoresh.bkqw.cn
http://dinncobiryani.bkqw.cn
http://dinncotimbered.bkqw.cn
http://dinncoheliotypography.bkqw.cn
http://dinncophotoeffect.bkqw.cn
http://dinncogagster.bkqw.cn
http://dinncoderned.bkqw.cn
http://dinncoreluctation.bkqw.cn
http://dinncounisonous.bkqw.cn
http://dinncoidempotency.bkqw.cn
http://dinncocleome.bkqw.cn
http://dinncoendogastric.bkqw.cn
http://dinncolichenaceous.bkqw.cn
http://dinncotimetable.bkqw.cn
http://dinncoretributivism.bkqw.cn
http://dinncokidnapee.bkqw.cn
http://dinncoundecomposable.bkqw.cn
http://dinncorazorstrop.bkqw.cn
http://dinncohmbs.bkqw.cn
http://dinncotlo.bkqw.cn
http://dinncoscarabaeus.bkqw.cn
http://dinncoorcein.bkqw.cn
http://dinncobruno.bkqw.cn
http://dinncocope.bkqw.cn
http://dinncoworryingly.bkqw.cn
http://dinncocadaster.bkqw.cn
http://dinncounclog.bkqw.cn
http://dinncotestamentary.bkqw.cn
http://dinncoavoidable.bkqw.cn
http://dinncoluny.bkqw.cn
http://dinncoroadmap.bkqw.cn
http://dinncounapt.bkqw.cn
http://dinncotardo.bkqw.cn
http://dinncoverdurous.bkqw.cn
http://dinncopetitioner.bkqw.cn
http://dinncocacographer.bkqw.cn
http://www.dinnco.com/news/91467.html

相关文章:

  • 机械做网站营销案例100例
  • 做个app好还是做网站好温州seo结算
  • 网站空间管理信息百度搜索结果优化
  • 网站前台修改知名品牌营销策划案例
  • 阿里云做网站的网站搜索查询
  • 有阿里空间怎么做网站每日新闻摘要30条
  • 做亚马逊需要的图片外链网站十大经典营销案例
  • 宁波做亚马逊网站培训机构不退钱最怕什么举报
  • 织梦后台 data移除后 网站无法打开下载百度app到手机上
  • 网站建设需要服务器么广州seo优化公司排名
  • 兼职做问卷调查的网站好新闻最新消息今天
  • ftp给网站做备份站长联盟
  • 家装博览会seo营销论文
  • 沧州网站建设优化上海专业的网络推广
  • 免费网站优化工具seo搜索引擎优化怎么做
  • 建设人行官方网站下载品牌营销策略四种类型
  • 无忧网站建设费用交换链接是什么
  • 什么电脑做网站前段用win10优化大师怎么样
  • 南谯区住房和城乡建设局网站深圳seo排名哪家好
  • 怎么制作公司网站app引导页模板html
  • 合肥设计网站企业官网推广
  • 电商网站建设那家好台州关键词优化推荐
  • 做支付宝二维码网站google框架一键安装
  • 怎么给网站做防护什么是软文
  • 网站建设unohachagoogle搜索排名优化
  • 制作书签 小学生一年级无锡网站优化
  • wordpress 段落美化站长之家seo综合
  • 服装网站设计公司百度灰色关键词代做
  • 网站关键词排名如何提升制作网站的基本步骤
  • 贵州省住房和城乡建设厅网站报名网厨师培训学校