源码获取:俺的博客首页 "资源" 里下载!

项目介绍

本项目为基于SSM的邮件收发管理系统;

用户角色包含以下功能:
用户登录,写信给好友,查看收件箱,查看已发送的邮件,草稿箱查看,通讯录设置,个人资料管理等功能。


环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;


技术栈

1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+CSS+JavaScript+jQuery


使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中config/db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/xx登录


 

 

 

 

 

管理员管理控制层:

/**
 * 管理员维护的接口
 */
@Controller
public class AdminController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IUserService userService;

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * 用户修改密码的接口,可以直接访问
     *
     * @param userName userName
     * @param password password
     */
    @RequestMapping("/alterPassword")
    @ResponseBody
    public void alterSecret(@RequestParam String userName, @RequestParam String password) {
        userService.alterPassword(userName, password);
    }

    /**
     * 根据用户名删除用户,可以直接访问
     *
     * @param userName userName
     */
    @RequestMapping("/deleteUser")
    @ResponseBody
    public void deleteUser(@RequestParam String[] userName) {
        userService.deleteByUsernames(userName);
    }

    /**
     * 用户产生验证码的接口,只有特定用户可以访问
     */
    @RequestMapping(value = "/registerCode")
    public ModelAndView registerCode(ModelAndView modelAndView, HttpServletRequest request) {
        String username = WebUtil.getUserNameByRequest(request);
        if ("sandeepin".equals(username) || "cflower".equals(username)) {
            modelAndView.setViewName("registerCode");
            return modelAndView;
        } else {
            modelAndView.setViewName("errorPage");
            modelAndView.addObject("message", "没有权限生成验证码!");
            return modelAndView;
        }
    }

    /**
     * 根据操作人的名字和要验证码人的名字来生成注册码
     *
     * @param customName
     * @param request
     * @return
     */
    @RequestMapping(value = "proRegisterCode", produces = "application/json; charset=utf-8")
    @ResponseBody
    public ResponseMsg proRegisterCode(@RequestParam String customName, HttpServletRequest request) {
        String registerCode = PassWordCreate.createPassWord(6);
        VerifyCode verifyCode = new VerifyCode();
        verifyCode.setState(false);
        verifyCode.setRegisterCode(registerCode);
        verifyCode.setOperatePerson(WebUtil.getUserNameByRequest(request));
        verifyCode.setDate(new Date());
        verifyCode.setCustomName(customName);
        boolean result = iVerifyCodeService.save(verifyCode);
        ResponseMsg responseMsg = new ResponseMsg();
        responseMsg.setSuccess(result);
        if (result) {
            responseMsg.setMsg(registerCode);
        } else {
            responseMsg.setMsg("生成注册码失败,请重新操作!");
        }
        return responseMsg;
    }
}

登录管理控制层:

/**
 * 登录
 * 管理员admin
 *
 */
@Controller
public class LoginController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IUserService userService;

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    // 登录
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> login(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<>();
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        String encryptedPwd = "";
        try {
            //加密的用户密码
            encryptedPwd = Md5SaltTool.getEncryptedPwd(password);
            logger.warn("encryptedPwd:" + encryptedPwd);
        } catch (NoSuchAlgorithmException e) {
            logger.error("Exception:", e);
        } catch (UnsupportedEncodingException e) {
            logger.error("Exception:", e);
        }
        User dataBaseUser = userService.queryUserByUsername(userName);
        if (dataBaseUser != null && encryptedPwd.equals(dataBaseUser.getPassWord())) {
            User user = new User(userName, encryptedPwd, dataBaseUser.getLevelType(), dataBaseUser.getEmail(),
                dataBaseUser.getPhone(), dataBaseUser.getAlias());
            request.getSession().setAttribute("user", user);
            logger.info("用户登录成功!");
            map.put("result", "1");
            map.put("userName", userName);
        } else if (dataBaseUser != null && !encryptedPwd.equals(dataBaseUser.getPassWord())) {
            logger.info("密码错误!");
            map.put("result", "2");
        } else {
            logger.info("用户不存在!");
            map.put("result", "0");
        }
        return map;
    }

    // 退出登录
    @RequestMapping(value = "/quit", method = RequestMethod.GET)
    public String loginOut(HttpServletRequest request) {
        if (!SystemUtil.isWindows()) {
            // 非windows环境下要删除用户文件
            FileUtil.deleteDir(fileRootPath + WebUtil.getUserNameByRequest(request));
        }

        // 清除session
        request.getSession().invalidate();
        logger.info("退出登录成功!");
        return "login";
    }

    // 注册
    @RequestMapping(value = "/signin", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> signin(@RequestParam(required = false) String alias,
        @RequestParam(required = true) String userName, @RequestParam(required = true) String password,
        @RequestParam(required = false) String regcode, @RequestParam(required = false) String email,
        @RequestParam(required = false) String phone, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<>();
        String encryptedPwd = "";
        try {
            //加密的用户密码
            encryptedPwd = Md5SaltTool.getEncryptedPwd(password);
        } catch (NoSuchAlgorithmException e) {
            logger.error("NoSuchAlgorithmException:", e);
        } catch (UnsupportedEncodingException e) {
            logger.error("UnsupportedEncodingException:", e);
        }
        User dataBaseUser = userService.queryUserByUsername(encryptedPwd);
        //regcode的重新写入
        if (!iVerifyCodeService.isValid(regcode)) {
            logger.info("注册失败,激活码失效或不正确!");
            map.put("result", "2");
            return map;
        } else {
            if (dataBaseUser == null) {
                User user = new User(userName, encryptedPwd, "0", email, phone, alias);
                userService.add(user);
                logger.info("账号注册成功!");
                map.put("result", "1");
            } else {
                logger.info("用户已经存在,请登录或换一个用户名!");
                map.put("result", "0");
            }
            return map;
        }
    }

    @RequestMapping(value = "/username", produces = "application/json; charset=utf-8")
    @ResponseBody
    public ResponseMsg fileRename(HttpServletRequest request) {
        ResponseMsg j = new ResponseMsg();
        // 获取用户名
        User user = (User) request.getSession().getAttribute("user");
        String userName = user.getUserName();
        if (userName == null) {
            userName = "null";
        }
        j.setMsg(userName);
        j.setSuccess(true);
        return j;
    }

    @RequestMapping(value = "/getUserByUserName")
    @ResponseBody
    public User getUserByUserName(HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return user;
    }

    //更新当前用户信息
    @RequestMapping(value = "/updateUserByUserName")
    @ResponseBody
    public ResponseMsg updateUserByUserName(@RequestParam(required = false) String username,
        @RequestParam(required = false) String alias, @RequestParam(required = false) String password,
        @RequestParam(required = false) String email, @RequestParam(required = false) String phone,
        HttpServletRequest request) {
        ResponseMsg j = new ResponseMsg();
        User user = (User) request.getSession().getAttribute("user");
        if (username != null) {
            user.setUserName(username);
        }
        if (alias != null) {
            user.setAlias(alias);
        }
        if (password != null) {
            try {
                String encryptedPwd = Md5SaltTool.getEncryptedPwd(password);
                user.setPassWord(encryptedPwd);
            } catch (NoSuchAlgorithmException e) {
                logger.error("NoSuchAlgorithmException:", e);
            } catch (UnsupportedEncodingException e) {
                logger.error("UnsupportedEncodingException:", e);
            }

        }
        if (email != null) {
            user.setEmail(email);
        }
        if (phone != null) {
            user.setPhone(phone);
        }
        userService.update(user);
        j.setMsg("更新用户信息成功!");
        j.setSuccess(true);
        return j;
    }

    //检查是否是登录状态
    @RequestMapping(value = "/islogin")
    @ResponseBody
    public ResponseMsg isLogin(@RequestParam(required = false) String savePath, HttpServletRequest request) {
        if (savePath == null) {
            savePath = "/";
        }
        ResponseMsg j = new ResponseMsg();
        // 获取用户名
        User user = (User) request.getSession().getAttribute("user");

        if (user == null) {
            //未登录,跳转到登录界面,登录之后默认保存到网盘连接的地址<a href="wut://pan">链接到app</a>
            j.setMsg("未登录");
            j.setSuccess(false);
        } else {
            j.setMsg("已登录");
            j.setSuccess(true);
        }
        return j;
    }
}

源码获取:俺的博客首页 "资源" 里下载!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐