示例#1
0
文件: UserManager.cs 项目: cf2080/SSO
        public async Task <User> DeleteUser(DatabaseContext _db, Guid userId)
        {
            UserDeleteService uds               = new UserDeleteService();
            IUserService      _userService      = new UserService(_db);
            SignatureService  _signatureService = new SignatureService();
            ISessionService   _sessionService   = new SessionService(_db);
            User deletingUser = _userService.GetUser(userId);
            var  sessions     = _sessionService.GetSessions(userId);
            var  applications = _applicationService.GetAllApplicationsList();
            var  responseList = new List <HttpResponseMessage>();

            //iterate through each application to check health, if any app is down, do not run delete process
            foreach (Application app in applications)
            {
                var httpresponse = await _applicationService.GetApplicationHealth(app.HealthCheckUrl);

                if (!httpresponse.IsSuccessStatusCode)
                {
                    throw new FailHealthCheckException("Failed to delete, an application is down");
                }
            }
            foreach (Application app in applications)
            {
                var deletePayload = new Dictionary <string, string>();
                deletePayload.Add("ssoUserId", userId.ToString());
                deletePayload.Add("email", deletingUser.Email);
                deletePayload.Add("timestamp", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());
                var signature = _signatureService.Sign(app.SharedSecretKey, deletePayload);
                deletePayload.Add("signature", signature);
                var request = await uds.SendDeleteRequest(app.UserDeletionUrl, deletePayload);

                responseList.Add(request);
            }
            if (responseList.All(response => response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.NotFound))
            {
                User deletedUser = _userService.DeleteUser(userId);
                if (deletedUser != null)
                {
                    _sessionService.DeleteSessions(deletedUser.Id);
                    try
                    {
                        _db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        _db.Entry(deletedUser).State = System.Data.Entity.EntityState.Detached;
                    }
                }
                return(deletedUser);                                               // delete successful
            }
            throw new FailedDeleteException("Some applications failed to delete"); // some application(s) sent back a non 200 or 404 reponse
        }
示例#2
0
        public ActionResult Delete(string DeleteUserId, SearchForm SearchForm)
        {
            UserSearchService SearchService = new UserSearchService();
            UserDto           UserInfoDto   = SearchService.SearchUserWithPrimaryKeyUserId(DeleteUserId);

            if (UserInfoDto == null)
            {
                // 削除対象のユーザ情報がない場合、検索画面を再表示
                return(View("Search", SearchForm));
            }

            UserDeleteService DeleteService = new UserDeleteService();

            DeleteService.DeleteUserWithPrimaryKeyUserId(DeleteUserId);

            return(View("DeleteComplete"));
        }
示例#3
0
 protected override void OnInitialize()
 {
     _service = new UserDeleteService(NullLogger <UserDeleteService> .Instance, Database, _mockTimelinePostService.Object);
 }