提交 5750044f authored 作者: inroi's avatar inroi

微调

上级 4e4d5225
...@@ -165,6 +165,23 @@ public class StarBosResult<T> implements Serializable { ...@@ -165,6 +165,23 @@ public class StarBosResult<T> implements Serializable {
log.error(starBosResult.toString()); log.error(starBosResult.toString());
return starBosResult; return starBosResult;
} }
public static Object badArgument() {
return fail(401, "参数不对");
}
public static Object badArgumentValue() {
return fail(402, "参数值不对");
}
public static Object updatedDateExpired() {
return fail(504, "更新数据已经失效");
}
public static Object updatedDataFailed() {
return fail(505, "更新数据失败");
}
public int getCode() { public int getCode() {
return code; return code;
} }
......
...@@ -4,15 +4,15 @@ import com.system.framework.core.response.StarBosResult; ...@@ -4,15 +4,15 @@ import com.system.framework.core.response.StarBosResult;
import com.system.oauth.system.entity.SysUserAccount; import com.system.oauth.system.entity.SysUserAccount;
import com.system.oauth.system.service.ISysRoleService; import com.system.oauth.system.service.ISysRoleService;
import com.system.oauth.system.service.ISysUserService; import com.system.oauth.system.service.ISysUserService;
import com.system.oauth.utils.JacksonUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
@Api(tags = "用户账号管理") @Api(tags = "用户账号管理")
...@@ -25,6 +25,8 @@ public class SysUserAccountController { ...@@ -25,6 +25,8 @@ public class SysUserAccountController {
private ISysRoleService roleService; private ISysRoleService roleService;
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired
private PasswordEncoder passwordEncoder;
@GetMapping("findRoleByUser") @GetMapping("findRoleByUser")
@ApiOperation(value = "userAccount-查询账号角色", notes = "userAccount-查询账号角色") @ApiOperation(value = "userAccount-查询账号角色", notes = "userAccount-查询账号角色")
...@@ -40,4 +42,39 @@ public class SysUserAccountController { ...@@ -40,4 +42,39 @@ public class SysUserAccountController {
} }
return result; return result;
} }
@PostMapping("reset_password")
public Object resetByMobile(@RequestBody String body, HttpServletRequest request) {
String password = JacksonUtil.parseString(body, "password");
String account = JacksonUtil.parseString(body, "account");
if (account == null || password == null) {
return StarBosResult.badArgument();
}
//判断验证码是否正确
// String cacheCode = CaptchaCodeManager.getCachedCaptcha(mobile);
// if (cacheCode == null || cacheCode.isEmpty() || !cacheCode.equals(code)) {
// return ResponseUtil.fail(AUTH_CAPTCHA_UNMATCH, "验证码错误");
// }
SysUserAccount accountUser = userService.findByUsername(account);
SysUserAccount user = null;
if (accountUser == null) {
return StarBosResult.fail(500, "账号不存在");
} else {
user = accountUser;
}
String encodedPassword = passwordEncoder.encode(password);
SysUserAccount sysUserAccount = new SysUserAccount();
sysUserAccount.setId(user.getId());
sysUserAccount.setPassword(encodedPassword);
if (!userService.updateById(sysUserAccount)) {
return StarBosResult.fail("数据更新失败");
}
return StarBosResult.ok();
}
} }
package com.system.oauth.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class JacksonUtil {
private static final Log logger = LogFactory.getLog(JacksonUtil.class);
public static String parseString(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return leaf.asText();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static List<String> parseStringList(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return mapper.convertValue(leaf, new TypeReference<List<String>>() {
});
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static Integer parseInteger(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return leaf.asInt();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static List<Integer> parseIntegerList(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() {
});
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static Boolean parseBoolean(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return leaf.asBoolean();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static Short parseShort(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null) {
Integer value = leaf.asInt();
return value.shortValue();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static Byte parseByte(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null) {
Integer value = leaf.asInt();
return value.byteValue();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static <T> T parseObject(String body, String field, Class<T> clazz) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node;
try {
node = mapper.readTree(body);
node = node.get(field);
return mapper.treeToValue(node, clazz);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static Object toNode(String json) {
if (json == null) {
return null;
}
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readTree(json);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static Map<String, String> toMap(String data) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.readValue(data, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static String toJson(Object data) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(data);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论