Servicestack 允许多个用户使用同一封电子邮件
Servicestack allow same email for multiple users
我正在尝试让多个用户拥有同一封电子邮件。我扩展了 OrmLiteAuthRepository 覆盖了 AssertNoExistingUser 但它从未被调用,即使我得到 "duplicate email error"。我知道它已连接,因为 getpermissions 方法正在运行。
public class MyOrmLiteAuthRepository : OrmLiteAuthRepository
{
public MyOrmLiteAuthRepository(IDbConnectionFactory dbFactory) : base(dbFactory) { }
public MyOrmLiteAuthRepository(IDbConnectionFactory dbFactory, string namedConnnection = null)
: base(dbFactory, namedConnnection)
{
DbFactory = dbFactory;
NamedConnnection = namedConnnection;
}
protected override void AssertNoExistingUser(IDbConnection db, IUserAuth newUser, IUserAuth exceptForExistingUser = null)
{
//I hate using try catch for simple stuff, it is very slow,
//But this is only during new users being added so low risk for slow
//and the base class should be called to do its native stuff
try
{
base.AssertNoExistingUser(db,newUser);
}
catch (Exception e)
{
if (e.Message.Contains("Email"))
{
//mask duplicate email messages
return;
}
//throw any other errors on new user creation.
throw;
}
}
public IDbConnectionFactory DbFactory { get; set; }
public string NamedConnnection { get; set; }
public override ICollection<string> GetPermissions(string userAuthId)
{
//Ignore this as we have implemented our own security
// base.GetPermissions(userAuthId);
using (var ss = HostContext.ResolveService<SecurityService>(new BasicRequest()))
{
return ss.UserPermissions(Convert.ToInt32(userAuthId));
}
}
ServiceStack 可以使用用户名或电子邮件进行身份验证,但无论使用哪一种,它们都必须是唯一的,以便唯一标识尝试进行身份验证的用户。
如果您只想在多个用户中保留相同的电子邮件地址,您可以将其存储在 PrimaryEmail
中,该地址未在身份验证中验证或使用。
我正在尝试让多个用户拥有同一封电子邮件。我扩展了 OrmLiteAuthRepository 覆盖了 AssertNoExistingUser 但它从未被调用,即使我得到 "duplicate email error"。我知道它已连接,因为 getpermissions 方法正在运行。
public class MyOrmLiteAuthRepository : OrmLiteAuthRepository
{
public MyOrmLiteAuthRepository(IDbConnectionFactory dbFactory) : base(dbFactory) { }
public MyOrmLiteAuthRepository(IDbConnectionFactory dbFactory, string namedConnnection = null)
: base(dbFactory, namedConnnection)
{
DbFactory = dbFactory;
NamedConnnection = namedConnnection;
}
protected override void AssertNoExistingUser(IDbConnection db, IUserAuth newUser, IUserAuth exceptForExistingUser = null)
{
//I hate using try catch for simple stuff, it is very slow,
//But this is only during new users being added so low risk for slow
//and the base class should be called to do its native stuff
try
{
base.AssertNoExistingUser(db,newUser);
}
catch (Exception e)
{
if (e.Message.Contains("Email"))
{
//mask duplicate email messages
return;
}
//throw any other errors on new user creation.
throw;
}
}
public IDbConnectionFactory DbFactory { get; set; }
public string NamedConnnection { get; set; }
public override ICollection<string> GetPermissions(string userAuthId)
{
//Ignore this as we have implemented our own security
// base.GetPermissions(userAuthId);
using (var ss = HostContext.ResolveService<SecurityService>(new BasicRequest()))
{
return ss.UserPermissions(Convert.ToInt32(userAuthId));
}
}
ServiceStack 可以使用用户名或电子邮件进行身份验证,但无论使用哪一种,它们都必须是唯一的,以便唯一标识尝试进行身份验证的用户。
如果您只想在多个用户中保留相同的电子邮件地址,您可以将其存储在 PrimaryEmail
中,该地址未在身份验证中验证或使用。