diff --git a/.vscode/settings.json b/.vscode/settings.json index 92b7926..c7dbe17 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,14 +24,14 @@ "dbcode.connections": [ { "connectionId": "btr-_nFe7R0oOvCj0mMun", - "name": "ry", + "name": "ry-mysql", "driver": "mysql", "connectionType": "host", "host": "127.0.0.1", "port": 3306, "ssl": false, "username": "root", - "password": "", + "password": "123456", "savePassword": "secretStorage", "database": "ry", "connectionTimeout": 30, @@ -41,7 +41,7 @@ }, { "connectionId": "7NX2UhXl__9t3Ca6TzEsB", - "name": "ry", + "name": "ry-postgres", "driver": "postgres", "connectionType": "host", "host": "127.0.0.1", diff --git a/ruoyi-auth/ruoyi-auth-common/src/main/java/com/ruoyi/auth/common/service/TfaService.java b/ruoyi-auth/ruoyi-auth-common/src/main/java/com/ruoyi/auth/common/service/TfaService.java new file mode 100644 index 0000000..6722274 --- /dev/null +++ b/ruoyi-auth/ruoyi-auth-common/src/main/java/com/ruoyi/auth/common/service/TfaService.java @@ -0,0 +1,14 @@ +package com.ruoyi.auth.common.service; + +import com.ruoyi.common.core.domain.model.LoginBody; +import com.ruoyi.common.core.domain.model.RegisterBody; + +public interface TfaService { + public void doBind(LoginBody loginBody); + + public void doBindVerify(LoginBody loginBody); + + public void doRegister(RegisterBody registerBody); + + public void doRegisterVerify(RegisterBody registerBody); +} diff --git a/ruoyi-auth/ruoyi-auth-common/src/main/java/com/ruoyi/auth/common/controller/OauthUserController.java b/ruoyi-auth/ruoyi-auth-starter/src/main/java/com/ruoyi/auth/controller/OauthUserController.java similarity index 88% rename from ruoyi-auth/ruoyi-auth-common/src/main/java/com/ruoyi/auth/common/controller/OauthUserController.java rename to ruoyi-auth/ruoyi-auth-starter/src/main/java/com/ruoyi/auth/controller/OauthUserController.java index f482345..cefe56e 100644 --- a/ruoyi-auth/ruoyi-auth-common/src/main/java/com/ruoyi/auth/common/controller/OauthUserController.java +++ b/ruoyi-auth/ruoyi-auth-starter/src/main/java/com/ruoyi/auth/controller/OauthUserController.java @@ -1,4 +1,4 @@ -package com.ruoyi.auth.common.controller; +package com.ruoyi.auth.controller; import java.util.List; @@ -35,8 +35,7 @@ import jakarta.servlet.http.HttpServletResponse; @RestController @RequestMapping("/system/oauth") @Tag(name = "【第三方认证】管理") -public class OauthUserController extends BaseController -{ +public class OauthUserController extends BaseController { @Autowired private IOauthUserService oauthUserService; @@ -46,8 +45,7 @@ public class OauthUserController extends BaseController @Operation(summary = "查询第三方认证列表") @PreAuthorize("@ss.hasPermi('system:oauth:list')") @GetMapping("/list") - public TableDataInfo list(OauthUser oauthUser) - { + public TableDataInfo list(OauthUser oauthUser) { startPage(); List list = oauthUserService.selectOauthUserList(oauthUser); return getDataTable(list); @@ -60,8 +58,7 @@ public class OauthUserController extends BaseController @PreAuthorize("@ss.hasPermi('system:oauth:export')") @Log(title = "第三方认证", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, OauthUser oauthUser) - { + public void export(HttpServletResponse response, OauthUser oauthUser) { List list = oauthUserService.selectOauthUserList(oauthUser); ExcelUtil util = new ExcelUtil(OauthUser.class); util.exportExcel(response, list, "第三方认证数据"); @@ -73,8 +70,7 @@ public class OauthUserController extends BaseController @Operation(summary = "获取第三方认证详细信息") @PreAuthorize("@ss.hasPermi('system:oauth:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { + public AjaxResult getInfo(@PathVariable("id") Long id) { return success(oauthUserService.selectOauthUserById(id)); } @@ -85,8 +81,7 @@ public class OauthUserController extends BaseController @PreAuthorize("@ss.hasPermi('system:oauth:add')") @Log(title = "第三方认证", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody OauthUser oauthUser) - { + public AjaxResult add(@RequestBody OauthUser oauthUser) { return toAjax(oauthUserService.insertOauthUser(oauthUser)); } @@ -97,8 +92,7 @@ public class OauthUserController extends BaseController @PreAuthorize("@ss.hasPermi('system:oauth:edit')") @Log(title = "第三方认证", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody OauthUser oauthUser) - { + public AjaxResult edit(@RequestBody OauthUser oauthUser) { return toAjax(oauthUserService.updateOauthUser(oauthUser)); } @@ -108,9 +102,8 @@ public class OauthUserController extends BaseController @Operation(summary = "删除第三方认证") @PreAuthorize("@ss.hasPermi('system:oauth:remove')") @Log(title = "第三方认证", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable(name = "ids") Long[] ids) { return toAjax(oauthUserService.deleteOauthUserByIds(ids)); } } diff --git a/ruoyi-auth/ruoyi-auth-starter/src/main/java/com/ruoyi/auth/controller/TfaController.java b/ruoyi-auth/ruoyi-auth-starter/src/main/java/com/ruoyi/auth/controller/TfaController.java new file mode 100644 index 0000000..c21d5d3 --- /dev/null +++ b/ruoyi-auth/ruoyi-auth-starter/src/main/java/com/ruoyi/auth/controller/TfaController.java @@ -0,0 +1,55 @@ +package com.ruoyi.auth.controller; + +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.ruoyi.auth.common.service.TfaService; +import com.ruoyi.common.annotation.Anonymous; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.model.LoginBody; +import com.ruoyi.common.core.domain.model.RegisterBody; + +@RestController +@RequestMapping("/auth/") // dySms mail +public class TfaController extends BaseController { + + @Autowired + Map tfaServiceMap; + + @PostMapping("/send/bind") + public AjaxResult send(@PathVariable String channel, @RequestBody LoginBody loginBody) { + TfaService tfaService = tfaServiceMap.get(channel + "AuthService"); + tfaService.doBind(loginBody); + return success(); + } + + @PostMapping("/verify/bind") // 发送验证码 + public AjaxResult verify(@PathVariable String channel, @RequestBody LoginBody loginBody) { + TfaService tfaService = tfaServiceMap.get(channel + "AuthService"); + tfaService.doBindVerify(loginBody); + return success(); + } + + @PostMapping("/send/register") + @Anonymous + public AjaxResult sendRegister(@PathVariable String channel, @RequestBody RegisterBody registerBody) { + TfaService tfaService = tfaServiceMap.get(channel + "AuthService"); + tfaService.doRegister(registerBody); + return success(); + } + + @PostMapping("/verify/register") + @Anonymous + public AjaxResult verifyRegister(@PathVariable String channel, @RequestBody RegisterBody registerBody) { + TfaService tfaService = tfaServiceMap.get(channel + "AuthService"); + tfaService.doRegisterVerify(registerBody); + return success(); + } +} diff --git a/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/controller/SysAuthController.java b/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/controller/SysAuthController.java index 8652222..2673ea8 100644 --- a/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/controller/SysAuthController.java +++ b/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/controller/SysAuthController.java @@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.auth.common.domain.OauthUser; +import com.ruoyi.auth.common.service.IOauthUserService; import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.controller.BaseController; @@ -25,9 +27,7 @@ import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.web.service.SysPermissionService; import com.ruoyi.framework.web.service.TokenService; -import com.ruoyi.auth.common.domain.OauthUser; -import com.ruoyi.auth.common.service.IOauthUserService; -import com.ruoyi.oauth.justauth.utils.AuthUtils; +import com.ruoyi.oauth.justauth.utils.JustAuthUtils; import com.ruoyi.system.service.ISysUserService; import jakarta.servlet.http.HttpServletRequest; @@ -91,7 +91,7 @@ public class SysAuthController extends BaseController return error(source + "平台账号暂不支持"); } JSONObject json = JSONObject.parseObject(obj); - AuthRequest authRequest = AuthUtils.getAuthRequest(source, json.getString("clientId"), json.getString("clientSecret"), json.getString("redirectUri"), authStateCache); + AuthRequest authRequest = JustAuthUtils.getAuthRequest(source, json.getString("clientId"), json.getString("clientSecret"), json.getString("redirectUri"), authStateCache); String authorizeUrl = authRequest.authorize(AuthStateUtils.createState()); return success(authorizeUrl); } @@ -114,7 +114,7 @@ public class SysAuthController extends BaseController return AjaxResult.error(10002, "第三方平台系统不支持或未提供来源"); } JSONObject json = JSONObject.parseObject(obj); - AuthRequest authRequest = AuthUtils.getAuthRequest(source, json.getString("clientId"), json.getString("clientSecret"), json.getString("redirectUri"), authStateCache); + AuthRequest authRequest = JustAuthUtils.getAuthRequest(source, json.getString("clientId"), json.getString("clientSecret"), json.getString("redirectUri"), authStateCache); AuthResponse response = authRequest.login(callback); if (response.ok()) { diff --git a/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/utils/AuthUtils.java b/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/utils/JustAuthUtils.java similarity index 99% rename from ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/utils/AuthUtils.java rename to ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/utils/JustAuthUtils.java index 69799bf..a421ad6 100644 --- a/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/utils/AuthUtils.java +++ b/ruoyi-auth/ruoyi-oauth-justauth/src/main/java/com/ruoyi/oauth/justauth/utils/JustAuthUtils.java @@ -38,7 +38,7 @@ import me.zhyd.oauth.request.AuthWeiboRequest; * * @author ruoyi */ -public class AuthUtils +public class JustAuthUtils { @SuppressWarnings("deprecation") public static AuthRequest getAuthRequest(String source, String clientId, String clientSecret, String redirectUri, diff --git a/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/controller/MailAuthController.java b/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/controller/MailAuthController.java deleted file mode 100644 index b50577b..0000000 --- a/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/controller/MailAuthController.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.ruoyi.tfa.email.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.ruoyi.common.annotation.Anonymous; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.domain.model.LoginBody; -import com.ruoyi.common.core.domain.model.RegisterBody; -import com.ruoyi.tfa.email.service.impl.MailServiceImpl; - -@RestController -@RequestMapping("/auth/mail") -public class MailAuthController extends BaseController { - - @Autowired - MailServiceImpl serviceImpl; - - @PostMapping("/send/bind") // 发送验证码 - public AjaxResult send(@RequestBody LoginBody loginBody) { - serviceImpl.doBind(loginBody); - return success(); - } - - @PostMapping("/verify/bind") // 发送验证码 - public AjaxResult verify(@RequestBody LoginBody loginBody) { - serviceImpl.doBindVerify(loginBody); - return success(); - } - - @PostMapping("/send/register") - @Anonymous - public AjaxResult sendRegister(@RequestBody RegisterBody registerBody) { - serviceImpl.doRegister(registerBody); - return success(); - } - - @PostMapping("/verify/register") - @Anonymous - public AjaxResult verifyRegister(@RequestBody RegisterBody registerBody) { - serviceImpl.doRegisterVerify(registerBody); - return success(); - } -} diff --git a/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/IMailService.java b/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/IMailService.java index 7fed0bf..3660a62 100644 --- a/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/IMailService.java +++ b/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/IMailService.java @@ -1,6 +1,7 @@ package com.ruoyi.tfa.email.service; import com.ruoyi.auth.common.service.OauthVerificationCodeService; +import com.ruoyi.auth.common.service.TfaService; -public interface IMailService extends OauthVerificationCodeService { +public interface IMailService extends OauthVerificationCodeService,TfaService { } diff --git a/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/impl/MailServiceImpl.java b/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/impl/MailServiceImpl.java index 5b8a0a6..bc22f76 100644 --- a/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/impl/MailServiceImpl.java +++ b/ruoyi-auth/ruoyi-tfa-email/src/main/java/com/ruoyi/tfa/email/service/impl/MailServiceImpl.java @@ -24,7 +24,7 @@ import com.ruoyi.system.service.ISysUserService; import com.ruoyi.tfa.email.service.IMailService; import com.ruoyi.tfa.email.utils.EmailUtil; -@Service +@Service("mailAuthService") public class MailServiceImpl implements IMailService { @Autowired diff --git a/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/controller/DySmsAuthController.java b/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/controller/DySmsAuthController.java deleted file mode 100644 index 1134693..0000000 --- a/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/controller/DySmsAuthController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.ruoyi.tfa.phone.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.ruoyi.common.annotation.Anonymous; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.domain.model.LoginBody; -import com.ruoyi.common.core.domain.model.RegisterBody; -import com.ruoyi.tfa.phone.service.Impl.DySmsServiceImpl; - -/** - * 手机号认证Controller - * - * @author zlh - * @date 2024-04-16 - */ -@RestController -@RequestMapping("/auth/phone") -public class DySmsAuthController extends BaseController { - @Autowired - public DySmsServiceImpl dySmsService; - - @PostMapping("/send/bind") // 发送验证码 - public AjaxResult send(@RequestBody LoginBody loginBody) { - dySmsService.doBind(loginBody); - return success(); - } - - @PostMapping("/verify/bind") // 发送验证码 - public AjaxResult verify(@RequestBody LoginBody loginBody) { - dySmsService.doBindVerify(loginBody); - return success(); - } - - @PostMapping("/send/register") - @Anonymous - public AjaxResult sendRegister(@RequestBody RegisterBody registerBody) { - dySmsService.doRegister(registerBody); - return success(); - } - - @PostMapping("/verify/register") - @Anonymous - public AjaxResult verifyRegister(@RequestBody RegisterBody registerBody) { - dySmsService.doRegisterVerify(registerBody); - return success(); - } -} diff --git a/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/DySmsService.java b/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/DySmsService.java index 27d58da..cbcf930 100644 --- a/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/DySmsService.java +++ b/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/DySmsService.java @@ -1,6 +1,7 @@ package com.ruoyi.tfa.phone.service; import com.ruoyi.auth.common.service.OauthVerificationCodeService; +import com.ruoyi.auth.common.service.TfaService; /** * 手机号认证Servcie @@ -8,6 +9,6 @@ import com.ruoyi.auth.common.service.OauthVerificationCodeService; * @author zlh * @date 2024-04-16 */ -public interface DySmsService extends OauthVerificationCodeService { +public interface DySmsService extends OauthVerificationCodeService, TfaService { } diff --git a/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/Impl/DySmsServiceImpl.java b/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/Impl/DySmsServiceImpl.java index 720bd27..d3e4d28 100644 --- a/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/Impl/DySmsServiceImpl.java +++ b/ruoyi-auth/ruoyi-tfa-phone/src/main/java/com/ruoyi/tfa/phone/service/Impl/DySmsServiceImpl.java @@ -32,7 +32,7 @@ import com.ruoyi.tfa.phone.utils.DySmsUtil; * @author zlh * @date 2024-04-16 */ -@Service +@Service("dySmsAuthService") public class DySmsServiceImpl implements DySmsService { @Autowired @@ -114,14 +114,14 @@ public class DySmsServiceImpl implements DySmsService { } } - public boolean doRegisterVerify(RegisterBody registerBody) { + public void doRegisterVerify(RegisterBody registerBody) { if (checkCode(registerBody.getPhonenumber(), registerBody.getCode(), OauthVerificationUse.REGISTER)) { SysUser sysUser = new SysUser(); sysUser.setUserName(registerBody.getPhonenumber()); sysUser.setNickName(registerBody.getUsername()); sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword())); sysUser.setPhonenumber(registerBody.getPhonenumber()); - return userService.registerUser(sysUser); + userService.registerUser(sysUser); } else { throw new ServiceException("验证码错误"); } @@ -158,14 +158,14 @@ public class DySmsServiceImpl implements DySmsService { sendCode(loginBody.getPhonenumber(), RandomCodeUtil.numberCode(6), OauthVerificationUse.BIND); } - public int doBindVerify(LoginBody loginBody) { + public void doBindVerify(LoginBody loginBody) { if (checkCode(loginBody.getPhonenumber(), loginBody.getCode(), OauthVerificationUse.BIND)) { SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId()); if (!SecurityUtils.matchesPassword(loginBody.getPassword(), sysUser.getPassword())) { throw new ServiceException("密码错误"); } sysUser.setPhonenumber(loginBody.getPhonenumber()); - return userService.updateUser(sysUser); + userService.updateUser(sysUser); } else { throw new ServiceException("验证码错误"); }