use of com.publiccms.entities.sys.SysAppToken in project PublicCMS-preview by sanluan.
the class AppTokenDirective method execute.
@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
SysApp entity = appService.getEntity(handler.getString("appKey"));
if (null != entity) {
if (entity.getAppSecret().equalsIgnoreCase(handler.getString("appSecret"))) {
SysAppToken token = new SysAppToken(UUID.randomUUID().toString(), entity.getId(), CommonUtils.getDate());
appTokenService.save(token);
handler.put("appToken", token.getAuthToken());
} else {
handler.put("error", SECRET_ERROR);
}
} else {
handler.put("error", KEY_NOT_EXISTS);
}
}
use of com.publiccms.entities.sys.SysAppToken in project PublicCMS-preview by sanluan.
the class SysAppTokenAdminController method delete.
/**
* @param authToken
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("delete")
public String delete(String authToken, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
SysAppToken entity = service.getEntity(authToken);
Long userId = getAdminFromSession(session).getId();
if (null != entity) {
SysApp app = appService.getEntity(entity.getAppId());
if (null != app) {
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), app.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
service.delete(authToken);
logOperateService.save(new LogOperate(site.getId(), userId, LogLoginService.CHANNEL_WEB_MANAGER, "delete.apptoken", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysAppToken in project PublicCMS-preview by sanluan.
the class MethodController method method.
/**
* 接口指令统一分发
*
* @param name
* @param appToken
* @param request
* @param response
* @return result
*/
@RequestMapping("method/{name}")
public Object method(@PathVariable String name, String appToken, HttpServletRequest request, HttpServletResponse response) {
BaseMethod method = methodMap.get(name);
if (null != method) {
try {
if (method.needAppToken()) {
SysAppToken token = appTokenService.getEntity(appToken);
if (null == token) {
return NEED_APP_TOKEN_MAP;
}
SysApp app = appService.getEntity(token.getAppId());
if (null == app) {
return NEED_APP_TOKEN_MAP;
}
}
Map<String, Object> map = new HashMap<>();
String[] paramters = request.getParameterValues("paramters");
if (CommonUtils.notEmpty(paramters) && paramters.length >= method.minParamtersNumber()) {
List<TemplateModel> list = new ArrayList<>();
for (String paramter : paramters) {
list.add(getObjectWrapper().wrap(paramter));
}
map.put("result", method.exec(list));
return map;
} else if (CommonUtils.empty(paramters) && 0 == method.minParamtersNumber()) {
map.put("result", method.exec(null));
return map;
} else {
map.put(ERROR, "paramtersError");
return map;
}
} catch (TemplateModelException e) {
log.error(e.getMessage(), e);
Map<String, String> map = new HashMap<>();
map.put(ERROR, ApiController.EXCEPTION);
return map;
}
} else {
return ApiController.NOT_FOUND_MAP;
}
}
Aggregations