Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
starlying committed Dec 13, 2023
1 parent 47ce398 commit f55ad3d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.2
* 更新API接口

## 1.2.1
* 修复微信登录调整错误

Expand Down
19 changes: 11 additions & 8 deletions Controllers/AuthController.GetRedirect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public async Task<ActionResult<GetRedirectResult>> GetRedirect([FromRoute] strin
{
var host = ApiUtils.GetHost(Request);
var oAuthType = OAuthType.Parse(type);
var config = await _configRepository.GetAsync();

var userName = string.Empty;

Expand All @@ -40,7 +41,7 @@ public async Task<ActionResult<GetRedirectResult>> 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Controllers/IndexController.Register.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public async Task<ActionResult<BoolResult>> 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);
Expand Down
8 changes: 5 additions & 3 deletions Controllers/IndexController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Controllers/RegisterController.Submit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public partial class RegisterController
[HttpPost, Route(Route)]
public async Task<ActionResult<BoolResult>> 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}");
Expand Down
2 changes: 1 addition & 1 deletion SSCMS.Login.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SSCMS" Version="7.2.1" />
<PackageReference Include="SSCMS" Version="7.2.2" />
<!-- <ProjectReference Include="..\..\..\SSCMS\SSCMS.csproj" /> -->
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f55ad3d

Please sign in to comment.