From f9f49446f1ca0476398a697ee938830646f07cfc Mon Sep 17 00:00:00 2001 From: MaxKey Date: Mon, 16 Oct 2023 14:03:31 +0800 Subject: [PATCH] =?UTF-8?q?openapi=20=E5=8D=95=E7=8B=AC=E5=88=86=E7=A6=BB?= =?UTF-8?q?=E5=87=BA=E5=AF=86=E7=A0=81=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/RestUserPasswordController.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 maxkey-web-apis/maxkey-web-api-rest/src/main/java/org/dromara/maxkey/web/apis/identity/rest/RestUserPasswordController.java diff --git a/maxkey-web-apis/maxkey-web-api-rest/src/main/java/org/dromara/maxkey/web/apis/identity/rest/RestUserPasswordController.java b/maxkey-web-apis/maxkey-web-api-rest/src/main/java/org/dromara/maxkey/web/apis/identity/rest/RestUserPasswordController.java new file mode 100644 index 000000000..cdd72b5e4 --- /dev/null +++ b/maxkey-web-apis/maxkey-web-api-rest/src/main/java/org/dromara/maxkey/web/apis/identity/rest/RestUserPasswordController.java @@ -0,0 +1,65 @@ +/* + * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.dromara.maxkey.web.apis.identity.rest; + +import java.io.IOException; + +import org.dromara.maxkey.entity.ChangePassword; +import org.dromara.maxkey.entity.UserInfo; +import org.dromara.maxkey.persistence.service.UserInfoService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.util.UriComponentsBuilder; + +@Controller +@RequestMapping(value={"/api/idm/Users"}) +public class RestUserPasswordController { + + static final Logger _logger = LoggerFactory.getLogger(RestUserPasswordController.class); + + @Autowired + @Qualifier("userInfoService") + private UserInfoService userInfoService; + + + @PostMapping(value = "/changePassword") + @ResponseBody + public String changePassword(@RequestParam(required = true) String username, + @RequestParam(required = true) String password, + UriComponentsBuilder builder) throws IOException { + + _logger.debug("UserInfo username {} , password {}", username , password); + + UserInfo loadUserInfo = userInfoService.findByUsername(username); + if(loadUserInfo != null) { + ChangePassword changePassword = new ChangePassword(loadUserInfo); + changePassword.setPassword(password); + changePassword.setDecipherable(loadUserInfo.getDecipherable()); + userInfoService.changePassword(changePassword,true); + } + return "true"; + } + +}