ssm+shiro+vue+elementui implements a simple authority management system

The source code has been uploaded to GitHub

Back-end part: https://github.com/Wisdom-Bao/shiro-ssm.git
Front-end part: https://github.com/Wisdom-Bao/shiro-vue.git

1. Log in and register

Insert picture description here
Key code:

 @RequestMapping("login")
 @ResponseBody
 public String login(String username,String password){
    
    
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        try {
    
    
            subject.login(token);
            return "success";
        } catch (UnknownAccountException e) {
    
       //用户名不存在
            return "no user";
        } catch (IncorrectCredentialsException e) {
    
         //密码错误
            return "wrong password";
        }

    }
 submitForm(formName) {
    
    
      this.$http
        .get(`/login?username=${
      
      formName.username}&password=${
      
      formName.pass}`)
        .then(resp => {
    
    
          if (formName.code != this.identifyCode) {
    
    
            this.$message({
    
    
              type: "info",
              message: "验证码错误"
            });
          } else if (resp.data == "success") {
    
    
            sessionStorage.setItem("token", "true");
            sessionStorage.setItem("username", formName.username);
            sessionStorage.setItem("password", formName.pass);
            _this.$router.push({
    
     path: "/" });
            this.$message({
    
    
              type: "success",
              message: "登录成功"
            });
          } else if (resp.data == "wrong password") {
    
    
            this.$message({
    
    
              type: "info",
              message: "密码错误"
            });
            _this.$router.push({
    
     path: "/login" });
          } else if (resp.data == "no user") {
    
    
            this.$message({
    
    
              type: "info",
              message: "用户名不存在"
            });
            _this.$router.push({
    
     path: "/login" });
          }
        });
    }

Insert picture description here

Insert picture description here
Key code:

 @RequestMapping("register")
 @ResponseBody
 public String register(String username, String password, String code){
    
    
        if(!code.equals(this.messageCode)){
    
    
            return "wrong code";
        }
        Object salt = ByteSource.Util.bytes(username);
        SimpleHash simpleHash = new SimpleHash("MD5", password, salt, 1);
        User user = new User();
        user.setName(username);
        user.setPassword(simpleHash.toString());
        userService.addUser(user);
        return "register success";
    }
submitForm(formName) {
    
    
      this.$http
        .get(
          `/register?username=${
      
      formName.username}&password=${
      
      formName.pass}&code=${
      
      formName.code}`
        )
        .then(resp => {
    
    
          console.log(resp);
          if (resp.data == "register success") {
    
    
            this.$message({
    
    
              type: "success",
              message: "注册成功"
            });
            _this.$router.push({
    
     path: "/" });
          }else if(resp.data == "wrong code"){
    
    
            this.$message({
    
    
              type: "info",
              message: "验证码不正确"
            });
          }
        });
    },

2. Display personal information

Insert picture description here
Key code:

    @ResponseBody
    @RequestMapping("findAllUserInfo")
    public List<UserVo> findAllUserInfo(){
    
    
        List<User> userList = userService.findAllUsers();
        List<UserVo> userVoList = new ArrayList<>();
        for(User user : userList) {
    
    
            Set roleSet = new HashSet();
            List<Role> roleList = roleService.findRoleByUserId(user.getId());
            for (Role role : roleList) {
    
    
                roleSet.add(role.getName());
            }
            UserVo userVo = new UserVo();
            userVo.setUserId(user.getId());
            userVo.setUserName(user.getName());
            userVo.setUserRoles(roleSet);
            userVoList.add(userVo);
        }
        return userVoList;
    }

The following parts are mainly crud, just connect to the database operation

Three, role management

1. Show all roles
Insert picture description here
2. Show detailed information about roles

Insert picture description here

3. Modify role information

Insert picture description here
3. Delete the role

Insert picture description here
4. Add roles

Insert picture description here

Three, authority management

Functions are similar to role management, so I won’t demonstrate them one by one

Insert picture description here

Four, user management

1. Show users

Insert picture description here

2. Modify user roles

Insert picture description here

Five, insufficient user authority

If the user does not have the corresponding permission, he cannot access the corresponding content
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_44042316/article/details/106528251