-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9223e46
commit 1051f20
Showing
22 changed files
with
794 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package redcomet.knowledge.bat; | ||
|
||
/** | ||
* メールの送信処理は、時間がかかるため、バッチ処理の中で処理する | ||
* | ||
* @author Koda | ||
* | ||
*/ | ||
public class MailSendBat { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
89
src/main/java/redcomet/knowledge/control/admin/ConfigControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
115
src/main/java/redcomet/knowledge/control/admin/MailControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.