Example #1
0
        private static async Task ProcessUnblockUserRequestAsync(UnblockUserRequest unblockUserRequest)
        {
            UnblockUserRequestResult result;

            using (var context = CreatePrincipalContext())
            {
                using (UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(context, unblockUserRequest.AdUserName))
                {
                    if (userPrincipal == null)
                    {
                        result = new UnblockUserRequestResult {
                            Id = unblockUserRequest.Id, RequestResult = false, RequestResultMessage = "AD User not found."
                        }
                    }
                    ;
                    else
                    {
                        userPrincipal.AccountExpirationDate = unblockUserRequest.AccountExpirationDate;
                        userPrincipal.Save();
                        result = new UnblockUserRequestResult {
                            Id = unblockUserRequest.Id, RequestResult = true, RequestResultMessage = ""
                        };
                    }
                }
            }
            HttpContent putContent = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json");
            var         response   = await _client.PutAsync("api/unblockuserrequests", putContent);

            response.EnsureSuccessStatusCode();
        }
        public async Task <IActionResult> UnblockUser([FromBody] UnblockUserRequest unblockUser)
        {
            JsonResponse <string> objResult = new JsonResponse <string>();

            try
            {
                bool unblocked = await this._settingService.UnblockUser(unblockUser);

                if (unblocked)
                {
                    objResult.Data    = StaticResource.Unblocked;
                    objResult.Status  = StaticResource.SuccessStatusCode;
                    objResult.Message = StaticResource.SuccessMessage;
                    return(new OkObjectResult(objResult));
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                objResult.Data    = ex.Message;
                objResult.Status  = StaticResource.FailStatusCode;
                objResult.Message = StaticResource.FailMessage;
            }
            return(new OkObjectResult(objResult));
        }
        public IActionResult Unblock([FromBody] UnblockUserRequest request)
        {
            bool isSuccess = _userManager.UnblockUser(CurrentUserId.Value, request.Username);

            if (!isSuccess)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Example #4
0
 public async Task <bool> UnblockUser(UnblockUserRequest unblockUser)
 {
     try
     {
         return(await this._settingsRepo.UnblockUser(unblockUser));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <bool> UnblockUser(UnblockUserRequest unblockUser)
        {
            try
            {
                UserBlocked userBlocked = await this.therapistContext.UserBlocked.FirstOrDefaultAsync(x => x.UserId.Equals(unblockUser.userId) && x.UserBlockedId.Equals(unblockUser.userBlockedId));

                userBlocked.IsActive     = false;
                userBlocked.IsDeleted    = true;
                userBlocked.ModifiedDate = DateTime.UtcNow;
                userBlocked.ModifiedBy   = unblockUser.userId;
                await this.therapistContext.SaveChangesAsync();

                await this.SaveBlockHistory(unblockUser.userId, unblockUser.blockedUserId, false);

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        private static async Task ProcessUnblockUserRequestAsync(UnblockUserRequest unblockUserRequest)
        {
            UnblockUserRequestResult result;

            try
            {
                using (var context = CreatePrincipalContext())
                {
                    using (UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(context, unblockUserRequest.AdUserName))
                    {
                        if (userPrincipal == null)
                        {
                            result = new UnblockUserRequestResult {
                                Id = unblockUserRequest.Id, RequestResult = false, RequestResultMessage = "AD User not found."
                            }
                        }
                        ;
                        else
                        {
                            string updateField = ConfigurationManager.AppSettings["AD:UpdateField"];
                            if (string.IsNullOrWhiteSpace(updateField))
                            {
                                if (userPrincipal.AccountExpirationDate.HasValue &&
                                    userPrincipal.AccountExpirationDate.Value < DateTime.UtcNow)
                                {
                                    if (!unblockUserRequest.AccountExpirationDate.HasValue || (unblockUserRequest.AccountExpirationDate.Value > DateTime.UtcNow))
                                    {
                                        userPrincipal.AccountExpirationDate = unblockUserRequest.AccountExpirationDate;
                                    }
                                    else
                                    {
                                        userPrincipal.AccountExpirationDate = null;
                                    }
                                }
                            }
                            else
                            {
                                var entry = userPrincipal.GetUnderlyingObject() as DirectoryEntry;
                                if (entry != null)
                                {
                                    var value = GetValueForFieldUpdate(entry.Properties[updateField], ConfigurationManager.AppSettings["AD:UpdateFieldEnableValue"]);
                                    entry.Properties[updateField].Clear();
                                    entry.Properties[updateField].Add(value);
                                }
                                else
                                {
                                    _logger.Warn($"Unblocked User {unblockUserRequest.AdUserName} failed. The defined update field is invalid or the user entry could not be loaded.");
                                    result = new UnblockUserRequestResult
                                    {
                                        Id                   = unblockUserRequest.Id,
                                        RequestResult        = false,
                                        RequestResultMessage = "Operation failed. The defined update field is invalid or the user entry could not be loaded."
                                    };
                                    await UpdateUnblockRequest(result);

                                    return;
                                }
                            }

                            userPrincipal.Save();
                            result = new UnblockUserRequestResult {
                                Id = unblockUserRequest.Id, RequestResult = true, RequestResultMessage = ""
                            };
                            _logger.Info($"Unblocked User {unblockUserRequest.AdUserName}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
                result = new UnblockUserRequestResult {
                    Id = unblockUserRequest.Id, RequestResult = false, RequestResultMessage = ex.Message
                };
            }
            await UpdateUnblockRequest(result);
        }