mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 04:22:08 +08:00
Update RestTimeBasedOtpController.java
This commit is contained in:
@@ -17,20 +17,22 @@
|
|||||||
|
|
||||||
package org.dromara.maxkey.web.api.endpoint;
|
package org.dromara.maxkey.web.api.endpoint;
|
||||||
|
|
||||||
|
import org.dromara.maxkey.entity.Message;
|
||||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
@Tag(name = "基于时间令牌验证 API文档模块")
|
@Tag(name = "基于时间令牌验证 API文档模块")
|
||||||
@Controller
|
@RestController
|
||||||
@RequestMapping(value={"/api/otp"})
|
@RequestMapping(value={"/api/otp"})
|
||||||
public class RestTimeBasedOtpController {
|
public class RestTimeBasedOtpController {
|
||||||
|
|
||||||
@@ -42,18 +44,15 @@ public class RestTimeBasedOtpController {
|
|||||||
|
|
||||||
@Operation(summary = "基于时间令牌验证 API文档模块", description = "传递参数username和token",method="GET")
|
@Operation(summary = "基于时间令牌验证 API文档模块", description = "传递参数username和token",method="GET")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping(value = "/timebased/validate", method = RequestMethod.GET)
|
@GetMapping("/timebased/validate")
|
||||||
public boolean getUser(@RequestParam String username,
|
public Message<Boolean> getUser(@RequestParam String username,
|
||||||
@RequestParam String token) {
|
@RequestParam String token) {
|
||||||
|
boolean isValidate = false;
|
||||||
UserInfo validUserInfo = userInfoService.findByUsername(username);
|
UserInfo validUserInfo = userInfoService.findByUsername(username);
|
||||||
if(validUserInfo != null) {
|
if(validUserInfo != null &&timeBasedOtpAuthn.validate(validUserInfo, token)) {
|
||||||
if(timeBasedOtpAuthn.validate(validUserInfo, token)) {
|
isValidate = true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return new Message<>(isValidate);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user