use of com.publiccms.entities.sys.SysUser in project PublicCMS-preview by sanluan.
the class LoginController method login.
/**
* @param username
* @param password
* @param returnUrl
* @param request
* @param response
* @param model
* @return view name
*/
@RequestMapping(value = "doLogin", method = RequestMethod.POST)
public String login(String username, String password, String returnUrl, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
SysSite site = getSite(request);
if (CommonUtils.empty(returnUrl)) {
returnUrl = site.getDynamicPath();
}
Map<String, String> config = configComponent.getConfigData(site.getId(), Config.CONFIG_CODE_SITE);
String loginPath = config.get(LoginConfigComponent.CONFIG_LOGIN_PATH);
if (CommonUtils.empty(loginPath)) {
loginPath = site.getDynamicPath();
}
username = StringUtils.trim(username);
password = StringUtils.trim(password);
if (ControllerUtils.verifyNotEmpty("username", username, model) || ControllerUtils.verifyNotEmpty("password", password, model)) {
return REDIRECT + loginPath;
} else {
SysUser user;
if (verifyNotEMail(username)) {
user = service.findByName(site.getId(), username);
} else {
user = service.findByEmail(site.getId(), username);
}
String ip = RequestUtils.getIpAddress(request);
if (ControllerUtils.verifyNotExist("username", user, model) || ControllerUtils.verifyNotEquals("password", VerificationUtils.md5Encode(password), user.getPassword(), model) || verifyNotEnablie(user, model)) {
Long userId = null;
if (null != user) {
userId = user.getId();
}
logLoginService.save(new LogLogin(site.getId(), username, userId, ip, LogLoginService.CHANNEL_WEB, false, CommonUtils.getDate(), password));
return REDIRECT + loginPath;
} else {
user.setPassword(null);
setUserToSession(request.getSession(), user);
String authToken = UUID.randomUUID().toString();
addLoginStatus(user, authToken, request, response);
sysUserTokenService.save(new SysUserToken(authToken, site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, CommonUtils.getDate(), ip));
service.updateLoginStatus(user.getId(), ip);
logLoginService.save(new LogLogin(site.getId(), username, user.getId(), ip, LogLoginService.CHANNEL_WEB, true, CommonUtils.getDate(), null));
return REDIRECT + returnUrl;
}
}
}
use of com.publiccms.entities.sys.SysUser in project PublicCMS-preview by sanluan.
the class LoginController method loginStatus.
/**
* @param request
* @param session
* @param response
* @param model
* @return result
*/
@RequestMapping("loginStatus")
@ResponseBody
public ModelMap loginStatus(HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
SysUser user = getUserFromSession(session);
if (null != user) {
model.addAttribute("id", user.getId());
model.addAttribute("name", user.getName());
model.addAttribute("nickname", user.getNickName());
model.addAttribute("email", user.getEmail());
model.addAttribute("emailChecked", user.isEmailChecked());
model.addAttribute("superuserAccess", user.isSuperuserAccess());
}
return model;
}
use of com.publiccms.entities.sys.SysUser in project PublicCMS-preview by sanluan.
the class LotteryController method lottery.
/**
* @param callback
* @param request
* @param session
* @param response
*/
@RequestMapping("lottery")
public void lottery(String callback, HttpServletRequest request, HttpSession session, HttpServletResponse response) {
try {
HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
SysUser user = getUserFromSession(session);
if (null != user) {
lotteryDirective.execute(handler, null, user);
}
handler.render();
} catch (Exception e) {
}
}
use of com.publiccms.entities.sys.SysUser in project PublicCMS-preview by sanluan.
the class PlaceController method delete.
/**
* @param id
* @param returnUrl
* @param request
* @param session
* @param response
* @param model
* @return view name
*/
@RequestMapping("delete")
public String delete(Long id, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
SysSite site = getSite(request);
if (CommonUtils.empty(returnUrl)) {
returnUrl = site.getDynamicPath();
}
CmsPlace entity = service.getEntity(id);
SysUser user = getUserFromSession(session);
String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
if (ControllerUtils.verifyCustom("manage", null == entity || null == user || CommonUtils.empty(metadata.getAdminIds()) || !ArrayUtils.contains(metadata.getAdminIds(), user.getId()), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
return REDIRECT + returnUrl;
} else {
service.delete(id);
logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "delete.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), id.toString()));
return REDIRECT + returnUrl;
}
}
use of com.publiccms.entities.sys.SysUser in project PublicCMS-preview by sanluan.
the class PlaceController method save.
/**
* @param entity
* @param returnUrl
* @param placeParamters
* @param request
* @param session
* @param response
* @param model
* @return view name
*/
@RequestMapping(value = "save")
public String save(CmsPlace entity, String returnUrl, @ModelAttribute CmsPlaceParamters placeParamters, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
SysSite site = getSite(request);
if (CommonUtils.empty(returnUrl)) {
returnUrl = site.getDynamicPath();
}
if (null != entity && CommonUtils.notEmpty(entity.getPath())) {
entity.setPath(entity.getPath().replace("//", SEPARATOR));
String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
SysUser user = getUserFromSession(session);
if (ControllerUtils.verifyCustom("contribute", null == metadata || !metadata.isAllowContribute() || 0 >= metadata.getSize() || (null == user && !metadata.isAllowAnonymous()), model)) {
return REDIRECT + returnUrl;
}
if (null != entity.getId()) {
CmsPlace oldEntity = service.getEntity(entity.getId());
if (null == oldEntity || CommonUtils.empty(oldEntity.getUserId()) || null == user || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model) || ControllerUtils.verifyNotEquals("siteId", user.getId(), oldEntity.getUserId(), model)) {
return REDIRECT + returnUrl;
}
entity = service.update(entity.getId(), entity, ignoreProperties);
logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
} else {
entity.setSiteId(site.getId());
Long userId = null;
if (null != user) {
userId = user.getId();
entity.setUserId(user.getId());
}
service.save(entity);
logOperateService.save(new LogOperate(site.getId(), userId, LogLoginService.CHANNEL_WEB, "save.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
}
Map<String, String> map = ExtendUtils.getExtentDataMap(placeParamters.getExtendDataList(), metadataComponent.getPlaceMetadata(filePath).getExtendList());
String extentString = ExtendUtils.getExtendString(map);
attributeService.updateAttribute(entity.getId(), extentString);
}
return REDIRECT + returnUrl;
}
Aggregations