Add UserName
This commit is contained in:
parent
71e2c17e43
commit
ddebff69ec
|
|
@ -4,6 +4,7 @@ public interface IUserIdentity
|
|||
{
|
||||
string Id { get; }
|
||||
string Email { get; }
|
||||
string UserName { get; }
|
||||
string FirstName { get; }
|
||||
string LastName { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Users.Models;
|
|||
public class User
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ public static class Utilities
|
|||
return (splits[0], splits[1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush cache
|
||||
/// </summary>
|
||||
public static void ClearCache()
|
||||
{
|
||||
// Clear whole cache.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ public class UserIdentity : IUserIdentity
|
|||
public string Id
|
||||
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value!;
|
||||
|
||||
public string UserName
|
||||
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value!;
|
||||
|
||||
public string Email
|
||||
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value!;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
using BotSharp.Abstraction.Repositories.Records;
|
||||
using BotSharp.Abstraction.Users.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
|
@ -29,12 +28,15 @@ public class UserService : IUserService
|
|||
}
|
||||
|
||||
record = user;
|
||||
record.UserName = user.UserName.ToLower();
|
||||
record.Email = user.Email.ToLower();
|
||||
record.Salt = Guid.NewGuid().ToString("N");
|
||||
record.Password = Utilities.HashText(user.Password, record.Salt);
|
||||
record.ExternalId = _user.Id;
|
||||
|
||||
db.CreateUser(record);
|
||||
|
||||
Utilities.ClearCache();
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
using BotSharp.Abstraction.Users.Enums;
|
||||
using BotSharp.Abstraction.Users.Models;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Users;
|
||||
|
||||
public class UserCreationModel
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
|
@ -15,6 +15,7 @@ public class UserCreationModel
|
|||
{
|
||||
return new User
|
||||
{
|
||||
UserName = UserName,
|
||||
FirstName = FirstName,
|
||||
LastName = LastName,
|
||||
Email = Email,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using BotSharp.Abstraction.Agents.Enums;
|
||||
using BotSharp.Abstraction.Users.Enums;
|
||||
using BotSharp.Abstraction.Users.Models;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Users;
|
||||
|
|
@ -8,6 +6,8 @@ namespace BotSharp.OpenAPI.ViewModels.Users;
|
|||
public class UserViewModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
[JsonPropertyName("user_name")]
|
||||
public string UserName { get; set; }
|
||||
[JsonPropertyName("first_name")]
|
||||
public string FirstName { get; set; }
|
||||
[JsonPropertyName("last_name")]
|
||||
|
|
@ -32,6 +32,7 @@ public class UserViewModel
|
|||
return new UserViewModel
|
||||
{
|
||||
Id = user.Id,
|
||||
UserName = user.UserName,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Email = user.Email,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class SignalRHub : Hub
|
|||
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
_logger.LogInformation($"SignalR Hub: {_user.FirstName} {_user.LastName} ({Context.UserIdentifier}) connected in {Context.ConnectionId} [{DateTime.Now}]");
|
||||
_logger.LogInformation($"SignalR Hub: {_user.FirstName} {_user.LastName} ({Context.User.Identity.Name}) connected in {Context.ConnectionId}");
|
||||
|
||||
var hooks = _services.GetServices<IConversationHook>();
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
|
|
@ -32,6 +32,7 @@ public class SignalRHub : Hub
|
|||
|
||||
if (!string.IsNullOrEmpty(conversationId))
|
||||
{
|
||||
_logger.LogInformation($"Connection {Context.ConnectionId} is with conversation {conversationId}");
|
||||
var conv = await convService.GetConversation(conversationId);
|
||||
if (conv != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
|
|||
|
||||
public class UserDocument : MongoBase
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ public class MongoRepository : IBotSharpRepository
|
|||
var users = _users.Select(x => new UserDocument
|
||||
{
|
||||
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
|
||||
UserName = x.UserName,
|
||||
FirstName = x.FirstName,
|
||||
LastName = x.LastName,
|
||||
Salt = x.Salt,
|
||||
|
|
@ -132,6 +133,7 @@ public class MongoRepository : IBotSharpRepository
|
|||
{
|
||||
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, user.Id);
|
||||
var update = Builders<UserDocument>.Update
|
||||
.Set(x => x.UserName, user.UserName)
|
||||
.Set(x => x.FirstName, user.FirstName)
|
||||
.Set(x => x.LastName, user.LastName)
|
||||
.Set(x => x.Email, user.Email)
|
||||
|
|
@ -868,6 +870,7 @@ public class MongoRepository : IBotSharpRepository
|
|||
return user != null ? new User
|
||||
{
|
||||
Id = user.Id,
|
||||
UserName = user.UserName,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Email = user.Email,
|
||||
|
|
@ -884,6 +887,7 @@ public class MongoRepository : IBotSharpRepository
|
|||
return user != null ? new User
|
||||
{
|
||||
Id = user.Id,
|
||||
UserName = user.UserName,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Email = user.Email,
|
||||
|
|
@ -901,6 +905,7 @@ public class MongoRepository : IBotSharpRepository
|
|||
var userCollection = new UserDocument
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
UserName = user.UserName,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Salt = user.Salt,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using BotSharp.Abstraction.Users;
|
|||
using BotSharp.Abstraction.Users.Models;
|
||||
using BotSharp.Core.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Senparc.Weixin.MP.AdvancedAPIs.MerChant;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
|
@ -21,6 +22,7 @@ namespace BotSharp.Plugin.WeChat.Users
|
|||
{
|
||||
var user = await userService.CreateUser(new User()
|
||||
{
|
||||
UserName = openId + "@" + appId + ".wechat",
|
||||
Email = openId + "@" + appId + ".wechat",
|
||||
Password = openId
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"userName": "guest",
|
||||
"firstName": "Guest",
|
||||
"lastName": "Anonymous",
|
||||
"email": "guest@gmail.com",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
{
|
||||
"userName": "haiping",
|
||||
"firstName": "Haiping",
|
||||
"lastName": "Chen",
|
||||
"email": "admin@gmail.com",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"userName": "nancy",
|
||||
"firstName": "Nancy",
|
||||
"lastName": "Luna",
|
||||
"email": "user1@gmail.com",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"userName": "elon",
|
||||
"firstName": "Elon",
|
||||
"lastName": "Musk",
|
||||
"email": "csr1@gmail.com",
|
||||
|
|
|
|||
Loading…
Reference in a new issue