Servicestack允许多个用户使用同一封电子邮件

问题描述 投票:1回答:1

我正在尝试允许多个用户使用同一封电子邮件。我扩展了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个回答
2
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.