Esempio n. 1
0
        public async Task <IActionResult> Unlock(ViewMessage viewMessage)
        {
            if (ModelState.IsValid)
            {
                var message = await repository.FindByCodeAsync(viewMessage.Code);

                if (message != null)
                {
                    var messageValue = encryptor.DecryptMessage(message, viewMessage.Key);
                    var user         = await userManager.GetUserAsync(User);

                    if (messageValue != null && user == message.ApplicationUser && message.IsLockout)
                    {
                        message.IsLockout = false;
                        await repository.UpdateMessageAsync(message);
                    }
                }
            }
            return(RedirectToAction(nameof(Messages)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Message(ViewMessage viewModel)
        {
            if (ModelState.IsValid)
            {
                var message = await repository.FindByCodeAsync(viewModel.Code);

                if (message != null)
                {
                    var result = await validator.ValidateAsync(message, User?.Identity.Name);

                    if (result.Succeeded)
                    {
                        string messageValue = encryptor.DecryptMessage(message, viewModel.Key);
                        if (messageValue != null)
                        {
                            if (message.IsDisposable)
                            {
                                await repository.RemoveMessageByIdAsync(message.Code);
                            }

                            return(View(new ViewMessage {
                                Code = viewModel.Code, Message = messageValue
                            }));
                        }
                        if (message.LockoutOnFailure)
                        {
                            message.IsLockout = true;
                            await repository.UpdateMessageAsync(message);
                        }
                        ModelState.AddModelError("Key", "The entered key value is incorrect ");
                    }
                    else
                    {
                        ModelState.AddModelError("", result.Description);
                    }
                }
            }
            return(View());
        }