use of io.jpom.common.interceptor.NotLogin in project Jpom by dromara.
the class IndexControl method checkSystem.
/**
* @return json
* @author Hotstrip
* <p>
* check if need to init system
* @api {get} check-system 检查是否需要初始化系统
* @apiGroup index
* @apiUse defResultJson
* @apiSuccess {String} routerBase 二级地址
* @apiSuccess {String} name 系统名称
* @apiSuccess {String} subTitle 主页面副标题
* @apiSuccess {String} loginTitle 登录也标题
* @apiSuccess {String} disabledGuide 是否禁用引导
* @apiSuccess (222) {Object} data 系统还没有超级管理员需要初始化
*/
@NotLogin
@RequestMapping(value = "check-system", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String checkSystem() {
JSONObject data = new JSONObject();
data.put("routerBase", UrlRedirectUtil.getHeaderProxyPath(getRequest(), BaseJpomInterceptor.PROXY_PATH));
//
ServerExtConfigBean instance = ServerExtConfigBean.getInstance();
data.put("name", instance.getName());
data.put("subTitle", instance.getSubTitle());
data.put("loginTitle", instance.getLoginTitle());
data.put("disabledGuide", instance.getDisabledGuide());
if (userService.canUse()) {
return JsonMessage.getString(200, "success", data);
}
return JsonMessage.getString(222, "需要初始化系统", data);
}
use of io.jpom.common.interceptor.NotLogin in project Jpom by dromara.
the class IndexControl method logoImage.
/**
* logo 图片
*
* @api {get} logo_image logo 图片
* @apiGroup index
* @apiSuccess {Object} BODY image
*/
@RequestMapping(value = "logo_image", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@NotLogin
public void logoImage(HttpServletResponse response) throws IOException {
ServerExtConfigBean instance = ServerExtConfigBean.getInstance();
String logoFile = instance.getLogoFile();
if (StrUtil.isNotEmpty(logoFile)) {
if (Validator.isMatchRegex(RegexPool.URL_HTTP, logoFile)) {
// 重定向
response.sendRedirect(logoFile);
return;
}
File file = FileUtil.file(logoFile);
if (FileUtil.isFile(file)) {
String type = FileTypeUtil.getType(file);
if (StrUtil.equalsAnyIgnoreCase(type, "jpg", "png", "gif")) {
ServletUtil.write(response, file);
return;
}
}
}
// 默认logo
InputStream inputStream = ResourceUtil.getStream("classpath:/logo/jpom.png");
ServletUtil.write(response, inputStream, MediaType.IMAGE_PNG_VALUE);
}
use of io.jpom.common.interceptor.NotLogin in project Jpom by dromara.
the class LoginControl method randCode.
/**
* 验证码
*
* @throws IOException IO
*/
@RequestMapping(value = "randCode.png", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@NotLogin
public void randCode() throws IOException {
int height = 50;
CircleCaptcha circleCaptcha = new CircleCaptcha(100, height, 4, 8);
// 设置为默认字体
circleCaptcha.setFont(new Font(null, Font.PLAIN, (int) (height * 0.75)));
circleCaptcha.createCode();
HttpServletResponse response = getResponse();
circleCaptcha.write(response.getOutputStream());
String code = circleCaptcha.getCode();
setSessionAttribute(LOGIN_CODE, code);
}
use of io.jpom.common.interceptor.NotLogin in project Jpom by dromara.
the class LoginControl method userLogin.
/**
* 登录接口
*
* @param userName 登录名
* @param userPwd 登录密码
* @param code 验证码
* @return json
*/
@PostMapping(value = "userLogin", produces = MediaType.APPLICATION_JSON_VALUE)
@NotLogin
@Feature(method = MethodFeature.EXECUTE, resultCode = { 200, 201 }, logResponse = false)
public String userLogin(@ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "请输入登录信息") }) String userName, @ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "请输入登录信息") }) String userPwd, String code) {
if (this.ipLock()) {
return JsonMessage.getString(400, "尝试次数太多,请稍后再来");
}
synchronized (userName.intern()) {
UserModel userModel = userService.getByKey(userName);
if (userModel == null) {
this.ipError();
return JsonMessage.getString(400, "登录失败,请输入正确的密码和账号,多次失败将锁定账号");
}
// 获取验证码
String sCode = getSessionAttribute(LOGIN_CODE);
Assert.state(StrUtil.equalsIgnoreCase(code, sCode), "请输入正确的验证码");
removeSessionAttribute(LOGIN_CODE);
UserModel updateModel = null;
try {
long lockTime = userModel.overLockTime();
if (lockTime > 0) {
String msg = DateUtil.formatBetween(lockTime * 1000, BetweenFormatter.Level.SECOND);
updateModel = userModel.errorLock();
this.ipError();
return JsonMessage.getString(400, "该账户登录失败次数过多,已被锁定" + msg + ",请不要再次尝试");
}
// 验证
if (userService.simpleLogin(userName, userPwd) != null) {
updateModel = UserModel.unLock(userName);
this.ipSuccess();
// 判断是否开启 两步验证
boolean bindMfa = userService.hasBindMfa(userName);
if (bindMfa) {
//
JSONObject jsonObject = new JSONObject();
String uuid = IdUtil.fastSimpleUUID();
MFA_TOKEN.put(uuid, userName);
jsonObject.put("tempToken", uuid);
return JsonMessage.getString(201, "请输入两步验证码", jsonObject);
}
UserLoginDto userLoginDto = this.createToken(userModel);
return JsonMessage.getString(200, "登录成功", userLoginDto);
} else {
updateModel = userModel.errorLock();
this.ipError();
return JsonMessage.getString(501, "登录失败,请输入正确的密码和账号,多次失败将锁定账号");
}
} finally {
if (updateModel != null) {
userService.update(updateModel);
}
// 用于记录登录日志
BaseServerController.resetInfo(userModel);
}
}
}
use of io.jpom.common.interceptor.NotLogin in project Jpom by dromara.
the class LoginControl method demoInfo.
/**
* 获取 demo 账号的信息
*/
@GetMapping(value = "user_demo_info", produces = MediaType.APPLICATION_JSON_VALUE)
@NotLogin
public String demoInfo() {
String userDemoTip = ServerExtConfigBean.getInstance().getUserDemoTip();
userDemoTip = StringUtil.convertFileStr(userDemoTip, StrUtil.EMPTY);
if (StrUtil.isEmpty(userDemoTip) || !userService.hasDemoUser()) {
return JsonMessage.getString(200, "");
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("user", UserModel.DEMO_USER);
return JsonMessage.getString(200, userDemoTip, jsonObject);
}
Aggregations