Merge pull request #16 from AnonymousDotNet/lida_dev

Lida dev
This commit is contained in:
Haiping 2024-09-29 07:09:31 -05:00 committed by GitHub
commit 35fef3364f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 42 additions and 7 deletions

View file

@ -14,7 +14,7 @@ public interface IBotSharpRepository
void Add<TTableInterface>(object entity);
#region Plugin
PluginConfig GetPluginConfig();
PluginConfig GetPluginConfig();
void SavePluginConfig(PluginConfig config);
#endregion
@ -22,7 +22,7 @@ public interface IBotSharpRepository
User? GetUserByEmail(string email) => throw new NotImplementedException();
User? GetUserByPhone(string phone) => throw new NotImplementedException();
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
User? GetUserByAffiliateId(string affiliateId) => throw new NotImplementedException();
User? GetUserByUserName(string userName) => throw new NotImplementedException();
@ -30,9 +30,10 @@ public interface IBotSharpRepository
void UpdateUserVerified(string userId) => throw new NotImplementedException();
void UpdateUserVerificationCode(string userId, string verficationCode) => throw new NotImplementedException();
void UpdateUserPassword(string userId, string password) => throw new NotImplementedException();
void UpdateUserEmail(string userId, string email)=> throw new NotImplementedException();
void UpdateUserEmail(string userId, string email) => throw new NotImplementedException();
void UpdateUserPhone(string userId, string Iphone) => throw new NotImplementedException();
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
#endregion
#region Agent
@ -76,7 +77,7 @@ public interface IBotSharpRepository
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
IEnumerable<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
#endregion
#region Execution Log
void AddExecutionLogs(string conversationId, List<string> logs);
List<string> GetExecutionLogs(string conversationId);

View file

@ -10,4 +10,5 @@ public interface IAuthenticationHook
void BeforeSending(Token token);
Task UserCreated(User user);
Task VerificationCodeResetPassword(User user);
Task DelUsers(List<string> userIds);
}

View file

@ -19,4 +19,5 @@ public interface IUserService
Task<bool> ModifyUserPhone(string phone);
Task<bool> UpdatePassword(string newPassword, string verificationCode);
Task<DateTime> GetUserTokenExpires();
Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable);
}

View file

@ -1,5 +1,5 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Infrastructures;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
using BotSharp.Abstraction.Users.Settings;
using BotSharp.OpenAPI.ViewModels.Users;
@ -9,7 +9,6 @@ using NanoidDotNet;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text.RegularExpressions;
using System.Net;
namespace BotSharp.Core.Users.Services;
@ -524,4 +523,23 @@ public class UserService : IUserService
db.UpdateUserPhone(record.Id, phone);
return true;
}
public async Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
db.UpdateUsersIsDisable(userIds, isDisable);
if (!isDisable)
{
return true;
}
// del membership
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
await hook.DelUsers(userIds);
}
return true;
}
}

View file

@ -68,7 +68,7 @@ public class UserController : ControllerBase
var token = await _userService.ActiveUser(model);
if (token == null)
{
return Unauthorized();
return BadRequest();
}
return Ok(token);
}
@ -143,6 +143,12 @@ public class UserController : ControllerBase
return await _userService.ModifyUserPhone(phone);
}
[HttpPost("/user/update/isdisable")]
public async Task<bool> UpdateUsersIsDisable([FromQuery] List<string> userIds, [FromQuery] bool isDisable)
{
return await _userService.UpdateUsersIsDisable(userIds, isDisable);
}
#region Avatar
[HttpPost("/user/avatar")]
public bool UploadUserAvatar([FromBody] UserAvatarModel input)

View file

@ -126,4 +126,12 @@ public partial class MongoRepository
.Set(x => x.UpdatedTime, DateTime.UtcNow);
_dc.Users.UpdateOne(filter, update);
}
public void UpdateUsersIsDisable(List<string> userIds, bool isDisable)
{
foreach (var userId in userIds)
{
UpdateUserIsDisable(userId, isDisable);
}
}
}