securityinfoproxy.java

来自「计算机技术的快速发展」· Java 代码 · 共 100 行

JAVA
100
字号
package com.suninformation.user;

import java.sql.*;
import com.suninformation.database.DBManager;

public class SecurityInfoProxy {
	private static final String DELETE_SECURITYINFO = "DELETE FROM psecurityinfo WHERE username=?";

	/**
	 * createSecurityInfo
	 * 
	 * @param userName
	 *            String
	 * @param securityEmail
	 *            String
	 * @param securityCode
	 *            String
	 * @param question
	 *            String
	 * @param answer
	 *            String
	 * @return securityInfo
	 * @throws UserAlreadyExistsException
	 * @throws UnacceptableException
	 */
	public SecurityInfo createSecurityInfo(String userName,
			String securityEmail, String securityCode, String question,
			String answer) throws UserAlreadyExistsException,
			UnacceptableException {
		return new SecurityInfo(userName, securityEmail, securityCode,
				question, answer);
	}

	/**
	 * getSecurityInfo
	 * 
	 * @param userName
	 *            String
	 * @return securityInfo
	 * @throws UserNotFoundException
	 * @throws UnacceptableException
	 */
	public SecurityInfo getSecurityInfo(String userName)
			throws UserNotFoundException, UnacceptableException {
		return new SecurityInfo(userName);
	}

	/**
	 * 删除用户安全信息
	 * 
	 * @param userName
	 *            String
	 * @throws UserNotFoundException
	 * @throws UnacceptableException
	 */
	public void deleteUserInfo(String userName) throws UserNotFoundException,
			UnacceptableException {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			getSecurityInfo(userName);
			try {
				conn = DBManager.getConnection();
				pstmt = conn.prepareStatement(DELETE_SECURITYINFO);
				pstmt.setString(1, userName);
				pstmt.execute();
			} catch (Exception e) {
				throw new UnacceptableException("删除用户安全信息数据失败!", e);
			} finally {
				DBManager.closeObject(conn, pstmt, rs);
			}
		} catch (UserNotFoundException unfe) {
			throw new UserNotFoundException("用户安全信息不存在。", unfe);
		}
	}

	/**
	 * sendMailForPWD
	 * 
	 * @param userName
	 *            String
	 * @param securityEmail
	 *            String
	 * @throws UserNotFoundException
	 * @throws UnacceptableException
	 */
	public void sendMailForPWD(String userName, String securityEmail)
			throws UserNotFoundException, UnacceptableException {
		SecurityInfo si = getSecurityInfo(userName);
		if (securityEmail.equals(si.getSecurityEmail())) {
			/** @todo 进行email的发送操作 */
			si.setSendMailTime(new java.sql.Date(System.currentTimeMillis()));
		} else {
			throw new UnacceptableException("安全邮件地址输入不符。");
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?