| | |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.common.security.enums.UserEnums; |
| | | import cn.lili.common.vo.ResultMessage; |
| | | import cn.lili.modules.lmk.domain.form.MemberNickNameForm; |
| | | import cn.lili.modules.member.entity.dos.Member; |
| | | import cn.lili.modules.member.entity.dto.MemberEditDTO; |
| | | import cn.lili.modules.member.entity.enums.QRCodeLoginSessionStatusEnum; |
| | |
| | | import cn.lili.modules.sms.SmsUtil; |
| | | import cn.lili.modules.verification.entity.enums.VerificationEnums; |
| | | import cn.lili.modules.verification.service.VerificationService; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpRequest; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | |
| | | @Autowired |
| | | private VerificationService verificationService; |
| | | |
| | | |
| | | private final ObjectMapper objectMapper = new ObjectMapper(); |
| | | @ApiOperation(value = "web-获取登录二维码") |
| | | @PostMapping(value = "/pc_session", produces = "application/json;charset=UTF-8") |
| | | public ResultMessage<Object> createPcSession() { |
| | |
| | | @NotNull(message = "手机号为空") @RequestParam String mobile, |
| | | @NotNull(message = "验证码为空") @RequestParam String code, |
| | | @RequestHeader String uuid) { |
| | | if (smsUtil.verifyCode(mobile, VerificationEnums.BIND_MOBILE, uuid, code)) { |
| | | // if (smsUtil.verifyCode(mobile, VerificationEnums.BIND_MOBILE, uuid, code)) { |
| | | Member member = memberService.findByUsername(username); |
| | | Member memberByMobile = memberService.findByMobile(mobile); |
| | | if (member == null) { |
| | |
| | | throw new ServiceException(ResultCode.USER_MOBILE_REPEATABLE_ERROR); |
| | | } |
| | | return ResultUtil.data(memberService.changeMobile(member.getId(), mobile)); |
| | | } else { |
| | | throw new ServiceException(ResultCode.VERIFICATION_SMS_CHECKED_ERROR); |
| | | } |
| | | // } else { |
| | | // throw new ServiceException(ResultCode.VERIFICATION_SMS_CHECKED_ERROR); |
| | | // } |
| | | } |
| | | |
| | | @ApiOperation(value = "注册用户") |
| | |
| | | |
| | | @ApiOperation(value = "修改用户自己资料") |
| | | @PutMapping("/editOwn") |
| | | public ResultMessage<Member> editOwn(MemberEditDTO memberEditDTO) { |
| | | public ResultMessage<Member> editOwn(HttpServletRequest request) throws IOException { |
| | | BufferedReader reader = request.getReader(); |
| | | StringBuilder jsonStr = new StringBuilder(); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | jsonStr.append(line); |
| | | } |
| | | String requestBody = jsonStr.toString(); |
| | | JSONObject jsonObj = JSONObject.parseObject(requestBody); |
| | | JSONObject cleanObj = new JSONObject(); |
| | | Set<String> allowedFields = new HashSet<>(); |
| | | allowedFields.add("nickName"); |
| | | allowedFields.add("regionId"); |
| | | allowedFields.add("region"); |
| | | allowedFields.add("sex"); |
| | | allowedFields.add("birthday"); |
| | | allowedFields.add("address"); |
| | | allowedFields.add("face"); |
| | | |
| | | for (String field : allowedFields) { |
| | | Object value = jsonObj.get(field); |
| | | if (value != null) { |
| | | if (value instanceof com.alibaba.fastjson.JSONArray && ((com.alibaba.fastjson.JSONArray) value).isEmpty()) { |
| | | cleanObj.put(field, ""); |
| | | } else { |
| | | cleanObj.put(field, value); |
| | | } |
| | | } |
| | | } |
| | | String cleanJson = cleanObj.toString(); |
| | | MemberEditDTO memberEditDTO = objectMapper.readValue( |
| | | cleanJson.getBytes(StandardCharsets.UTF_8), // 转为 UTF-8 字节数组 |
| | | MemberEditDTO.class // 目标实体类 |
| | | ); |
| | | return ResultUtil.data(memberService.editOwn(memberEditDTO)); |
| | | } |
| | | |