Example #1
0
        protected override void Save(Guid userID, string service, string key, string hashedSaltedSecret, string newkey = null)
        {
            var existing = LoadRegistration(service, key);

            using (var conn = ConnectionHelper.Open())
            {
                var sqlUser = new DragonRegistration()
                {
                    RegistrationID = Guid.NewGuid(),
                    UserID = userID,
                    Service = service,
                    Key = newkey??key, /* can rename key */
                    Secret = hashedSaltedSecret
                };

                if (existing != null)
                {
                    sqlUser.RegistrationID = existing.RegistrationID;

                    if (!existing.Key.Equals(key))
                        throw new InvalidOperationException(
                            "Trying to attach another account from the already connected service");

                    conn.ExecuteFor<DragonRegistration>(SQL.SqlUserStore_Update, sqlUser);
                }
                else
                {
                    conn.ExecuteFor<DragonRegistration>(SQL.SqlUserStore_Insert, sqlUser);
                }
            }
        }
Example #2
0
        protected override void Save(Guid userID, string service, string key, string hashedSaltedSecret, string newkey = null)
        {
            var existing = LoadRegistration(service, key);

            using (var conn = ConnectionHelper.Open())
            {
                var sqlUser = new DragonRegistration()
                {
                    RegistrationID = Guid.NewGuid(),
                    UserID         = userID,
                    Service        = service,
                    Key            = newkey ?? key, /* can rename key */
                    Secret         = hashedSaltedSecret
                };

                if (existing != null)
                {
                    sqlUser.RegistrationID = existing.RegistrationID;

                    if (!existing.Key.Equals(key))
                    {
                        throw new InvalidOperationException(
                                  "Trying to attach another account from the already connected service");
                    }

                    conn.ExecuteFor <DragonRegistration>(SQL.SqlUserStore_Update, sqlUser);
                }
                else
                {
                    conn.ExecuteFor <DragonRegistration>(SQL.SqlUserStore_Insert, sqlUser);
                }
            }
        }