Skip to content

Commit 4d5ebd8

Browse files
authored
Merge pull request #286 from SciSharp/master
merge latest code
2 parents f7cef69 + 592d7a0 commit 4d5ebd8

File tree

48 files changed

+475
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+475
-217
lines changed

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public interface IBotSharpRepository
1818
#region User
1919
User? GetUserByEmail(string email);
2020
User? GetUserById(string id);
21+
User? GetUserByUserName(string userName);
2122
void CreateUser(User user);
2223
#endregion
2324

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using BotSharp.Abstraction.Users.Models;
2+
using System.Security.Claims;
3+
4+
namespace BotSharp.Abstraction.Users;
5+
6+
public interface IAuthenticationHook
7+
{
8+
Task<User> Authenticate(string id, string password);
9+
void AddClaims(List<Claim> claims);
10+
}

src/Infrastructure/BotSharp.Abstraction/Users/IUserIdentity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public interface IUserIdentity
77
string UserName { get; }
88
string FirstName { get; }
99
string LastName { get; }
10+
string FullName { get; }
1011
}

src/Infrastructure/BotSharp.Abstraction/Users/Models/User.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class User
1111
public string Email { get; set; } = string.Empty;
1212
public string Salt { get; set; } = string.Empty;
1313
public string Password { get; set; } = string.Empty;
14+
public string Source { get; set; } = "internal";
1415
public string? ExternalId { get; set; }
1516
public string Role { get; set; } = UserRole.Client;
1617
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;

src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public bool AttachMenu(List<PluginMenuDef> menu)
3636
{
3737
SubMenu = new List<PluginMenuDef>
3838
{
39-
new PluginMenuDef("Router", link: "/page/agent/router"), // icon: "bx bx-map-pin"
40-
new PluginMenuDef("Evaluator", link: "/page/agent/evaluator"), // icon: "bx bx-task"
41-
new PluginMenuDef("Agents", link: "/page/agent"), // icon: "bx bx-bot"
39+
new PluginMenuDef("Router", link: "page/agent/router"), // icon: "bx bx-map-pin"
40+
new PluginMenuDef("Evaluator", link: "page/agent/evaluator"), // icon: "bx bx-task"
41+
new PluginMenuDef("Agents", link: "page/agent"), // icon: "bx bx-bot"
4242
}
4343
});
4444

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<PackageReference Include="Colorful.Console" Version="1.2.15" />
120120
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.1" />
121121
<PackageReference Include="Fluid.Core" Version="2.5.0" />
122+
<PackageReference Include="Nanoid" Version="3.0.0" />
122123
</ItemGroup>
123124

124125
<ItemGroup>

src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
5151
public bool AttachMenu(List<PluginMenuDef> menu)
5252
{
5353
var section = menu.First(x => x.Label == "Apps");
54-
menu.Add(new PluginMenuDef("Conversation", link: "/page/conversation", icon: "bx bx-conversation", weight: section.Weight + 5));
54+
menu.Add(new PluginMenuDef("Conversation", link: "page/conversation", icon: "bx bx-conversation", weight: section.Weight + 5));
5555
return true;
5656
}
5757
}

src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,17 @@ public void IncrementConversationCount()
192192
#endregion
193193

194194
#region User
195-
public User? GetUserByEmail(string email)
196-
{
197-
throw new NotImplementedException();
198-
}
195+
public User? GetUserByEmail(string email)
196+
=> throw new NotImplementedException();
199197

200-
public User? GetUserById(string id)
201-
{
202-
throw new NotImplementedException();
203-
}
198+
public User? GetUserById(string id)
199+
=> throw new NotImplementedException();
204200

205-
public void CreateUser(User user)
206-
{
207-
throw new NotImplementedException();
208-
}
201+
public User? GetUserByUserName(string userName)
202+
=> throw new NotImplementedException();
203+
204+
public void CreateUser(User user)
205+
=> throw new NotImplementedException();
209206
#endregion
210207

211208

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
using BotSharp.Abstraction.Users.Models;
22
using System.IO;
33

4-
namespace BotSharp.Core.Repository
4+
namespace BotSharp.Core.Repository;
5+
6+
public partial class FileRepository
57
{
6-
public partial class FileRepository
8+
public User? GetUserByEmail(string email)
79
{
8-
public User? GetUserByEmail(string email)
9-
{
10-
return Users.FirstOrDefault(x => x.Email == email);
11-
}
10+
return Users.FirstOrDefault(x => x.Email == email.ToLower());
11+
}
1212

13-
public User? GetUserById(string id = null)
14-
{
15-
return Users.FirstOrDefault(x => x.ExternalId == id || x.Id == id);
16-
}
13+
public User? GetUserById(string id = null)
14+
{
15+
return Users.FirstOrDefault(x => x.Id == id || (x.ExternalId != null && x.ExternalId == id));
16+
}
17+
18+
public User? GetUserByUserName(string userName = null)
19+
{
20+
return Users.FirstOrDefault(x => x.UserName == userName.ToLower());
21+
}
1722

18-
public void CreateUser(User user)
23+
public void CreateUser(User user)
24+
{
25+
var userId = Guid.NewGuid().ToString();
26+
user.Id = userId;
27+
var dir = Path.Combine(_dbSettings.FileRepository, "users", userId);
28+
if (!Directory.Exists(dir))
1929
{
20-
var userId = Guid.NewGuid().ToString();
21-
user.Id = userId;
22-
var dir = Path.Combine(_dbSettings.FileRepository, "users", userId);
23-
if (!Directory.Exists(dir))
24-
{
25-
Directory.CreateDirectory(dir);
26-
}
27-
var path = Path.Combine(dir, "user.json");
28-
File.WriteAllText(path, JsonSerializer.Serialize(user, _options));
30+
Directory.CreateDirectory(dir);
2931
}
32+
var path = Path.Combine(dir, "user.json");
33+
File.WriteAllText(path, JsonSerializer.Serialize(user, _options));
3034
}
3135
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
using BotSharp.Abstraction.Users.Models;
55
using BotSharp.Abstraction.Agents.Models;
66
using MongoDB.Driver;
7-
using BotSharp.Abstraction.Routing.Models;
8-
using BotSharp.Abstraction.Repositories.Filters;
9-
using BotSharp.Abstraction.Repositories.Models;
10-
using BotSharp.Abstraction.Routing.Settings;
11-
using BotSharp.Abstraction.Evaluations.Settings;
127
using System.Text.Encodings.Web;
138
using BotSharp.Abstraction.Plugins.Models;
149
using BotSharp.Abstraction.Statistics.Settings;

0 commit comments

Comments
 (0)