public async Task <IActionResult> SendInvalidImages(InvalidImages invalidImages) { InvalidImagesModel model = new InvalidImagesModel() { returnUrl = invalidImages.returnUrl, PersonID = invalidImages.PersonID }; foreach (var item in invalidImages.NeededId) { if (item == ImageTypeCodes.NationalCard.ToInt()) { model.NationalCard = new PersonImagesDTO() { ImageTypeID = item, ImageTypeName = ExtensionMethods.Description <ImageTypeCodes>((ImageTypeCodes)item) }; } else if (item == ImageTypeCodes.Person.ToInt()) { model.Person = new PersonImagesDTO() { ImageTypeID = item, ImageTypeName = ExtensionMethods.Description <ImageTypeCodes>((ImageTypeCodes)item) }; } else if (item == ImageTypeCodes.Booklet.ToInt()) { model.Booklet = new PersonImagesDTO() { ImageTypeID = item, ImageTypeName = ExtensionMethods.Description <ImageTypeCodes>((ImageTypeCodes)item) }; } Console.WriteLine(ExtensionMethods.Description <ImageTypeCodes>((ImageTypeCodes)item)); } return(View(model)); }
public async Task <IActionResult> Login(LoginInputModel model, string button) { if (button != "login") { // the user clicked the "cancel" button var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl); if (context != null) { // if the user cancels, send a result back into IdentityServer as if they // denied the consent (even if this client does not require consent). // this will send back an access denied OIDC error response to the client. await _interaction.GrantConsentAsync(context, ConsentResponse.Denied); // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null return(Redirect(model.ReturnUrl)); } else { // since we don't have a valid context, then we just go back to the home page return(Redirect("~/")); } } if (ModelState.IsValid) { var User = Sql.User.FirstOrDefault(p => p.UserName == model.Username && p.Password == Api.EncryptPassword(model.Password)); // validate username/password against in-memory store if (User != null /* || _users.ValidateCredentials(model.Username, model.Password)*/) { Console.WriteLine(User.Password); LoginDTO login = Api.ToObject <LoginDTO>(Api.Execute(new Inputs { Password = User.Password, NationalCode = User.UserName }, "DeviceLogin")); PersonDTO person = login.Person; if (person == null) { await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials")); ModelState.AddModelError("", AccountOptions.InvalidCredentialsErrorMessage); } else { if (person.PersonImages == null || person.PersonImages.Count == 0) { } else { var notAccepted = person.PersonImages.Where(p => p.ImageStatusID != ImageStatusCodes.Accepted.ToInt()).ToList(); if (notAccepted.Count > 0) { var pending = person.PersonImages.Where(p => p.ImageStatusID == ImageStatusCodes.Pending.ToInt()).ToList(); var invalid = person.PersonImages.Where(p => p.ImageStatusID != ImageStatusCodes.Accepted.ToInt() && p.ImageStatusID != ImageStatusCodes.Pending.ToInt()).ToList(); if (pending.Count == login.NeedImages.Count || (pending.Count > 0 && invalid.Count == 0)) { // something went wrong, show form with error var m = await _account.BuildLoginViewModelAsync(model); m.pleaseWait = true; return(View(m)); } else { InvalidImages invalidModel = new InvalidImages(); invalidModel.PersonID = person.PersonID; invalidModel.NeededId = invalid.Select(p => p.ImageTypeID).ToList(); invalidModel.returnUrl = model.ReturnUrl; return(RedirectToAction("SendInvalidImages", invalidModel)); } } } Console.WriteLine(User.UserName); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("UserName", User.UserName); Console.WriteLine(User.UserName); TestUser user = new TestUser { Username = User.UserName, SubjectId = User.Id.ToString(), IsActive = true, ProviderSubjectId = User.UserName, Password = User.Password, ProviderName = User.UserName, Claims = new List <Claim> { new Claim("UserName", User.UserName) { } } }; //var user = _users.FindByUsername(model.Username); await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.SubjectId, user.Username)); // only set explicit expiration here if user chooses "remember me". // otherwise we rely upon expiration configured in cookie middleware. AuthenticationProperties props = null; if (AccountOptions.AllowRememberLogin && model.RememberLogin) { props = new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration), RedirectUri = "/" }; } ; //user.Claims.Add(); // issue authentication cookie with subject ID and username await HttpContext.SignInAsync(new IdentityServerUser(User.UserName), props); Console.WriteLine(model.ReturnUrl); // make sure the returnUrl is still valid, and if so redirect back to authorize endpoint or a local page if (_interaction.IsValidReturnUrl(model.ReturnUrl) || Url.IsLocalUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } return(Redirect("~/")); } } await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials")); ModelState.AddModelError("", AccountOptions.InvalidCredentialsErrorMessage); } // something went wrong, show form with error var vm = await _account.BuildLoginViewModelAsync(model); return(View(vm)); }