Пример #1
0
        protected override void Save(Guid userID, string service, string key, string hashedSaltedSecret)
        {
            using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
            {
                var existing = LoadRegistration(service, key);
                conn.Open();
                var sqlUser = new DragonRegistration()
                {
                    RegistrationID = Guid.NewGuid(),
                    UserID = userID,
                    Service = service,
                    Key = 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);
                }
            }
        }
Пример #2
0
 protected override void SetPropertyInternal(Guid userID, string key, string val)
 {
     using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
     {
         conn.Open();
         var param = new { LID = Guid.NewGuid(), UserID = userID, Key = key, Value = val };
         if (conn.ExecuteFor<DragonProfile>(SQL.SqlProfileStore_Update, param) == 0)
         {
             conn.ExecuteFor<DragonProfile>(SQL.SqlProfileStore_Insert, param);
         }
     }
 }
Пример #3
0
        protected override void RemoveSessionRecord(Guid sessionID)
        {
            base.RemoveSessionRecord(sessionID);

            using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
            {
                conn.Open();
                conn.ExecuteFor<DragonSession>(SQL.SqlSessionStore_Delete, new { SessionID = sessionID });
            }
        }
Пример #4
0
        protected override void AddNodeInternal(Guid parentID, Guid childID)
        {
            var parents = EnumerateParentNodesInternal(childID);

            if (!parents.Contains(parentID))
            {
                using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
                {
                    conn.Open();
                    var param = new DragonPermissionNode() {ParentID = parentID, ChildID = childID};
                    conn.ExecuteFor<DragonPermissionNode>(SQL.SqlPermissionStore_InsertPermissionNode, param);
                }
            }

            RebuildTree();
        }
Пример #5
0
        protected override void SaveSessionRecord(DragonSession sessionRecord)
        {
            using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
            {
                conn.Open();

                SetSessionData(sessionRecord);
                var p = new
                    {
                        Hash = sessionRecord.Hash,
                        SessionID = sessionRecord.SessionID,
                        Expires = sessionRecord.Expires,
                        Location = sessionRecord.Location,
                        UserID = sessionRecord.UserID
                    };
                if (conn.ExecuteFor<DragonSession>(SQL.SqlSessionStore_Update, p) == 0)
                {
                    conn.ExecuteFor<DragonSession>(SQL.SqlSessionStore_Insert, p);
                }
            }

            base.SaveSessionRecord(sessionRecord);
        }
Пример #6
0
        protected override void AddRightInternal(Guid nodeID, Guid subjectID, string spec, bool inherit)
        {
            if (EnumerateRightsInternal(nodeID).Any(x =>
                x.SubjectID.Equals(subjectID) && x.Spec.Equals(spec)))
            {
                RemoveRightInternal(nodeID, subjectID, spec);
            }

            using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
            {
                conn.Open();
                var param = new DragonPermissionRight()
                    {
                        LID = Guid.NewGuid(),
                        NodeID = nodeID,
                        SubjectID = subjectID,
                        Spec = spec,
                        Inherit = inherit
                    };
                conn.ExecuteFor<DragonPermissionRight>(SQL.SqlPermissionStore_InsertPermissionRight, param);
            }

            RebuildTree();
        }
Пример #7
0
        protected override void RemoveRightInternal(Guid nodeID, Guid subjectID, string spec)
        {
            var candidate = EnumerateRightsInternal(nodeID).FirstOrDefault(x =>
                x.SubjectID.Equals(subjectID) && x.Spec.Equals(spec));

            if (candidate == null)
                throw new RightDoesNotExistException();

            using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
            {
                conn.Open();
                var param = new
                {
                    LID = candidate.LID
                };
                conn.ExecuteFor<DragonPermissionRight>(SQL.SqlPermissionStore_DeletePermissionRight, param);
            }

            RebuildTree();
        }
Пример #8
0
        protected override void RemoveNodeInternal(Guid parentID, Guid childID)
        {
            // no parenthood test here because delete will ignore anyway

            using (var conn = new SqlConnection(StandardSqlStore.ConnectionString))
            {
                conn.Open();
                var param = new { ParentID = parentID, ChildID = childID };
                conn.ExecuteFor<DragonPermissionNode>(SQL.SqlPermissionStore_DeletePermissionNode, param);
            }

            RebuildTree();
        }