hdong:Add flag CreateUserAutomatically to control user create in user/me .

This commit is contained in:
YouWeiDH 2024-10-30 19:39:26 +08:00
parent d592621190
commit 3ec5055216
2 changed files with 6 additions and 2 deletions

View file

@ -7,4 +7,5 @@ public class AccountSetting
/// </summary>
public bool NewUserVerification { get; set; }
public string[] AllowMultipleDeviceLoginUserIds { get; set; } = [];
public bool CreateUserAutomatically { get; set; } = true;
}

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Users.Settings;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using System.ComponentModel.DataAnnotations;
@ -10,10 +11,12 @@ public class UserController : ControllerBase
{
private readonly IServiceProvider _services;
private readonly IUserService _userService;
public UserController(IUserService userService, IServiceProvider services)
private readonly AccountSetting _setting;
public UserController(IUserService userService, IServiceProvider services, AccountSetting setting)
{
_services = services;
_userService = userService;
_setting = setting;
}
[AllowAnonymous]
@ -77,7 +80,7 @@ public class UserController : ControllerBase
public async Task<UserViewModel> GetMyUserProfile()
{
var user = await _userService.GetMyProfile();
if (user == null)
if (user == null && _setting.CreateUserAutomatically)
{
var identiy = _services.GetRequiredService<IUserIdentity>();
var accessor = _services.GetRequiredService<IHttpContextAccessor>();