|
@@ -0,0 +1,88 @@
|
|
|
+package com.galaxis.manatee.controller;
|
|
|
+
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
+import com.galaxis.manatee.entity.User;
|
|
|
+import com.galaxis.manatee.service.UserService;
|
|
|
+import com.galaxis.manatee.util.AliSmsUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zcj
|
|
|
+ * @version 0.1
|
|
|
+ * @date 2020/4/3 4:54 下午
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/user")
|
|
|
+public class UserController {
|
|
|
+
|
|
|
+ private UserService userService;
|
|
|
+ private BCryptPasswordEncoder bCryptPasswordEncoder;
|
|
|
+ private String confirmCode;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证人手机号
|
|
|
+ */
|
|
|
+ @Value(("${aliyun.access.mobile}"))
|
|
|
+ private String mobile;
|
|
|
+ /**
|
|
|
+ * 验证key的Id
|
|
|
+ */
|
|
|
+ @Value(("${aliyun.access.key.id}"))
|
|
|
+ private String accessKeyId;
|
|
|
+ /**
|
|
|
+ * 验证key的secret
|
|
|
+ */
|
|
|
+ @Value(("${aliyun.access.key.secret}"))
|
|
|
+ private String accessKeySecret;
|
|
|
+
|
|
|
+ public UserController(UserService userService, BCryptPasswordEncoder bCryptPasswordEncoder) {
|
|
|
+ this.userService = userService;
|
|
|
+ this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常处理
|
|
|
+ * @param exception 异常
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @ExceptionHandler
|
|
|
+ public ResponseEntity<String> exceptionHandler(Exception exception){
|
|
|
+ return new ResponseEntity<>(exception.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管理员认证
|
|
|
+ */
|
|
|
+ @GetMapping("/goConfirm")
|
|
|
+ public void mobileConfirm() throws ClientException {
|
|
|
+ Random random=new Random();
|
|
|
+ String s=String.valueOf(random.nextLong());
|
|
|
+ confirmCode=s.substring(s.length()-6);
|
|
|
+ log.info(confirmCode+"");
|
|
|
+ //发短信
|
|
|
+// AliSmsUtil.sendRegisterConfirmCode("18088233323",confirmCode,accessKeyId,accessKeySecret);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注册
|
|
|
+ * @param user 应用会员
|
|
|
+ * @return 注册结果
|
|
|
+ */
|
|
|
+ @PostMapping("/signUp")
|
|
|
+ public ResponseEntity<String> signUp(@RequestBody User user) {
|
|
|
+ if(user.getConfirmCode()==null||!user.getConfirmCode().equals(confirmCode)){
|
|
|
+ return new ResponseEntity<>("验证码信息错误", HttpStatus.NON_AUTHORITATIVE_INFORMATION);
|
|
|
+ }
|
|
|
+ user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
|
|
|
+ userService.signUp(user);
|
|
|
+ return new ResponseEntity<>(null, HttpStatus.OK);
|
|
|
+ }
|
|
|
+}
|