Compare commits

...

9 Commits

@ -0,0 +1,22 @@
package com.controller.admin;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import com.po.Auser;
import com.service.admin.AdminService;
@Controller
public class AdminController {
@Autowired
private AdminService adminService;
@RequestMapping("/admin")
public String toLogin(@ModelAttribute Auser auser) {
return "admin/login";
}
@RequestMapping("admin/login")
public String login(@ModelAttribute Auser auser, Model model, HttpSession session) {
return adminService.login(auser, model, session);
}
}

@ -0,0 +1,36 @@
package com.controller.admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.service.admin.AdminEmailAndUserService;
@Controller
@RequestMapping("/admin")
public class AdminEmailAndUserController extends BaseController{
@Autowired
private AdminEmailAndUserService adminEmailAndUserService;
@RequestMapping("/selectEmail")
public String selectAllEmail(Model model) {
return adminEmailAndUserService.selectAllEmail(model);
}
@RequestMapping("/delete")
public String delete(Integer id) {
return adminEmailAndUserService.delete(id);
}
@RequestMapping("/selectUser")
public String selectUser(Model model) {
return adminEmailAndUserService.selectBuserEmail(model);
}
@RequestMapping("/lock")
public String lock(Integer id) {
return adminEmailAndUserService.lock(id);
}
@RequestMapping("/unLock")
public String unLock(Integer id) {
return adminEmailAndUserService.unLock(id);
}
}

@ -0,0 +1,22 @@
package com.controller.before;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.exception.UserLoginNoException;
@Controller
public class BaseBeforeController {
/**
* 前台用户登录权限控制,处理方法执行前执行该方法
* @throws UserLoginNoException
*/
@ModelAttribute
public void isLogin(HttpSession session, HttpServletRequest request) throws UserLoginNoException {
if(session.getAttribute("emailuser") == null){
throw new UserLoginNoException("没有登录");
}
}
}

@ -0,0 +1,21 @@
package com.controller.admin;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.exception.AdminLoginNoException;
@Controller
public class BaseController {
/**
* 登录权限控制,处理方法执行前执行该方法
* @throws AdminLoginNoException
*/
@ModelAttribute
public void isLogin(HttpSession session, HttpServletRequest request) throws AdminLoginNoException {
if(session.getAttribute("auser") == null){
throw new AdminLoginNoException("没有登录");
}
}
}

@ -0,0 +1,106 @@
package com.controller.before;
import java.io.FileInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.po.Email;
import com.service.before.EmailService;
import com.util.MyUtil;
@Controller
@RequestMapping("/email")
public class EmailController extends BaseBeforeController{
@Autowired
private EmailService emailService;
/**
* 写信
*/
@RequestMapping("/write")
public String write(Email myemail, Model model, HttpServletRequest request, HttpSession session) {
return emailService.write(myemail,model,request,session);
}
/**
* 回复初始化
*/
@RequestMapping("/reEmailInit")
public String reEmailInit(Integer id, Model model, HttpSession session) {
return emailService.reEmailInit(id, model);
}
/**
* 收信
*/
@RequestMapping("/recieve")
public String recieve(Model model, HttpSession session) {
return emailService.recieve(model, session);
}
/**
* 已发送
*/
@RequestMapping("/send")
public String send(Model model, HttpSession session) {
return emailService.send(model, session);
}
/**
* 打开信件看详情
*/
@RequestMapping("/detail")
public String detail(Model model, Integer id) {//id接收参数id
return emailService.detail(model, id);
}
/**
* 删除一个邮件
*/
@RequestMapping("/deleteOne")
public String deleteOne(Integer id) {//id接收参数id
return emailService.deleteOne(id);
}
/***
* 删除多个邮件
*/
@RequestMapping("/deleteMore")
public String deleteMore(Integer ids[]) {//id接收参数id
return emailService.deleteMore(ids);
}
/**
* 下载附件,该方法不访问数据库,故只写控制层
*/
@RequestMapping("/down")
public String down(String fileid, HttpServletRequest request, HttpServletResponse response) {//fileid接收参数fileid
String aFilePath = null; //要下载的文件路径
FileInputStream in = null; //输入流
ServletOutputStream out = null; //输出流
try {
//从workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps下载
aFilePath = request.getServletContext().getRealPath("uploadfiles");
//设置下载文件使用的报头
response.setHeader("Content-Type", "application/x-msdownload" );
response.setHeader("Content-Disposition", "attachment; filename="
+ MyUtil.toUTF8String(fileid));
// 读入文件
in = new FileInputStream(aFilePath + "\\"+ fileid);
//得到响应对象的输出流,用于向客户端输出二进制数据
out = response.getOutputStream();
out.flush();
int aRead = 0;
byte b[] = new byte[1024];
while ((aRead = in.read(b)) != -1 & in != null) {
out.write(b,0,aRead);
}
out.flush();
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,40 @@
package com.controller.before;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.po.Buser;
import com.service.before.NavigateService;
@Controller
public class NavigateController extends BaseBeforeController{
@Autowired
private NavigateService navigateService;
/**
* 转到写信页面
*/
@RequestMapping("/toWrite")
public String toWrite(Model model) {
return navigateService.toWrite(model);
}
/***
* 安全退出不需访问数据库这里不需要service层和dao层
*/
@RequestMapping("/exit")
public String exit(HttpSession session, Model model) {
session.invalidate();
model.addAttribute("buser", new Buser());
return "before/login";
}
/***
* 去修改密码页面不需访问数据库这里不需要service层和dao层
*/
@RequestMapping("/toUpdate")
public String toUpdate(HttpSession session, Model model) {
model.addAttribute("buser", (Buser)session.getAttribute("emailuser"));
return "before/update";
}
}

@ -0,0 +1,49 @@
package com.controller.before;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import com.po.Buser;
import com.service.before.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/register")
public String register(@ModelAttribute Buser buser,Model model, HttpSession session, String code) {
return userService.register(buser, model, session, code);
}
@RequestMapping("/login")
public String login(@ModelAttribute Buser buser,Model model, HttpSession session, String code) {
return userService.login(buser, model, session, code);
}
/**
* 转到登录页面
*/
@RequestMapping("/toLogin")
public String toLogin(Model model) {
return userService.toLogin(model);
}
/**
* 转到注册页面
*/
@RequestMapping("/toRegister")
public String toRegister(Model model) {
return userService.toRegister(model);
}
/**
* 修改密码
*/
@RequestMapping("/update")
public String update(Model model, HttpSession session, String bpwd) {
return userService.update(model, session, bpwd);
}
}

@ -0,0 +1,95 @@
package com.controller.before;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 验证码
*/
@Controller
public class ValidateCodeController {
private char code[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2',
'3', '4', '5', '6', '7', '8', '9' };
private static final int WIDTH = 50;
private static final int HEIGHT = 20;
private static final int LENGTH = 4;
@RequestMapping("/validateCode")
public void validateCode(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// 设置响应报头信息
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// 设置响应的MIME类型
response.setContentType("image/jpeg");
BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_INT_RGB);
Font mFont = new Font("Arial", Font.TRUETYPE_FONT, 18);
Graphics g = image.getGraphics();
Random rd = new Random();
// 设置背景颜色
g.setColor(new Color(rd.nextInt(55) + 200, rd.nextInt(55) + 200, rd
.nextInt(55) + 200));
g.fillRect(0, 0, WIDTH, HEIGHT);
// 设置字体
g.setFont(mFont);
// 画边框
g.setColor(Color.black);
g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
// 随机产生的验证码
String result = "";
for (int i = 0; i < LENGTH; ++i) {
result += code[rd.nextInt(code.length)];
}
HttpSession se = request.getSession();
se.setAttribute("code", result);
// 画验证码
for (int i = 0; i < result.length(); i++) {
g.setColor(new Color(rd.nextInt(200), rd.nextInt(200), rd
.nextInt(200)));
g.drawString(result.charAt(i) + "", 12 * i + 1, 16);
}
// 随机产生2个干扰线
for (int i = 0; i < 2; i++) {
g.setColor(new Color(rd.nextInt(200), rd.nextInt(200), rd
.nextInt(200)));
int x1 = rd.nextInt(WIDTH);
int x2 = rd.nextInt(WIDTH);
int y1 = rd.nextInt(HEIGHT);
int y2 = rd.nextInt(HEIGHT);
g.drawLine(x1, y1, x2, y2);
}
// 释放图形资源
g.dispose();
try {
OutputStream os = response.getOutputStream();
// 输出图像到页面
ImageIO.write(image, "JPEG", os);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save