use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.
the class LoginController method loginIn.
/**
* 用户登录
*
* @param userName 用户名
* @param password 密码
* @param isAdmin 是否勾选超级管理员选项,1是0否
* @return
*/
@RequestMapping(value = "/loginIn", method = RequestMethod.POST)
public ModelAndView loginIn(HttpServletRequest request, HttpServletResponse response, Model model, String userName, String password, boolean isAdmin) {
// 登录结果
LoginResult loginResult = new LoginResult();
loginResult.setAdminEnum((isAdmin == true ? AdminEnum.IS_ADMIN : AdminEnum.NOT_ADMIN));
loginResult.setLoginEnum(LoginEnum.LOGIN_WRONG_USER_OR_PASSWORD);
AppUser userModel = null;
if (ConstUtils.SUPER_ADMIN_NAME.equals(userName)) {
userModel = userService.getByName(userName);
if (userModel != null && ConstUtils.SUPER_ADMIN_PASS.equals(password)) {
loginResult.setLoginEnum(LoginEnum.LOGIN_SUCCESS);
} else {
loginResult.setLoginEnum(LoginEnum.LOGIN_WRONG_USER_OR_PASSWORD);
}
} else {
if (LoginUtil.passportCheck(userName, password)) {
// 同时要验证是否有cachecloud权限
userModel = userService.getByName(userName);
if (userModel != null && userModel.getType() != AppUserTypeEnum.NO_USER.value()) {
if (isAdmin) {
if (AppUserTypeEnum.ADMIN_USER.value().equals(userModel.getType())) {
loginResult.setLoginEnum(LoginEnum.LOGIN_SUCCESS);
} else {
loginResult.setLoginEnum(LoginEnum.LOGIN_NOT_ADMIN);
}
} else {
loginResult.setLoginEnum(LoginEnum.LOGIN_SUCCESS);
}
} else {
// 用户不存在
loginResult.setLoginEnum(LoginEnum.LOGIN_USER_NOT_EXIST);
}
}
}
// 登录成功写入登录状态
if (loginResult.getLoginEnum().equals(LoginEnum.LOGIN_SUCCESS)) {
userLoginStatusService.addLoginStatus(request, response, userModel.getId().toString());
}
model.addAttribute("success", loginResult.getLoginEnum().value());
model.addAttribute("admin", loginResult.getAdminEnum().value());
return new ModelAndView();
}
use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.
the class RedisConfigTemplateController method add.
/**
* 添加配置
*/
@RequestMapping(value = "/add")
public ModelAndView add(HttpServletRequest request, HttpServletResponse response, Model model) {
AppUser appUser = getUserInfo(request);
InstanceConfig instanceConfig = getInstanceConfig(request);
if (StringUtils.isBlank(instanceConfig.getConfigKey())) {
model.addAttribute("status", SuccessEnum.FAIL.value());
model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "configKey=" + instanceConfig.getConfigKey());
return new ModelAndView("");
}
logger.warn("user {} want to add config, configKey is {}, configValue is {}, type is {}", appUser.getName(), instanceConfig.getConfigKey(), instanceConfig.getType());
SuccessEnum successEnum;
try {
redisConfigTemplateService.saveOrUpdate(instanceConfig);
successEnum = SuccessEnum.SUCCESS;
} catch (Exception e) {
successEnum = SuccessEnum.FAIL;
model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
logger.error(e.getMessage(), e);
}
logger.warn("user {} want to add config, configKey is {}, configValue is {}, type is {}, result is {}", appUser.getName(), instanceConfig.getConfigKey(), instanceConfig.getConfigValue(), instanceConfig.getType(), successEnum.value());
model.addAttribute("status", successEnum.value());
//发送邮件通知
appEmailUtil.sendRedisConfigTemplateChangeEmail(appUser, instanceConfig, successEnum, RedisConfigTemplateChangeEnum.ADD);
return new ModelAndView("");
}
use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.
the class RedisConfigTemplateController method update.
/**
* 修改配置
*/
@RequestMapping(value = "/update")
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, Model model) {
AppUser appUser = getUserInfo(request);
String id = request.getParameter("id");
String configKey = request.getParameter("configKey");
String configValue = request.getParameter("configValue");
String info = request.getParameter("info");
int status = NumberUtils.toInt(request.getParameter("status"), -1);
if (StringUtils.isBlank(id) || !NumberUtils.isDigits(id) || StringUtils.isBlank(configKey) || status > 1 || status < 0) {
model.addAttribute("status", SuccessEnum.FAIL.value());
model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "id=" + id + ",configKey=" + configKey + ",configValue=" + configValue + ",status=" + status);
return new ModelAndView("");
}
//开始修改
logger.warn("user {} want to change id={}'s configKey={}, configValue={}, info={}, status={}", appUser.getName(), id, configKey, configValue, info, status);
SuccessEnum successEnum;
InstanceConfig instanceConfig = redisConfigTemplateService.getById(NumberUtils.toLong(id));
try {
instanceConfig.setConfigValue(configValue);
instanceConfig.setInfo(info);
instanceConfig.setStatus(status);
redisConfigTemplateService.saveOrUpdate(instanceConfig);
successEnum = SuccessEnum.SUCCESS;
} catch (Exception e) {
successEnum = SuccessEnum.FAIL;
model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
logger.error(e.getMessage(), e);
}
logger.warn("user {} want to change id={}'s configKey={}, configValue={}, info={}, status={}, result is {}", appUser.getName(), id, configKey, configValue, info, status, successEnum.value());
//发送邮件通知
appEmailUtil.sendRedisConfigTemplateChangeEmail(appUser, instanceConfig, successEnum, RedisConfigTemplateChangeEnum.UPDATE);
model.addAttribute("status", successEnum.value());
return new ModelAndView("");
}
use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.
the class ManageUserLoginInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
long userId = userLoginStatusService.getUserIdFromLoginStatus(request);
AppUser user = userService.get(userId);
//必须是管理员
if (user == null || user.getType() != AppUserTypeEnum.ADMIN_USER.value()) {
String redirectUrl = LoginInterceptorUtil.getLoginRedirectUrl(request);
response.sendRedirect(redirectUrl);
return false;
}
request.setAttribute("userInfo", user);
request.setAttribute("uri", request.getRequestURI());
return true;
}
use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.
the class AppAuditDaoTest method testInsert.
@Test
public void testInsert() {
int memSize = 4;
AppDesc appDesc = appDao.getAppDescById(10132L);
AppUser appUser = appUserDao.get(10016L);
AppAudit appAudit = new AppAudit();
appAudit.setAppId(appDesc.getAppId());
appAudit.setUserId(appUser.getId());
appAudit.setUserName(appUser.getName());
appAudit.setModifyTime(new Date());
appAudit.setParam1(String.valueOf(memSize));
appAudit.setParam2(appDesc.getTypeDesc());
appAudit.setInfo("应用申请:类型:" + appDesc.getTypeDesc() + ";初始申请空间:" + memSize + ";");
appAudit.setStatus(AppStatusEnum.STATUS_INITIALIZE.getStatus());
appAudit.setType(AppAuditType.APP_AUDIT.getValue());
appAuditDao.insertAppAudit(appAudit);
}
Aggregations