项目集成2(系统首页与用户模块操作)

  • 用户登录
    动态生成秘钥:
@Service //将类交给Spring容器
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;


    @Override
    public String findUP(User u) {
        byte[] bytes = u.getPassword().getBytes();
        String md5pwd = DigestUtils.md5DigestAsHex(bytes);

        u.setPassword(md5pwd);
        User byUP = userMapper.findByUP(u);

        if (byUP==null){
            return null;
        }
        return UUID.randomUUID().toString().replace("-", "");
    }
}

Cookie和Session:
业务说明:用户向服务器发起请求,获取结果时请求周期是一次请求一次响应,请求结束则响应的数据清空,为了保存服务器的响应数据,应该想办法将服务器数据持久化
Session相关:
1.称为“会话控制”
2.可以存储用户信息
3.生命周期是整个会话,会话关闭则数据清空
4.数据结构为key-value
5.浏览器session存储的位置(F12—Application)
Cookie相关:
1.是一个小型文本文件,存储在本地终端上
2.可以存储用户信息
3.数据结构是key-value
4.数据一般采用加密的方式保存
5.数据可以永久保存
Cookie和Session选择(特点):
1.数据需要临时保存,则选择Session,长时间存储则选择Cookie
2.对安全性要求高,则选择Session,要求不高则选择Cookie
用户登录实现数据存储:
用户登录成功后,将秘钥保存到Session中,后期需要校验Session,如果token中有值,则代表用户登录过,没有值则说明用户没有登录过,跳转到登录页面

  • 登录后页面跳转
    编辑路由(router/index.js):
import Home from '../components/Home.vue'
{path: '/home',component: Home, children:[
      {path: '/user', component: User},
      {path: '/itemCat', component: ItemCat},
      {path: '/item', component: Item},
      {path: '/item/addItem', component: AddItem}
    ],
  }
  • Vue的路由导航守卫
    访问BUG:
    用户可以直接根据网址访问其他页面,如果想控制该漏洞,则需要在前端进行权限的校验
    规则:如果用户访问没有token信息,则表示用户没有登录,则需要跳转到登录页面
    解决方式:拦截器(老东西),新的可使用路由导航守卫,本质也是一个拦截器
    定义路由导航守卫:
    参数1. to 路由跳转的网址
    参数2. from 路由从哪里来
    参数3. next 是一个函数,表示放行或重定向,next() 放行,next("/login") 重定向
    核心逻辑: 检查是否有token. 如果访问login页面 直接放行.没有token 表示用户没有登录,重定向到登录页面
router.beforeEach((to,from,next) => {
   if(to.path === "/login"){
     return next()
   }
    //说明用户访问的页面不是login 请求需要校验
    //获取token数据.
    let token = window.sessionStorage.getItem("token")
    //if(token !==null && token.length>0)
    //下列if 解释为: 如果token不为null
    if(token){
      return next()
    }

    next("/login")
})
  • 左侧菜单业务实现
    权限层级代码结构:

SQL语句:

SELECT p.id,p.name,p.parent_id,p.level,p.created,p.updated,
       c.id c_id,c.name c_name,c.parent_id c_parent_id,c.path c_path,c.level c_level,c.created c_created,c.updated c_updated FROM 
(SELECT * FROM rights WHERE parent_id=0) p
    LEFT JOIN rights c
     ON p.id=c.parent_id

重难点(配置文件):

   <select id="getRightsList" resultMap="rightRM">
        SELECT p.id,p.name,p.parent_id,p.level,p.created,p.updated,
               c.id c_id,c.name c_name,c.parent_id c_parent_id,c.path c_path,c.level c_level,c.created c_created,c.updated c_updated FROM
                (SELECT * FROM rights WHERE parent_id=0) p
                    LEFT JOIN rights c
                              ON p.id=c.parent_id
    </select>
    <resultMap id="rightRM" type="Rights" autoMapping="true">
        <id property="id" column="id"></id>
<!--        封装一对多数据-->
        <collection property="children" ofType="Rights">
            <id property="id" column="c_id"></id>
            <result property="name" column="c_name"></result>
            <result property="parentId" column="c_parent_id"></result>
            <result property="path" column="c_path"></result>
            <result property="level" column="c_level"></result>
            <result property="created" column="c_created"></result>
            <result property="updated" column="c_updated"></result>
        </collection>
    </resultMap>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值