|
@@ -10,18 +10,25 @@ import cn.cslg.pas.domain.Project;
|
|
|
import cn.cslg.pas.domain.ProjectUser;
|
|
|
import cn.cslg.pas.domain.User;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.dev33.satoken.stp.SaLoginModel;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.captcha.CaptchaUtil;
|
|
|
import cn.hutool.captcha.CircleCaptcha;
|
|
|
import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import okhttp3.*;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -35,6 +42,9 @@ public class OAuth2Service {
|
|
|
private final RedisUtil redisUtil;
|
|
|
private final ProjectUserService projectUserService;
|
|
|
private final ProjectService projectService;
|
|
|
+ @Value("${authorUrl}")
|
|
|
+ private String url;
|
|
|
+ public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
|
public User getUserinfo() {
|
|
|
Integer userId = StpUtil.getLoginIdAsInt();
|
|
@@ -105,6 +115,60 @@ public class OAuth2Service {
|
|
|
return Response.success(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return 1.生成验证码的base64转码 2.生成的UUID 与Redis里面的验证码KEY值一致
|
|
|
+ * @author 沈永艺
|
|
|
+ */
|
|
|
+ public String verifyCode() throws Exception {
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
+ .build();
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(url+"/permission/api/admin/verifyCode")
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ String resBody = okHttpClient.newCall(request).execute().body().string();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(resBody);
|
|
|
+ JSONObject data = (JSONObject) jsonObject.get("data");
|
|
|
+ Object captcha =data.get("captcha");
|
|
|
+ Object uuid = data.get("uuid");
|
|
|
+ Object code = data.get("code");
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
+ result.put("captcha",captcha.toString());
|
|
|
+ result.put("uuid", uuid.toString());
|
|
|
+ result.put("code", code.toString());
|
|
|
+ //将验证码存放到Redis里面并设置
|
|
|
+ //过期时间为 60 单位:秒
|
|
|
+ //KEY值格式为: 验证码:UUID VALUE值为:验证码生成工具所生成的验证码
|
|
|
+ return Response.success(result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @return 登录成功的信息
|
|
|
+ * @author 沈永艺
|
|
|
+ */
|
|
|
+ public String login( String username,String password,String code,String uuid) throws IOException {
|
|
|
+ Map<String,Object> map =new HashMap<>();
|
|
|
+ map.put("code",code);
|
|
|
+ map.put("uuid",uuid);
|
|
|
+ map.put("username",username);
|
|
|
+ map.put("password",password);
|
|
|
+ JSONObject json =new JSONObject(map);
|
|
|
+ RequestBody a = RequestBody.create(JSON, String.valueOf(json));
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(url+"/permission/api/admin/login")
|
|
|
+ .post(a)
|
|
|
+ .build();
|
|
|
+ String resBody = okHttpClient.newCall(request).execute().body().string();
|
|
|
+ JSONObject jsonObject =JSONObject.parseObject(resBody);
|
|
|
+ String token =jsonObject.get("data").toString();
|
|
|
+
|
|
|
+
|
|
|
+ return Response.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
public String changePwd(String oldPassword, String newPassword) {
|
|
|
Integer userId = StpUtil.getLoginIdAsInt();
|
|
|
User user = userService.getById(userId);
|