Search in sources :

Example 16 with UserInfo

use of org.maxkey.entity.UserInfo in project MaxKey by dromara.

the class SafeController method setting.

@ResponseBody
@RequestMapping(value = "/setting")
public Message setting(HttpServletRequest request, HttpServletResponse response, @RequestParam("authnType") String authnType, @RequestParam("mobile") String mobile, @RequestParam("mobileVerify") String mobileVerify, @RequestParam("email") String email, @RequestParam("emailVerify") String emailVerify, @RequestParam("theme") String theme) {
    UserInfo userInfo = WebContext.getUserInfo();
    userInfo.setAuthnType(Integer.parseInt(authnType));
    userInfoService.updateAuthnType(userInfo);
    userInfo.setMobile(mobile);
    userInfoService.updateMobile(userInfo);
    userInfo.setEmail(email);
    userInfo.setTheme(theme);
    WebContext.setCookie(response, null, WebConstants.THEME_COOKIE_NAME, theme, ConstsTimeInterval.ONE_WEEK);
    userInfoService.updateEmail(userInfo);
    return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS), MessageType.success);
}
Also used : ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) Message(org.maxkey.web.message.Message) UserInfo(org.maxkey.entity.UserInfo) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with UserInfo

use of org.maxkey.entity.UserInfo in project MaxKey by dromara.

the class SafeController method changeAppLoginPasswod.

@ResponseBody
@RequestMapping(value = "/changeAppLoginPasswod")
public Message changeAppLoginPasswod(@RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword, @RequestParam("confirmPassword") String confirmPassword) {
    UserInfo userInfo = WebContext.getUserInfo();
    _logger.debug("App Login Password : " + userInfo.getAppLoginPassword());
    _logger.debug("App Login new Password : " + PasswordReciprocal.getInstance().encode(newPassword));
    if (newPassword.equals(confirmPassword)) {
        if (StringUtils.isEmpty(userInfo.getAppLoginPassword()) || userInfo.getAppLoginPassword().equals(PasswordReciprocal.getInstance().encode(oldPassword))) {
            userInfo.setAppLoginPassword(PasswordReciprocal.getInstance().encode(newPassword));
            boolean change = userInfoService.updateAppLoginPassword(userInfo);
            _logger.debug("" + change);
            return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS), MessageType.prompt);
        }
    }
    return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR), MessageType.error);
}
Also used : ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) Message(org.maxkey.web.message.Message) UserInfo(org.maxkey.entity.UserInfo) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with UserInfo

use of org.maxkey.entity.UserInfo in project MaxKey by dromara.

the class UserInfoController method importing.

@RequestMapping(value = "/import")
public ModelAndView importing(@ModelAttribute("excelImportFile") ExcelImport excelImportFile) {
    if (excelImportFile.isExcelNotEmpty()) {
        try {
            List<UserInfo> userInfoList = Lists.newArrayList();
            Workbook workbook = excelImportFile.biuldWorkbook();
            int recordCount = 0;
            int sheetSize = workbook.getNumberOfSheets();
            for (int i = 0; i < sheetSize; i++) {
                // 遍历sheet页
                Sheet sheet = workbook.getSheetAt(i);
                int rowSize = sheet.getLastRowNum() + 1;
                for (int j = 1; j < rowSize; j++) {
                    // 遍历行
                    Row row = sheet.getRow(j);
                    if (row == null || j < 3) {
                        // 略过空行和前3行
                        continue;
                    } else {
                        // 其他行是数据行
                        UserInfo userInfo = buildUserFromSheetRow(row);
                        userInfoList.add(userInfo);
                        recordCount++;
                        _logger.debug("record {} user {} account {}", recordCount, userInfo.getDisplayName(), userInfo.getUsername());
                    }
                }
            }
            // 数据去重
            if (!CollectionUtils.isEmpty(userInfoList)) {
                userInfoList = userInfoList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getUsername()))), ArrayList::new));
                if (userInfoService.insertBatch(userInfoList)) {
                    new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS), null, MessageType.success, OperateType.add, MessageScope.DB);
                } else {
                    new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            excelImportFile.closeWorkbook();
        }
    } else {
        new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error);
    }
    return new ModelAndView("/userinfo/usersImport");
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) MessageType(org.maxkey.web.message.MessageType) OperateType(org.maxkey.web.message.OperateType) RequestParam(org.springframework.web.bind.annotation.RequestParam) DateUtils(org.maxkey.util.DateUtils) UserInfo(org.maxkey.entity.UserInfo) Date(java.util.Date) UserInfoService(org.maxkey.persistence.service.UserInfoService) MessageScope(org.maxkey.web.message.MessageScope) ExcelUtils(org.maxkey.util.ExcelUtils) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) JsonUtils(org.maxkey.util.JsonUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) BindingResult(org.springframework.validation.BindingResult) Controller(org.springframework.stereotype.Controller) ConstsPasswordSetType(org.maxkey.constants.ConstsPasswordSetType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Valid(javax.validation.Valid) StringUtils(org.maxkey.util.StringUtils) Message(org.maxkey.web.message.Message) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Lists(com.google.common.collect.Lists) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) Sheet(org.apache.poi.ss.usermodel.Sheet) Logger(org.slf4j.Logger) IOException(java.io.IOException) PropertyEditorSupport(java.beans.PropertyEditorSupport) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Workbook(org.apache.poi.ss.usermodel.Workbook) JpaPageResults(org.apache.mybatis.jpa.persistence.JpaPageResults) WebContext(org.maxkey.web.WebContext) CollectionUtils(org.springframework.util.CollectionUtils) WebDataBinder(org.springframework.web.bind.WebDataBinder) Row(org.apache.poi.ss.usermodel.Row) Comparator(java.util.Comparator) InitBinder(org.springframework.web.bind.annotation.InitBinder) PasswordReciprocal(org.maxkey.crypto.password.PasswordReciprocal) ExcelImport(org.maxkey.entity.ExcelImport) ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) Message(org.maxkey.web.message.Message) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.maxkey.entity.UserInfo) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with UserInfo

use of org.maxkey.entity.UserInfo in project MaxKey by dromara.

the class UserInfoController method forwardChangeUserinfoStatus.

@RequestMapping(value = { "/forwardChangeUserinfoStatus/{id}" })
public ModelAndView forwardChangeUserinfoStatus(@PathVariable("id") String id) {
    ModelAndView modelAndView = new ModelAndView("/userinfo/changeUserinfoStatus");
    UserInfo userInfo = userInfoService.get(id);
    modelAndView.addObject("model", userInfo);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.maxkey.entity.UserInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with UserInfo

use of org.maxkey.entity.UserInfo in project MaxKey by dromara.

the class UserInfoController method getUserInfo.

/**
 * 查询用户,根据id
 * @param id
 * @return
 */
@ResponseBody
@RequestMapping(value = "/getUsers/{id}")
public UserInfo getUserInfo(@PathVariable("id") String id) {
    _logger.debug(id);
    UserInfo userInfo = userInfoService.get(id);
    if (userInfo != null && userInfo.getDecipherable() != null) {
        try {
            userInfo.setPassword(PasswordReciprocal.getInstance().decoder(userInfo.getDecipherable()));
        } catch (Exception e) {
        }
        userInfo.setDecipherable(userInfo.getPassword());
    }
    return userInfo;
}
Also used : UserInfo(org.maxkey.entity.UserInfo) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserInfo (org.maxkey.entity.UserInfo)85 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)42 ModelAndView (org.springframework.web.servlet.ModelAndView)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 Message (org.maxkey.web.message.Message)8 Date (java.util.Date)7 HashMap (java.util.HashMap)7 Operation (io.swagger.v3.oas.annotations.Operation)6 ConstsOperateMessage (org.maxkey.constants.ConstsOperateMessage)6 Accounts (org.maxkey.entity.Accounts)6 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)6 SigninPrincipal (org.maxkey.authn.SigninPrincipal)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ServiceResponseBuilder (org.maxkey.authz.cas.endpoint.response.ServiceResponseBuilder)4 AbstractAuthorizeAdapter (org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter)4 SynchroRelated (org.maxkey.entity.SynchroRelated)4 NamingException (javax.naming.NamingException)3 ProxyServiceResponseBuilder (org.maxkey.authz.cas.endpoint.response.ProxyServiceResponseBuilder)3 Ticket (org.maxkey.authz.cas.endpoint.ticket.Ticket)3 Apps (org.maxkey.entity.apps.Apps)3