diff --git a/CHANGELOG.md b/CHANGELOG.md index f6547ed..e6129e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.2.2 +* 更新API接口 + ## 1.2.1 * 修复微信登录调整错误 diff --git a/Controllers/AuthController.GetRedirect.cs b/Controllers/AuthController.GetRedirect.cs index c490882..f0e794d 100644 --- a/Controllers/AuthController.GetRedirect.cs +++ b/Controllers/AuthController.GetRedirect.cs @@ -18,6 +18,7 @@ public async Task> GetRedirect([FromRoute] strin { var host = ApiUtils.GetHost(Request); var oAuthType = OAuthType.Parse(type); + var config = await _configRepository.GetAsync(); var userName = string.Empty; @@ -40,7 +41,7 @@ public async Task> GetRedirect([FromRoute] strin AvatarUrl = userInfo.HeadImgUrl }; - var (newUser, _) = await _userRepository.InsertAsync(user, Guid.NewGuid().ToString(), PageUtils.GetIpAddress(Request)); + var (newUser, _) = await _userRepository.InsertAsync(user, Guid.NewGuid().ToString(), config.IsUserRegistrationChecked, PageUtils.GetIpAddress(Request)); userName = newUser.UserName; await _oAuthRepository.InsertAsync(new OAuth @@ -70,7 +71,7 @@ await _oAuthRepository.InsertAsync(new OAuth AvatarUrl = userInfo.AvatarUrl }; - var (newUser, _) = await _userRepository.InsertAsync(user, Guid.NewGuid().ToString(), PageUtils.GetIpAddress(Request)); + var (newUser, _) = await _userRepository.InsertAsync(user, Guid.NewGuid().ToString(), config.IsUserRegistrationChecked, PageUtils.GetIpAddress(Request)); userName = newUser.UserName; await _oAuthRepository.InsertAsync(new OAuth @@ -91,14 +92,16 @@ await _oAuthRepository.InsertAsync(new OAuth userName = await _oAuthRepository.GetUserNameAsync(OAuthType.Weibo.Value, userInfo.UnionId); if (string.IsNullOrEmpty(userName)) { - var user = new User(); - user.UserName = await _userRepository.IsUserNameExistsAsync(userInfo.Name) + var user = new User + { + UserName = await _userRepository.IsUserNameExistsAsync(userInfo.Name) ? Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", "") - : userInfo.Name; - user.DisplayName = userInfo.ScreenName; - user.AvatarUrl = userInfo.AvatarLarge; + : userInfo.Name, + DisplayName = userInfo.ScreenName, + AvatarUrl = userInfo.AvatarLarge + }; - var (newUser, _) = await _userRepository.InsertAsync(user, Guid.NewGuid().ToString(), PageUtils.GetIpAddress(Request)); + var (newUser, _) = await _userRepository.InsertAsync(user, Guid.NewGuid().ToString(), config.IsUserRegistrationChecked, PageUtils.GetIpAddress(Request)); userName = newUser.UserName; await _oAuthRepository.InsertAsync(new OAuth diff --git a/Controllers/AuthController.cs b/Controllers/AuthController.cs index dbb764f..80952cd 100644 --- a/Controllers/AuthController.cs +++ b/Controllers/AuthController.cs @@ -12,13 +12,15 @@ public partial class AuthController : ControllerBase private const string RouteRedirect = "{type}/redirect"; private readonly IAuthManager _authManager; + private readonly IConfigRepository _configRepository; private readonly IUserRepository _userRepository; private readonly IOAuthRepository _oAuthRepository; private readonly ILoginManager _loginManager; - public AuthController(IAuthManager authManager, IUserRepository userRepository, IOAuthRepository oAuthRepository, ILoginManager loginManager) + public AuthController(IAuthManager authManager, IConfigRepository configRepository, IUserRepository userRepository, IOAuthRepository oAuthRepository, ILoginManager loginManager) { _authManager = authManager; + _configRepository = configRepository; _userRepository = userRepository; _oAuthRepository = oAuthRepository; _loginManager = loginManager; diff --git a/Controllers/IndexController.Register.cs b/Controllers/IndexController.Register.cs index 4fefb59..8f80e58 100644 --- a/Controllers/IndexController.Register.cs +++ b/Controllers/IndexController.Register.cs @@ -19,8 +19,9 @@ public async Task> Register([FromBody] RegisterRequest Mobile = request.Mobile }; + var config = await _configRepository.GetAsync(); var (newUser, errorMessage) = - await _userRepository.InsertAsync(user, request.Password, PageUtils.GetIpAddress(Request)); + await _userRepository.InsertAsync(user, request.Password, config.IsUserRegistrationChecked, PageUtils.GetIpAddress(Request)); if (newUser == null) { return this.Error(errorMessage); diff --git a/Controllers/IndexController.cs b/Controllers/IndexController.cs index 3e9d3db..191e30e 100644 --- a/Controllers/IndexController.cs +++ b/Controllers/IndexController.cs @@ -15,16 +15,18 @@ public partial class IndexController : ControllerBase private const string RouteIsCodeCorrect = "actions/iscodecorrect"; private readonly IAuthManager _authManager; + private readonly ICacheManager _cacheManager; + private readonly IConfigRepository _configRepository; private readonly IUserRepository _userRepository; private readonly ILogRepository _logRepository; - private readonly ICacheManager _cacheManager; - public IndexController(IAuthManager authManager, IUserRepository userRepository, ILogRepository logRepository, ICacheManager cacheManager) + public IndexController(IAuthManager authManager, ICacheManager cacheManager, IConfigRepository configRepository, IUserRepository userRepository, ILogRepository logRepository) { _authManager = authManager; + _cacheManager = cacheManager; + _configRepository = configRepository; _userRepository = userRepository; _logRepository = logRepository; - _cacheManager = cacheManager; } public class EditRequest diff --git a/Controllers/RegisterController.Submit.cs b/Controllers/RegisterController.Submit.cs index 2aa9478..9f0d9b7 100644 --- a/Controllers/RegisterController.Submit.cs +++ b/Controllers/RegisterController.Submit.cs @@ -13,7 +13,8 @@ public partial class RegisterController [HttpPost, Route(Route)] public async Task> Submit([FromBody] User request) { - var (user, errorMessage) = await _userRepository.InsertAsync(request, request.Password, PageUtils.GetIpAddress(Request)); + var config = await _configRepository.GetAsync(); + var (user, errorMessage) = await _userRepository.InsertAsync(request, request.Password, config.IsUserRegistrationChecked, PageUtils.GetIpAddress(Request)); if (user == null) { return this.Error($"用户注册失败:{errorMessage}"); diff --git a/SSCMS.Login.csproj b/SSCMS.Login.csproj index 465ab2d..2c1e651 100644 --- a/SSCMS.Login.csproj +++ b/SSCMS.Login.csproj @@ -17,7 +17,7 @@ - + diff --git a/package.json b/package.json index 8000186..5bd98a9 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,11 @@ "name": "login", "displayName": "用户登录插件", "description": "SSCMS 用户登录插件", - "version": "1.2.1", + "version": "1.2.2", "license": "AGPL-3.0", "publisher": "sscms", "engines": { - "sscms": "^7.2.1" + "sscms": "^7.2.2" }, "categories": [ "Other"