|
@@ -47,6 +47,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -215,27 +216,28 @@ public class UserApiController {
|
|
public BaseResponse<Object> login(String name,String pass) throws Exception {
|
|
public BaseResponse<Object> login(String name,String pass) throws Exception {
|
|
// String dataStr = passwordEncoder.encode(pass);
|
|
// String dataStr = passwordEncoder.encode(pass);
|
|
User user = userRepository.findByUsername(name);
|
|
User user = userRepository.findByUsername(name);
|
|
-
|
|
|
|
- Map<String,String> path = this.localStorageService.findByRealName(user.getAvatarName());
|
|
|
|
- user.setAvatarName(path.get("url"));
|
|
|
|
- if (user != null){
|
|
|
|
- boolean bo = passwordEncoder.matches(pass,user.getPassword());
|
|
|
|
- if (bo){
|
|
|
|
- Map<String,Object> newToken = SecurityUtils.getToken(key);
|
|
|
|
- //组装返回值
|
|
|
|
- JSONObject returnData = new JSONObject();
|
|
|
|
- returnData.put("nonce",newToken.get("nonce"));
|
|
|
|
- returnData.put("timestamp",newToken.get("timestamp"));
|
|
|
|
- returnData.put("token",newToken.get("token"));
|
|
|
|
- returnData.put("userId",user.getId());
|
|
|
|
- String cipher = EncryptUtils.desEncrypt(returnData.toJSONString());
|
|
|
|
- returnData.put("cipher", cipher);
|
|
|
|
- returnData.put("user", user);
|
|
|
|
- Map<String, Object> authInfo = new HashMap<String, Object>(1) {{
|
|
|
|
- put("data", returnData);
|
|
|
|
- }};
|
|
|
|
- System.out.println("returnData:"+returnData.toJSONString());
|
|
|
|
- return new BaseResponse<>(authInfo);
|
|
|
|
|
|
+ if(!ObjectUtils.isEmpty(user)) {
|
|
|
|
+ Map<String, String> path = this.localStorageService.findByRealName(user.getAvatarName());
|
|
|
|
+ user.setAvatarName(path.get("url"));
|
|
|
|
+ if (user != null) {
|
|
|
|
+ boolean bo = passwordEncoder.matches(pass, user.getPassword());
|
|
|
|
+ if (bo) {
|
|
|
|
+ Map<String, Object> newToken = SecurityUtils.getToken(key);
|
|
|
|
+ //组装返回值
|
|
|
|
+ JSONObject returnData = new JSONObject();
|
|
|
|
+ returnData.put("nonce", newToken.get("nonce"));
|
|
|
|
+ returnData.put("timestamp", newToken.get("timestamp"));
|
|
|
|
+ returnData.put("token", newToken.get("token"));
|
|
|
|
+ returnData.put("userId", user.getId());
|
|
|
|
+ String cipher = EncryptUtils.desEncrypt(returnData.toJSONString());
|
|
|
|
+ returnData.put("cipher", cipher);
|
|
|
|
+ returnData.put("user", user);
|
|
|
|
+ Map<String, Object> authInfo = new HashMap<String, Object>(1) {{
|
|
|
|
+ put("data", returnData);
|
|
|
|
+ }};
|
|
|
|
+ System.out.println("returnData:" + returnData.toJSONString());
|
|
|
|
+ return new BaseResponse<>(authInfo);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw new BadRequestException("登录失败!");
|
|
throw new BadRequestException("登录失败!");
|