gpt4 book ai didi

c# - 如何将 ServiceStack RegistrationFeature 插件与 Redis 一起使用?

转载 作者:IT王子 更新时间:2023-10-29 06:15:01 26 4
gpt4 key购买 nike

我正在添加

Plugins.Add(new RegistrationFeature());

现在我已经找到了 Register 服务的 API 页面,但是我如何将它与 Redis 一起使用呢?有什么简单的方法吗?

public object Post(Register register)
{
var Id = DBService.RegisterUser(register.UserName, register.FirstName, register.LastName, register.DisplayName, register.Email, register.Password, register.AutoLogin, register.Continue);

和Redis页面:

public string RegisterUser(string userName, string firstName, string lastName, string displayName, string email,
string password, bool? autoLogin, string @continue)
{
using (var redisclient = RedisManager.GetClient())
{
var redisUser = redisclient.As<Register>();
var yeniKayit = new Register()
{
AutoLogin = autoLogin,
Continue = @continue,
DisplayName = displayName,
UserName = userName,
Email = email,
FirstName = firstName,
LastName = lastName,
Password = password
};
redisUser.Store(yeniKayit);
return yeniKayit.Continue;
}
}

我创建了这样的代码,它保存到 redis 但这次 auth 不起作用?

最佳答案

如果启用 RegistrationFeature 并使用 the Redis setup I suggested in this answer (为了完整性显示在下面)然后注册将像正常的 ServiceStack 身份验证一样工作。

private IRedisClientsManager redisClientsManager;

public override void Configure(Funq.Container container)
{
// Configure ServiceStack to connect to Redis
// Replace with your connection details
redisClientsManager = new PooledRedisClientManager("127.0.0.1:6379");
container.Register<IRedisClientsManager>(c => redisClientsManager);
container.Register<ICacheClient>(c => c.Resolve<IRedisClientsManager>().GetCacheClient()).ReusedWithin(Funq.ReuseScope.None);

// Setup the authorisation feature
Plugins.Add(new AuthFeature(()=>
new AuthUserSession(),
new IAuthProvider[]{ new BasicAuthProvider() }
));

// Use a RedisAuthRepository
var userRepo = new RedisAuthRepository(redisClientsManager);
container.Register<IUserAuthRepository>(userRepo);

// Enable the RegistrationFeature
Plugins.Add(new RegistrationFeature());
}

因此,如果您向 /register 发布一个有效的注册请求,那么该用户将在 Redis 存储库中创建。

{
"UserName": "john.smith",
"Password": "test",
"Email": "john.smith@domain.com",
"FirstName": "John",
"LastName": "Smith",
"DisplayName": "John Smith"
}

关于c# - 如何将 ServiceStack RegistrationFeature 插件与 Redis 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24801968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com