diff --git a/disconf-web/html/assets/css/project.css b/disconf-web/html/assets/css/project.css index 031d77e16..2cbf3f4b4 100644 --- a/disconf-web/html/assets/css/project.css +++ b/disconf-web/html/assets/css/project.css @@ -276,7 +276,8 @@ th { .startActivity-form-value { width: 500px; height: 30px; - border: 1px solid #D6D6D6 border-radius : 5 px; + border: 1px solid #D6D6D6; + border-radius: 5px; } .startActivity-form-value-small { @@ -352,7 +353,8 @@ th { .ticketDiscount-form-value { width: 500px; height: 30px; - border: 1px solid #D6D6D6 border-radius : 5 px; + border: 1px solid #D6D6D6; + border-radius: 5px; } .ticketDiscount-form-textarea { @@ -533,7 +535,8 @@ input.regForm-item-value { input.question-form-value { width: 380px; height: 22px; - border: 1px solid #D6D6D6 border-radius : 5 px; + border: 1px solid #D6D6D6; + border-radius: 5px; vertical-align: middle; margin-bottom: 0px; border-radius: 0 4px 4px 0; @@ -714,7 +717,8 @@ input.autoPush-detail-item-input { .register-item-value { width: 200px; height: 30px; - border: 1px solid #D6D6D6 border-radius : 5 px; + border: 1px solid #D6D6D6; + border-radius: 5px; } .register-item-value-area { @@ -986,13 +990,15 @@ q:before, q:after { .private-item-value { width: 300px; height: 30px; - border: 1px solid #D6D6D6 border-radius : 5 px; + border: 1px solid #D6D6D6; + border-radius: 5px; text-align: left; vertical-align: middle; } .private-item-value-pre { - border: 1px solid #D6D6D6 border-radius : 5 px; + border: 1px solid #D6D6D6; + border-radius: 5px; text-align: left; vertical-align: middle; } diff --git a/disconf-web/html/assets/js/modify_password.js b/disconf-web/html/assets/js/modify_password.js index 57db832a9..6cb149f7c 100644 --- a/disconf-web/html/assets/js/modify_password.js +++ b/disconf-web/html/assets/js/modify_password.js @@ -13,9 +13,16 @@ $("#item_submit").on("click", function (e) { // 验证 if (!old_password || !new_password || !new_password_2) { $("#error").removeClass("hide"); - $("#error").html("表单不能为空或填写格式错误!"); + $("#error").html("修改密码失败, 表单不能为空或填写格式错误!"); return; } + + if (new_password != new_password_2) { + $("#error").removeClass("hide"); + $("#error").html("修改密码失败, 两次输入的密码不一致!"); + return; + } + $.ajax({ type: "PUT", url: "/api/account/password", @@ -25,9 +32,9 @@ $("#item_submit").on("click", function (e) { "new_password_2": new_password_2 } }).done(function (data) { - $("#error").removeClass("hide"); if (data.success === "true") { - $("#error").html(data.result); + alert(data.result); + window.location.href = "/login.html"; } else { Util.input.whiteError($("#error"), data); } diff --git a/disconf-web/html/assets/js/register.js b/disconf-web/html/assets/js/register.js new file mode 100644 index 000000000..7505890e5 --- /dev/null +++ b/disconf-web/html/assets/js/register.js @@ -0,0 +1,31 @@ +var appId = -1; +var envId = -1; +var version = ""; + +// 提交 +$("#item_submit").on("click", function (e) { + $("#error").addClass("hide"); + var user_name = $("#reg_user_name").val(); + var pwd = $("#reg_pwd").val(); + + // 验证 + if (!user_name || !pwd) { + $("#error").html("注册失败, 表单不能为空或填写格式错误!"); + return; + } + $.ajax({ + type: "PUT", + url: "/api/account/register", + data: { + "name": user_name, + "password": pwd + } + }).done(function (data) { + if (data.success === "true") { + alert(data.result); + window.location.href = "/login.html"; + } else { + $("#error").html(data.result); + } + }); +}); diff --git a/disconf-web/html/login.html b/disconf-web/html/login.html index 872703a24..0e96a963a 100644 --- a/disconf-web/html/login.html +++ b/disconf-web/html/login.html @@ -78,7 +78,11 @@
  • 登录 -
  • + +     +
  • + 注册 +
  • @@ -95,12 +99,12 @@
    -
    +

    登录

    @@ -115,7 +119,7 @@

    登录

     一个月内免登录
    diff --git a/disconf-web/html/main.html b/disconf-web/html/main.html index d057addf8..0ada912ec 100644 --- a/disconf-web/html/main.html +++ b/disconf-web/html/main.html @@ -94,7 +94,7 @@
    + + +
    +
    +
    + +
    + +
    + +
    + +
    + +
    + +
    +

    注册

    +
    + +
    + +
    + 用户名: + +
    + +
    + 密码: + +
    + + + +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + diff --git a/disconf-web/sql/0-init_table.sql b/disconf-web/sql/0-init_table.sql index 0a8ed950a..ec7e899de 100644 --- a/disconf-web/sql/0-init_table.sql +++ b/disconf-web/sql/0-init_table.sql @@ -14,6 +14,7 @@ CREATE TABLE `app` ( CREATE TABLE `config` ( `config_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '唯一的ID(没有啥意义,主键,自增长而已)', `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '配置文件/配置项', + `status` int(11) NOT NULL DEFAULT '1' COMMENT '状态:1是正常 0是删除', `name` varchar(255) NOT NULL DEFAULT '' COMMENT '配置文件名/配置项KeY名', `value` text NOT NULL COMMENT '0 配置文件:文件的内容,1 配置项:配置值', `app_id` bigint(20) NOT NULL COMMENT 'appid', @@ -24,6 +25,17 @@ CREATE TABLE `config` ( PRIMARY KEY (`config_id`) ) ENGINE=InnoDB AUTO_INCREMENT=150 DEFAULT CHARSET=utf8 COMMENT='配置'; +CREATE TABLE `config_history` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `config_id` bigint(20) NOT NULL, + `old_value` longtext NOT NULL, + `new_value` longtext NOT NULL, + `create_time` varchar(14) NOT NULL DEFAULT '99991231235959', + `update_by` bigint(20) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8; + + CREATE TABLE `env` ( `env_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '环境ID(主键,自增长)', `name` varchar(255) NOT NULL DEFAULT 'DEFAULT_ENV' COMMENT '环境名字', diff --git a/disconf-web/sql/1-init_data.sql b/disconf-web/sql/1-init_data.sql index 9fc37dbab..f4929ed9d 100644 --- a/disconf-web/sql/1-init_data.sql +++ b/disconf-web/sql/1-init_data.sql @@ -109,19 +109,12 @@ VALUES (71, 2, '/api/web/config/filetext/{configId}', 'update', '0100', '99991231235959'), (72, 3, '/api/web/config/filetext/{configId}', 'update', '0000', '99991231235959'); -/* testUser1 MhxzKhl9209*/ -/* testUser2 MhxzKhl167*/ -/* testUser3 MhxzKhl783*/ -/* testUser4 MhxzKhl8758*/ -/* testUser5 MhxzKhl112*/ +INSERT INTO `role_resource` (`role_id`, `url_pattern`, `url_description`, `method_mask`) VALUES + (1,'/api/account/password' , '修改密码' , '0100'), + (2,'/api/account/password' , '修改密码' , '0100'), + (3,'/api/account/password' , '修改密码' , '0000'); + /* admin admin*/ INSERT INTO `user` (`user_id`, `name`, `password`, `token`, `ownapps`, `role_id`) VALUES - (1, 'testUser1', '5eec8499597a115c88e0a9580ae1562ab85d0b1a', 'b9070d385a13357efa09e50e080607c2b299241b', '2', 1), - (2, 'testUser2', '71e9dc667eefa5a3a4840cb4f1ce22bc246f22f0', 'b169dec42f61ec6cbad88d70e7c4c6b89630ccfb', '2', 1), - (3, 'testUser3', 'e2cdc4a9195030543e38e19a923f075d54471cc4', 'a1a20b0e03a5191c530cbfc064eda3c16254df64', '2', 1), - (4, 'testUser4', '5cef2d7e4ada5a615f03e12b569d80aedfb056fc', '007b07fccbc1c82c987f7b8e4651e85cca01cf2b', '2', 1), - (5, 'testUser5', 'f996eeaa224abe0037d99adbce73c315e13238f9', 'c9dfdcb50a3d84f2b6a4771dcb7c2ceb19e7d281', '2', 1), - (6, 'admin', 'd033e22ae348aeb5660fc2140aec35850c4da997', 'f28d164d23291c732f64134e6b7d92be3ff8b1b3', '', 2), - (7, 'admin_read', 'b76f3e20d1c8d0bc17d40158e44097d5eeee8640', '2022ab9c2754d62f9ddba5fded91e4238247ebaf', '2', 3), - (8, 'mobiledsp', '0855b44a368e44dc6e6825532073b29a368584af', '132069654193f802203d1c6c86e753ecede698f6', '4', 1); + (1, 'admin', 'd033e22ae348aeb5660fc2140aec35850c4da997', 'f28d164d23291c732f64134e6b7d92be3ff8b1b3', '', 2) diff --git a/disconf-web/src/main/java/com/baidu/disconf/web/service/user/form/RegisterForm.java b/disconf-web/src/main/java/com/baidu/disconf/web/service/user/form/RegisterForm.java new file mode 100644 index 000000000..7c0b0ccc2 --- /dev/null +++ b/disconf-web/src/main/java/com/baidu/disconf/web/service/user/form/RegisterForm.java @@ -0,0 +1,28 @@ +package com.baidu.disconf.web.service.user.form; + +import com.baidu.dsp.common.form.RequestFormBase; +import lombok.Data; +import org.hibernate.validator.constraints.NotEmpty; + +import javax.validation.constraints.NotNull; + +/** + * Created by liaomengge on 16/8/31. + */ +@Data +public class RegisterForm extends RequestFormBase { + + /** + * 姓名 + */ + @NotNull(message = "name.empty") + @NotEmpty(message = "name.empty") + private String name; + + /** + * 密码 + */ + @NotEmpty(message = "password.empty") + @NotNull(message = "password.empty") + private String password; +} diff --git a/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserInnerMgrImpl.java b/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserInnerMgrImpl.java index b49454e46..7ffe7a775 100644 --- a/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserInnerMgrImpl.java +++ b/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserInnerMgrImpl.java @@ -1,7 +1,9 @@ package com.baidu.disconf.web.service.user.service.impl; -import java.util.Set; - +import com.baidu.disconf.web.service.user.dao.UserDao; +import com.baidu.disconf.web.service.user.dto.Visitor; +import com.baidu.disconf.web.service.user.service.UserInnerMgr; +import com.baidu.ub.common.commons.ThreadContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -9,10 +11,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import com.baidu.disconf.web.service.user.dao.UserDao; -import com.baidu.disconf.web.service.user.dto.Visitor; -import com.baidu.disconf.web.service.user.service.UserInnerMgr; -import com.baidu.ub.common.commons.ThreadContext; +import java.util.Set; /** * @author knightliao diff --git a/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserMgrImpl.java b/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserMgrImpl.java index 0693da89e..9d0b76ebf 100644 --- a/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserMgrImpl.java +++ b/disconf-web/src/main/java/com/baidu/disconf/web/service/user/service/impl/UserMgrImpl.java @@ -1,14 +1,5 @@ package com.baidu.disconf.web.service.user.service.impl; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - import com.baidu.disconf.web.service.sign.utils.SignUtils; import com.baidu.disconf.web.service.user.bo.User; import com.baidu.disconf.web.service.user.dao.UserDao; @@ -17,6 +8,15 @@ import com.baidu.disconf.web.service.user.service.UserMgr; import com.baidu.disconf.web.service.user.vo.VisitorVo; import com.baidu.ub.common.commons.ThreadContext; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; /** * @author liaoqiqi @@ -90,13 +90,26 @@ public List getAll() { public String addOneAppForUser(Long userId, int appId) { User user = getUser(userId); + String ownAppIds = user.getOwnApps(); - if (ownAppIds.contains(",")) { - ownAppIds = ownAppIds + "," + appId; + //此处`admin`用户,并非指的是管理员,而是作为一个特殊的用户 + if ("admin".equals(user.getName()) && StringUtils.isNotBlank(ownAppIds)) { + ownAppIds = StringUtils.EMPTY; + user.setOwnApps(ownAppIds); + userDao.update(user); + return ownAppIds; + } - } else { + if (StringUtils.isBlank(ownAppIds)) { ownAppIds = String.valueOf(appId); + } else { + if (",".equals(ownAppIds.substring(ownAppIds.length() - 1))) { + ownAppIds += appId; + } else { + ownAppIds += "," + appId; + } } + user.setOwnApps(ownAppIds); userDao.update(user); diff --git a/disconf-web/src/main/java/com/baidu/disconf/web/tools/UserCreateCommon.java b/disconf-web/src/main/java/com/baidu/disconf/web/tools/UserCreateCommon.java index c7ae06b97..93230868f 100644 --- a/disconf-web/src/main/java/com/baidu/disconf/web/tools/UserCreateCommon.java +++ b/disconf-web/src/main/java/com/baidu/disconf/web/tools/UserCreateCommon.java @@ -1,16 +1,15 @@ package com.baidu.disconf.web.tools; -import java.util.ArrayList; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.baidu.disconf.web.service.role.bo.RoleEnum; import com.baidu.disconf.web.service.sign.utils.SignUtils; import com.baidu.disconf.web.service.user.bo.User; import com.baidu.disconf.web.service.user.dao.UserDao; import com.github.knightliao.apollo.utils.common.RandomUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; /** * @author knightliao @@ -95,10 +94,6 @@ public static void generateCreateTestUserSQL(UserDao userDao) { */ private static void printUserList(List userList) { - // - // - // - for (User user : userList) { if (user.getId() != null) { diff --git a/disconf-web/src/main/java/com/baidu/disconf/web/web/app/controller/AppController.java b/disconf-web/src/main/java/com/baidu/disconf/web/web/app/controller/AppController.java index 31f1c7656..4136f1d39 100644 --- a/disconf-web/src/main/java/com/baidu/disconf/web/web/app/controller/AppController.java +++ b/disconf-web/src/main/java/com/baidu/disconf/web/web/app/controller/AppController.java @@ -1,9 +1,17 @@ package com.baidu.disconf.web.web.app.controller; -import java.util.List; - -import javax.validation.Valid; - +import com.baidu.disconf.web.service.app.bo.App; +import com.baidu.disconf.web.service.app.form.AppNewForm; +import com.baidu.disconf.web.service.app.service.AppMgr; +import com.baidu.disconf.web.service.app.vo.AppListVo; +import com.baidu.disconf.web.service.user.dto.Visitor; +import com.baidu.disconf.web.service.user.service.UserMgr; +import com.baidu.disconf.web.service.user.vo.VisitorVo; +import com.baidu.disconf.web.web.app.validator.AppValidator; +import com.baidu.dsp.common.constant.WebConstants; +import com.baidu.dsp.common.controller.BaseController; +import com.baidu.dsp.common.vo.JsonObjectBase; +import com.baidu.ub.common.commons.ThreadContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -12,13 +20,9 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; -import com.baidu.disconf.web.service.app.form.AppNewForm; -import com.baidu.disconf.web.service.app.service.AppMgr; -import com.baidu.disconf.web.service.app.vo.AppListVo; -import com.baidu.disconf.web.web.app.validator.AppValidator; -import com.baidu.dsp.common.constant.WebConstants; -import com.baidu.dsp.common.controller.BaseController; -import com.baidu.dsp.common.vo.JsonObjectBase; +import javax.validation.Valid; +import java.util.List; +import java.util.Set; /** * @author liaoqiqi @@ -36,6 +40,9 @@ public class AppController extends BaseController { @Autowired private AppValidator appValidator; + @Autowired + private UserMgr userMgr; + /** * list * @@ -63,7 +70,22 @@ public JsonObjectBase create(@Valid AppNewForm appNewForm) { appValidator.validateCreate(appNewForm); - appMgr.create(appNewForm); + App app = appMgr.create(appNewForm); + + //bind user + VisitorVo visitorVo = userMgr.getCurVisitor(); + userMgr.addOneAppForUser(visitorVo.getId(), app.getId().intValue()); + + + //update session apps + Visitor visitor = ThreadContext.getSessionVisitor(); + + if (visitor != null) { + Set appIds = visitor.getAppIds(); + if (appIds != null) { + appIds.add(app.getId()); + } + } return buildSuccess("创建成功"); } diff --git a/disconf-web/src/main/java/com/baidu/disconf/web/web/auth/UserController.java b/disconf-web/src/main/java/com/baidu/disconf/web/web/auth/UserController.java index 67d91808a..9c7552e37 100644 --- a/disconf-web/src/main/java/com/baidu/disconf/web/web/auth/UserController.java +++ b/disconf-web/src/main/java/com/baidu/disconf/web/web/auth/UserController.java @@ -1,21 +1,14 @@ package com.baidu.disconf.web.web.auth; -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - +import com.baidu.disconf.web.service.role.bo.RoleEnum; import com.baidu.disconf.web.service.sign.form.SigninForm; import com.baidu.disconf.web.service.sign.service.SignMgr; +import com.baidu.disconf.web.service.sign.utils.SignUtils; import com.baidu.disconf.web.service.user.bo.User; +import com.baidu.disconf.web.service.user.dao.UserDao; import com.baidu.disconf.web.service.user.dto.Visitor; import com.baidu.disconf.web.service.user.form.PasswordModifyForm; +import com.baidu.disconf.web.service.user.form.RegisterForm; import com.baidu.disconf.web.service.user.service.UserMgr; import com.baidu.disconf.web.service.user.vo.VisitorVo; import com.baidu.disconf.web.web.auth.constant.LoginConstant; @@ -27,6 +20,16 @@ import com.baidu.dsp.common.controller.BaseController; import com.baidu.dsp.common.vo.JsonObjectBase; import com.baidu.ub.common.commons.ThreadContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; /** * @author liaoqiqi @@ -50,6 +53,9 @@ public class UserController extends BaseController { @Autowired private RedisLogin redisLogin; + @Autowired + private UserDao userDao; + /** * GET 获取 * @@ -133,6 +139,7 @@ public JsonObjectBase signout(HttpServletRequest request) { * * @return */ + @NoAuth @RequestMapping(value = "/password", method = RequestMethod.PUT) @ResponseBody public JsonObjectBase password(@Valid PasswordModifyForm passwordModifyForm, HttpServletRequest request) { @@ -144,9 +151,40 @@ public JsonObjectBase password(@Valid PasswordModifyForm passwordModifyForm, Htt Visitor visitor = ThreadContext.getSessionVisitor(); userMgr.modifyPassword(visitor.getLoginUserId(), passwordModifyForm.getNew_password()); - // re login + // relogin redisLogin.logout(request); - return buildSuccess("修改成功,请重新登录"); + return buildSuccess("修改密码成功,请重新登录"); + } + + + @NoAuth + @RequestMapping(value = "/register", method = RequestMethod.PUT) + @ResponseBody + public JsonObjectBase register(@Valid RegisterForm registerForm, HttpServletRequest request) { + + String regUserName = registerForm.getName(); + String regPwd = registerForm.getPassword(); + + //校验是否存在用户名 + User user = userDao.getUserByName(regUserName); + + if (user != null) { + return buildFail("用户名存在, 注册失败"); + } + + //新增用户 + user = new User(); + user.setName(regUserName); + user.setPassword(SignUtils.createPassword(regPwd)); + user.setToken(SignUtils.createToken(regUserName)); + user.setOwnApps("0"); + //此处给管理员的权限,就是为了admin中心权限,下方到各个部门权限 + user.setRoleId(RoleEnum.ADMIN.getValue()); + + userMgr.create(user); + + return buildSuccess("注册成功,请重新登录"); } + } diff --git a/disconf-web/src/main/java/com/baidu/dsp/common/controller/BaseController.java b/disconf-web/src/main/java/com/baidu/dsp/common/controller/BaseController.java index aaf855944..2f269b4d7 100644 --- a/disconf-web/src/main/java/com/baidu/dsp/common/controller/BaseController.java +++ b/disconf-web/src/main/java/com/baidu/dsp/common/controller/BaseController.java @@ -1,11 +1,11 @@ package com.baidu.dsp.common.controller; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.baidu.dsp.common.constant.ErrorCode; +import com.baidu.dsp.common.constant.WebConstants; +import com.baidu.dsp.common.utils.ParamValidateUtils; +import com.baidu.dsp.common.vo.JsonObjectBase; +import com.baidu.dsp.common.vo.JsonObjectUtils; +import com.baidu.ub.common.db.DaoPageResult; import org.springframework.beans.BeansException; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.context.ApplicationContext; @@ -18,12 +18,11 @@ import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.servlet.ModelAndView; -import com.baidu.dsp.common.constant.ErrorCode; -import com.baidu.dsp.common.constant.WebConstants; -import com.baidu.dsp.common.utils.ParamValidateUtils; -import com.baidu.dsp.common.vo.JsonObjectBase; -import com.baidu.dsp.common.vo.JsonObjectUtils; -import com.baidu.ub.common.db.DaoPageResult; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author liaoqiqi @@ -60,6 +59,17 @@ protected JsonObjectBase buildSuccess(T value) { return JsonObjectUtils.buildSimpleObjectSuccess(value); } + /** + * Fail:非列表数据 + * + * @param value + * + * @return + */ + protected JsonObjectBase buildFail(T value) { + return JsonObjectUtils.buildSimpleObjectFail(value); + } + /** * OK: 列表数据 * diff --git a/disconf-web/src/main/java/com/baidu/dsp/common/interceptor/login/LoginInterceptor.java b/disconf-web/src/main/java/com/baidu/dsp/common/interceptor/login/LoginInterceptor.java index 5cab82dd3..35fbdc25d 100644 --- a/disconf-web/src/main/java/com/baidu/dsp/common/interceptor/login/LoginInterceptor.java +++ b/disconf-web/src/main/java/com/baidu/dsp/common/interceptor/login/LoginInterceptor.java @@ -1,17 +1,5 @@ package com.baidu.dsp.common.interceptor.login; -import java.util.List; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.servlet.ModelAndView; - import com.baidu.disconf.web.service.user.constant.UserConstant; import com.baidu.disconf.web.service.user.dto.Visitor; import com.baidu.disconf.web.service.user.service.UserMgr; @@ -21,6 +9,16 @@ import com.baidu.dsp.common.interceptor.WebCommonInterceptor; import com.github.knightliao.apollo.utils.tool.TokenUtil; import com.github.knightliao.apollo.utils.web.CookieUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.util.List; /** * 所有请求(一个Session可能会有多个请求)均会通过此拦截器 diff --git a/disconf-web/src/main/java/com/baidu/dsp/common/utils/email/LogMailBean.java b/disconf-web/src/main/java/com/baidu/dsp/common/utils/email/LogMailBean.java index 3ad391a2c..be635b4a2 100644 --- a/disconf-web/src/main/java/com/baidu/dsp/common/utils/email/LogMailBean.java +++ b/disconf-web/src/main/java/com/baidu/dsp/common/utils/email/LogMailBean.java @@ -1,19 +1,21 @@ package com.baidu.dsp.common.utils.email; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; -import java.util.Date; - +import com.baidu.disconf.web.config.ApplicationPropertyConfig; +import com.baidu.disconf.web.service.user.dto.Visitor; +import com.baidu.ub.common.commons.ThreadContext; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.baidu.disconf.web.config.ApplicationPropertyConfig; -import com.baidu.disconf.web.service.user.dto.Visitor; -import com.baidu.ub.common.commons.ThreadContext; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @author liaoqiqi @@ -24,6 +26,8 @@ public class LogMailBean { protected static final Logger LOG = LoggerFactory.getLogger(LogMailBean.class); + private final ExecutorService service = Executors.newFixedThreadPool(10); + /** * 发送报警邮件中标题的最大长度,255 */ @@ -108,7 +112,7 @@ public void sendLogExceptionEmail(String message, Throwable e) { * * @return */ - public boolean sendHtmlEmail(String toEmail, String title, String content) { + public boolean sendHtmlEmail(String toEmail, String title, final String content) { LOG.info("send to " + toEmail); LOG.info("title: " + title); @@ -148,8 +152,8 @@ public boolean sendHtmlEmail(String toEmail, String title, String content) { } String mailTo = toEmail; - String mailFrom = emailProperties.getFromEmail(); - String[] mailToList = mailTo.split(";"); + final String mailFrom = emailProperties.getFromEmail(); + final String[] mailToList = mailTo.split(";"); if (content == null) { @@ -158,7 +162,14 @@ public boolean sendHtmlEmail(String toEmail, String title, String content) { } else { try { - mailBean.sendHtmlMail(mailFrom, mailToList, mailTitle, content); + final String finalMailTitle = mailTitle; + service.submit(new Callable() { + @Override + public Object call() throws Exception { + mailBean.sendHtmlMail(mailFrom, mailToList, finalMailTitle, content); + return null; + } + }); } catch (Exception e) { LOG.error("When send alarm mail,we can't send it", e); return false; diff --git a/disconf-web/src/main/java/com/baidu/dsp/common/vo/JsonObjectUtils.java b/disconf-web/src/main/java/com/baidu/dsp/common/vo/JsonObjectUtils.java index 62225fd42..8d1b8591b 100644 --- a/disconf-web/src/main/java/com/baidu/dsp/common/vo/JsonObjectUtils.java +++ b/disconf-web/src/main/java/com/baidu/dsp/common/vo/JsonObjectUtils.java @@ -1,8 +1,8 @@ package com.baidu.dsp.common.vo; -import java.util.List; -import java.util.Map; - +import com.baidu.dsp.common.constant.ErrorCode; +import com.baidu.dsp.common.constant.FrontEndInterfaceConstant; +import com.baidu.dsp.common.context.ContextReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -12,9 +12,8 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.json.MappingJackson2JsonView; -import com.baidu.dsp.common.constant.ErrorCode; -import com.baidu.dsp.common.constant.FrontEndInterfaceConstant; -import com.baidu.dsp.common.context.ContextReader; +import java.util.List; +import java.util.Map; /** * 通用的JSON返回器 @@ -69,6 +68,24 @@ public static JsonObjectBase buildSimpleObjectSuccess(T value) { return json; } + /** + * 返回错误(顶层结构), 非列表请求 + * + * @param value + * + * @return + */ + public static JsonObjectBase buildSimpleObjectFail(T value) { + + JsonSimpleObject json = new JsonSimpleObject(); + json.setSuccess(FrontEndInterfaceConstant.RETURN_FAIL); + json.setResult(value); + + LOG.info(json.toString()); + + return json; + } + /** * 返回正确, 列表请求 * diff --git a/disconf-web/src/main/resources/myconfig/spring-servlet-interceptor.xml b/disconf-web/src/main/resources/myconfig/spring-servlet-interceptor.xml index b16504467..008d14bc3 100644 --- a/disconf-web/src/main/resources/myconfig/spring-servlet-interceptor.xml +++ b/disconf-web/src/main/resources/myconfig/spring-servlet-interceptor.xml @@ -30,6 +30,7 @@ /api/config/file /api/config/list /api/config/simple/list + /api/account/register