Skip to content

Commit

Permalink
0.3.1 リリース
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Jan 6, 2015
1 parent 9223e46 commit 1051f20
Show file tree
Hide file tree
Showing 22 changed files with 794 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>redcomet</groupId>
<artifactId>knowledge</artifactId>
<packaging>war</packaging>
<version>0.3.0</version>
<version>0.3.1</version>
<name>webapp for knowledge</name>
<url>https://support-project.org/</url>

Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>redcomet</groupId>
<artifactId>web</artifactId>
<version>0.3.0</version>
<version>0.3.1</version>
</dependency>

<dependency>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redcomet/knowledge/bat/MailSendBat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package redcomet.knowledge.bat;

/**
* メールの送信処理は、時間がかかるため、バッチ処理の中で処理する
*
* @author Koda
*
*/
public class MailSendBat {

}
1 change: 1 addition & 0 deletions src/main/java/redcomet/knowledge/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


public class AppConfig extends redcomet.web.config.AppConfig {
public static final String SYSTEM_NAME = "knowledge";

private String indexPath;

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/redcomet/knowledge/config/SystemConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package redcomet.knowledge.config;

public class SystemConfig {
public static final String ROLE_ADMIN = "admin";
public static final String ROLE_USER = "user";

/** ユーザ登録のやりかたを判定するシステム設定のラベル */
public static final String USER_ADD_TYPE = "USER_ADD_TYPE";
/** ユーザ登録のやりかた: 管理者が登録(デフォルト) */
public static final String USER_ADD_TYPE_VALUE_ADMIN = "ADMIN";
/** ユーザ登録のやりかた: ユーザ自身で登録し、管理者が承認(メール通知あり) */
public static final String USER_ADD_TYPE_VALUE_APPROVE = "APPROVE";
/** ユーザ登録のやりかた: ユーザ自身で登録(メールアドレスのチェック無し) */
public static final String USER_ADD_TYPE_VALUE_USER = "USER";
/** ユーザ登録のやりかた: ユーザ自身で登録(メールアドレスのチェックあり) */
public static final String USER_ADD_TYPE_VALUE_MAIL = "MAIL";

/** ユーザ登録を実施した後、通知するか(ON/OFF) */
public static final String USER_ADD_NOTIFY = "USER_ADD_NOTIFY";
/** ユーザ登録を実施した後、通知する(ON) */
public static final String USER_ADD_NOTIFY_ON = "ON";
/** ユーザ登録を実施した後、通知しない(OFF) */
public static final String USER_ADD_NOTIFY_OFF = "OFF";



}
89 changes: 89 additions & 0 deletions src/main/java/redcomet/knowledge/control/admin/ConfigControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package redcomet.knowledge.control.admin;

import java.util.ArrayList;
import java.util.List;

import redcomet.common.bean.ValidateError;
import redcomet.knowledge.config.AppConfig;
import redcomet.knowledge.config.SystemConfig;
import redcomet.knowledge.control.Control;
import redcomet.web.annotation.Auth;
import redcomet.web.boundary.Boundary;
import redcomet.web.dao.MailConfigsDao;
import redcomet.web.dao.SystemConfigsDao;
import redcomet.web.entity.MailConfigsEntity;
import redcomet.web.entity.SystemConfigsEntity;

public class ConfigControl extends Control {



/**
* 一般設定画面を表示
* @return
*/
@Auth(roles="admin")
public Boundary config() {
SystemConfigsDao dao = SystemConfigsDao.get();

SystemConfigsEntity userAddType = dao.selectOnKey(SystemConfig.USER_ADD_TYPE, AppConfig.SYSTEM_NAME);
if (userAddType == null) {
userAddType = new SystemConfigsEntity(SystemConfig.USER_ADD_TYPE, AppConfig.SYSTEM_NAME);
userAddType.setConfigValue(SystemConfig.USER_ADD_TYPE_VALUE_ADMIN);
}
setAttribute("userAddType", userAddType.getConfigValue());

SystemConfigsEntity userAddNotify = dao.selectOnKey(SystemConfig.USER_ADD_NOTIFY, AppConfig.SYSTEM_NAME);
if (userAddNotify == null) {
userAddNotify = new SystemConfigsEntity(SystemConfig.USER_ADD_NOTIFY, AppConfig.SYSTEM_NAME);
userAddNotify.setConfigValue(SystemConfig.USER_ADD_NOTIFY_OFF);
}
setAttribute("userAddNotify", userAddNotify.getConfigValue());

return forward("config.jsp");
}



/**
* メールの設定を保存
* @return
*/
@Auth(roles="admin")
public Boundary save() {
List<ValidateError> errors = new ArrayList<>();
String type = getParam("userAddType");
String notify = getParam("userAddNotify");
// メール送信の場合、メールの設定が完了しているかチェック
if ((type != null && type.equals(SystemConfig.USER_ADD_TYPE_VALUE_MAIL))
|| (notify != null && notify.equals(SystemConfig.USER_ADD_NOTIFY_ON))) {
MailConfigsDao mailConfigsDao = MailConfigsDao.get();
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.SYSTEM_NAME);
if (mailConfigsEntity == null) {
ValidateError error = new ValidateError("メールを送る場合、メールの送信の設定が必須です");
errors.add(error);
}
}
if (!errors.isEmpty()) {
setResult(null, errors);
return forward("config.jsp");
}

SystemConfigsDao dao = SystemConfigsDao.get();
SystemConfigsEntity userAddType = new SystemConfigsEntity(SystemConfig.USER_ADD_TYPE, AppConfig.SYSTEM_NAME);
userAddType.setConfigValue(type);
dao.save(userAddType);

SystemConfigsEntity userAddNotify = new SystemConfigsEntity(SystemConfig.USER_ADD_NOTIFY, AppConfig.SYSTEM_NAME);
userAddNotify.setConfigValue(notify);
dao.save(userAddNotify);

String successMsg = "保存しました";
setResult(successMsg, errors);

return forward("config.jsp");
}



}
115 changes: 115 additions & 0 deletions src/main/java/redcomet/knowledge/control/admin/MailControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package redcomet.knowledge.control.admin;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import redcomet.common.bean.ValidateError;
import redcomet.common.config.INT_FLAG;
import redcomet.common.util.PasswordUtil;
import redcomet.common.util.StringUtils;
import redcomet.knowledge.config.AppConfig;
import redcomet.knowledge.control.Control;
import redcomet.web.annotation.Auth;
import redcomet.web.boundary.Boundary;
import redcomet.web.dao.MailConfigsDao;
import redcomet.web.entity.MailConfigsEntity;

public class MailControl extends Control {

/**
* メールの設定画面を表示
* @return
*/
@Auth(roles="admin")
public Boundary config() {
MailConfigsDao dao = MailConfigsDao.get();
MailConfigsEntity entity = dao.selectOnKey(AppConfig.SYSTEM_NAME);
if (entity == null) {
entity = new MailConfigsEntity();
}
entity.setSystemName(AppConfig.SYSTEM_NAME);
entity.setSmtpPassword(""); // パスワードは送らない
setAttributeOnProperty(entity);

return forward("config.jsp");
}


/**
* メールの設定を保存
* @return
* @throws BadPaddingException
* @throws IllegalBlockSizeException
* @throws NoSuchPaddingException
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
*/
@Auth(roles="admin")
public Boundary save() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
List<ValidateError> errors = new ArrayList<>();
errors.addAll(MailConfigsEntity.get().validate(getParams()));

String type = getParam("authType");
//認証がONの場合のチェック
if (type.equals(String.valueOf(INT_FLAG.ON.getValue()))) {
if (StringUtils.isEmpty(getParam("smtpId"))) {
ValidateError error = new ValidateError("認証する場合、SMTP IDは必須です");
errors.add(error);
}
if (StringUtils.isEmpty(getParam("smtpPassword"))) {
ValidateError error = new ValidateError("認証する場合、SMTP パスワードは必須です");
errors.add(error);
}
}
if (!errors.isEmpty()) {
setResult(null, errors);
return forward("config.jsp");
}

MailConfigsEntity entity = super.getParams(MailConfigsEntity.class);

// パスワードは暗号化する
String salt = PasswordUtil.getSalt();
entity.setSmtpPassword(PasswordUtil.encrypt(entity.getSmtpPassword(), salt));
entity.setSalt(salt);

MailConfigsDao dao = MailConfigsDao.get();
entity = dao.save(entity);
setAttributeOnProperty(entity);

// TODO テストでメール送信(更新したユーザのメールアドレス宛に、メールを送る)

String successMsg = "保存しました";
setResult(successMsg, errors);

return forward("config.jsp");
}



/**
* メールの設定を削除
* @return
*/
@Auth(roles="admin")
public Boundary delete() {
MailConfigsDao dao = MailConfigsDao.get();
dao.physicalDelete(AppConfig.SYSTEM_NAME); // 物理削除で消してしまう

MailConfigsEntity entity = new MailConfigsEntity();
entity.setSystemName(AppConfig.SYSTEM_NAME);
setAttributeOnProperty(entity);

addMsgInfo("メールの設定を削除しました");

return forward("config.jsp");
}


}
Loading

0 comments on commit 1051f20

Please sign in to comment.