用户完成
This commit is contained in:
parent
e82de75e08
commit
c594f3e297
@ -2,7 +2,6 @@ package com.qiuguo.iot.user.api.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@ -11,8 +10,8 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
@ -50,27 +49,93 @@ public class UserController {
|
||||
@Value("${userUrl.registerUrl}")
|
||||
private String registerUrl;
|
||||
|
||||
@Value("${userUrl.changeUrl}")
|
||||
private String changeUrl;
|
||||
|
||||
@Value("${userUrl.userCancelUrl}")
|
||||
private String userCancelUrl;
|
||||
|
||||
/**
|
||||
* 设置登录密码-auth
|
||||
*/
|
||||
@Value("${userUrl.userInfoUrl}")
|
||||
private String userInfoUrl;
|
||||
|
||||
@Value("${userUrl.firstPasswordUrl}")
|
||||
private String firstPasswordUrl;
|
||||
|
||||
@Value("${userUrl.editUserInfoUrl}")
|
||||
private String editUserInfoUrl;
|
||||
|
||||
/**
|
||||
* 修改登录密码-auth
|
||||
*/
|
||||
@PostMapping("/change")
|
||||
public Mono<JSONObject> change(@RequestBody JSONObject jsonObject, @RequestHeader("Api-Token") String token,
|
||||
@RequestHeader("Api-Type") String type) {
|
||||
WebClient authWebClient = getAuthWebClient(token, type);
|
||||
return authWebClient.post().uri(baseUrl + changeUrl).bodyValue(getMultiValueMap(jsonObject)).retrieve()
|
||||
.bodyToMono(JSONObject.class).doOnNext(res -> {
|
||||
if (!Objects.equals(res.getInteger("code"), 1)) {
|
||||
throw new RuntimeException(res.getString("info"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号注销-auth
|
||||
*/
|
||||
|
||||
/**
|
||||
* 退出登录 -auth
|
||||
*/
|
||||
@PostMapping("/userCance")
|
||||
public Mono<JSONObject> userCance(@RequestBody JSONObject jsonObject, @RequestHeader("Api-Token") String token,
|
||||
@RequestHeader("Api-Type") String type) {
|
||||
return getAuthWebClient(token, type).post().uri(baseUrl + userCancelUrl).bodyValue(getMultiValueMap(jsonObject)).retrieve()
|
||||
.bodyToMono(JSONObject.class).doOnNext(res -> {
|
||||
if (!Objects.equals(res.getInteger("code"), 1)) {
|
||||
throw new RuntimeException(res.getString("info"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息-auth
|
||||
*/
|
||||
@PostMapping("/edit/userInfo")
|
||||
public Mono<JSONObject> editUserInfo(@RequestBody JSONObject jsonObject, @RequestHeader("Api-Token") String token,
|
||||
@RequestHeader("Api-Type") String type) {
|
||||
return WebClient.builder()
|
||||
.defaultHeader("Api-Token", token)
|
||||
.defaultHeader("Api-Type", type).build().post().uri(editUserInfoUrl).bodyValue(jsonObject).retrieve()
|
||||
.bodyToMono(JSONObject.class).doOnNext(res -> {
|
||||
if (!Objects.equals(res.getInteger("code"), 200)) {
|
||||
throw new RuntimeException(res.getString("msg"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人信息管理-auth
|
||||
*/
|
||||
@GetMapping("/userInfo")
|
||||
public Mono<JSONObject> getUserInfo(@RequestHeader("Api-Token") String token,
|
||||
@RequestHeader("Api-Type") String type) {
|
||||
return getAuthWebClient(token, type).get().uri(userInfoUrl).retrieve()
|
||||
.bodyToMono(JSONObject.class).doOnNext(res -> {
|
||||
if (!Objects.equals(res.getInteger("code"), 200)) {
|
||||
throw new RuntimeException(res.getString("msg"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否设置登录密码-auth
|
||||
*/
|
||||
@GetMapping("/first/password")
|
||||
public Mono<JSONObject> firstPassword(@RequestHeader("Api-Token") String token,
|
||||
@RequestHeader("Api-Type") String type) {
|
||||
return getAuthWebClient(token, type).get().uri(firstPasswordUrl).retrieve()
|
||||
.bodyToMono(JSONObject.class).doOnNext(res -> {
|
||||
if (!Objects.equals(res.getInteger("code"), 200)) {
|
||||
throw new RuntimeException(res.getString("msg"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -95,7 +160,6 @@ public class UserController {
|
||||
//登录
|
||||
return webClient.post().uri(baseUrl + smsUrl).bodyValue(getMultiValueMap(jsonObject))
|
||||
.retrieve().bodyToMono(JSONObject.class).flatMap(res -> {
|
||||
System.out.println("res = " + res);
|
||||
if (Objects.equals(res.getInteger("code"), 1) && !res.getString("info")
|
||||
.contains("该手机号还没有注册哦")) {
|
||||
return Mono.just(res);
|
||||
@ -111,7 +175,6 @@ public class UserController {
|
||||
register.add("pay_password", null);
|
||||
return webClient.post().uri(baseUrl + registerUrl).bodyValue(register).retrieve()
|
||||
.bodyToMono(JSONObject.class).flatMap(registerRes -> {
|
||||
System.out.println("registerRes = " + registerRes);
|
||||
if (!Objects.equals(registerRes.getInteger("code"), 1)) {
|
||||
return Mono.error(new RuntimeException(registerRes.getString("info")));
|
||||
} else {
|
||||
@ -152,5 +215,11 @@ public class UserController {
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
private WebClient getAuthWebClient(String token, String type) {
|
||||
return WebClient.builder()
|
||||
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.defaultHeader("Api-Token", token)
|
||||
.defaultHeader("Api-Type", type).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,4 +51,9 @@ userUrl:
|
||||
pwdUrl: '/data/api.login/in'
|
||||
smsUrl: '/data/api.login/phone'
|
||||
sendSmsUrl: '/data/api.login/sendsms'
|
||||
registerUrl: '/data/api.login/register'
|
||||
registerUrl: '/data/api.login/register'
|
||||
changeUrl: '/data/api.login/change'
|
||||
userCancelUrl: '/data/api.auth.center/userCancel'
|
||||
userInfoUrl: 'https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/box/userInfo'
|
||||
firstPasswordUrl: 'https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/box/first/password'
|
||||
editUserInfoUrl: 'https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/box/edit/userInfp'
|
||||
Loading…
x
Reference in New Issue
Block a user