【问题标题】:Servicestack allow same email for multiple usersServicestack 允许多个用户使用相同的电子邮件
【发布时间】:2019-10-24 13:01:52
【问题描述】:

我正在尝试允许多个用户拥有相同的电子邮件。我扩展了 OrmLiteAuthRepository 覆盖了 AssertNoExistingUser 但它从未被调用,即使我收到“重复的电子邮件错误”。我知道它已连接,因为 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 ormlite-servicestack


    【解决方案1】:

    ServiceStack 可以使用用户名或电子邮件进行身份验证,但无论使用哪种,它们都必须是唯一的,以便唯一标识尝试进行身份验证的用户。

    如果您只想在多个用户中保留相同的电子邮件地址,您可以将其存储在 PrimaryEmail 中,该地址未经过验证或在身份验证中使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2018-11-16
      • 2015-08-30
      • 2014-08-06
      • 2011-06-17
      • 2014-11-24
      • 1970-01-01
      相关资源
      最近更新 更多