Search in sources :

Example 21 with AppUser

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();
}
Also used : LoginResult(com.sohu.cache.entity.LoginResult) ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with AppUser

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("");
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with AppUser

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("");
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with AppUser

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;
}
Also used : AppUser(com.sohu.cache.entity.AppUser)

Example 25 with AppUser

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);
}
Also used : AppAudit(com.sohu.cache.entity.AppAudit) AppUser(com.sohu.cache.entity.AppUser) AppDesc(com.sohu.cache.entity.AppDesc) Date(java.util.Date) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Aggregations

AppUser (com.sohu.cache.entity.AppUser)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 ModelAndView (org.springframework.web.servlet.ModelAndView)15 SuccessEnum (com.sohu.cache.web.enums.SuccessEnum)8 AppAudit (com.sohu.cache.entity.AppAudit)3 InstanceConfig (com.sohu.cache.entity.InstanceConfig)3 AppDesc (com.sohu.cache.entity.AppDesc)2 AppToUser (com.sohu.cache.entity.AppToUser)2 InstanceAlert (com.sohu.cache.entity.InstanceAlert)2 BaseTest (com.sohu.test.BaseTest)2 Date (java.util.Date)2 Test (org.junit.Test)2 AppDataMigrateEnum (com.sohu.cache.constant.AppDataMigrateEnum)1 AppDailyData (com.sohu.cache.entity.AppDailyData)1 InstanceAlertValueResult (com.sohu.cache.entity.InstanceAlertValueResult)1 InstanceInfo (com.sohu.cache.entity.InstanceInfo)1 LoginResult (com.sohu.cache.entity.LoginResult)1 SystemConfig (com.sohu.cache.entity.SystemConfig)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1