需求分析大作业 功能实现进度一

一、今日完成

1.增加管理员登录功能

package com.me.web;

import com.me.dao.UserDao;
import com.me.domain.AdminUser;
import com.me.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/loginServlet")
public class dengluServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String rand = (String) request.getSession().getAttribute("rand");
        String username = request.getParameter("user");
        String pwd = request.getParameter("pwd");
        String randcode = request.getParameter("randcode");
        UserDao dao = new UserDao();
        int num_user = 0,num_admin = 0;
        User user = null;
        AdminUser adminUser = null;
        if (!randcode.equals(rand)){
            response.getWriter().write("<script>alert('验证码错误!');window.location.href='"+request.getContextPath()+"/login.html'</script>");
        }

        //查找是否有账号、以及登录
        try {
            num_user= dao.ajaxUsername(username);
            num_admin = dao.ajaxAdminUser(username);
            user = dao.login(username,pwd);
            adminUser = dao.adminLogin(username,pwd);
        } catch (SQLException e) {
            e.printStackTrace();
            response.getWriter().write("<script>alert('登录失败!');window.location.href='"+request.getContextPath()+"/login.html'</script>");
        }

        if (num_user == 0){
            //查找管理员账号
            if (num_admin == 0){
                //未找到
                response.getWriter().write("<script>alert('该用户不存在,请注册!');window.location.href='"+request.getContextPath()+"/register.html'</script>");
            }else {
                if (adminUser != null){
                    //登录成功
                  request.getSession().setAttribute("user",adminUser);
                    request.getSession().setAttribute("who","admin");
                    response.getWriter().write("<script>alert('登录成功!');window.location.href='"+request.getContextPath()+"/main.html'</script>");
                }else if (adminUser == null){
                    //管理员账号或密码错误
                    response.getWriter().write("<script>alert('用户名或密码错误!');window.location.href='"+request.getContextPath()+"/register.html'</script>");
                }
            }
        }else {
            if (user != null){
                //账号密码正确
                request.getSession().setAttribute("user",user);
                request.getSession().setAttribute("who","user");
                response.getWriter().write("<script>alert('登录成功!');window.location.href='"+request.getContextPath()+"/main.html'</script>");
            }else if (user == null ){
                //账号密码错误
                response.getWriter().write("<script>alert('用户名或密码错误!');window.location.href='"+request.getContextPath()+"/register.html'</script>");
            }
        }
    }
}

2.增加需求审核界面

 

 

二、明日计划

1.完成用户管理界面以及功能

2.完成新增用户的功能

3.完成权限管理界面及部分功能

 

posted @ 2020-10-19 21:39  嘉禾旧木  阅读(94)  评论(0编辑  收藏  举报