public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model) { if (ModelState.IsValid) { if (model.OldPassword == model.NewPassword) { ModelState.AddModelError(string.Empty, "Новый и старый пароли не должны совпадать"); return(View(model)); } User user = await userManager.FindByNameAsync(User.Identity.Name); user.UserName += ApplicationConstantsProvider.AvoidValidationCode(); user.Email += ApplicationConstantsProvider.AvoidValidationCode(); var changePasswordResult = await userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (changePasswordResult.Succeeded) { return(View("Redirect", new RedirectModel { InfoMessages = RedirectionMessageProvider.AccountUpdatedMessages(), RedirectUrl = "/Account/Personal", SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime() })); } else { ModelState.AddModelError(string.Empty, "Вы ввели неверный старый пароль"); } } return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { if (!string.IsNullOrWhiteSpace(model.TelegramId)) { User sameTelegramUser = (await userLogic.Read(new User { TelegramUsername = model.TelegramId }))?.FirstOrDefault(); if (sameTelegramUser != null) { ModelState.AddModelError(string.Empty, "Уже есть пользователь с таким Telegram-идентификатором"); return(View(model)); } } User user = new User { Email = model.Email, UserName = model.UserName, TelegramUsername = string.IsNullOrWhiteSpace(model.TelegramId) ? string.Empty : model.TelegramId, TelegramChatId = string.Empty }; var registerResult = await userManager.CreateAsync(user, model.Password); if (registerResult.Succeeded) { user.Email += ApplicationConstantsProvider.AvoidValidationCode(); user.UserName += ApplicationConstantsProvider.AvoidValidationCode(); await userManager.AddToRoleAsync(user, "regular user"); await savedListLogic.Create(user); await signInManager.SignInAsync(user, false); return(View("Redirect", new RedirectModel { InfoMessages = RedirectionMessageProvider.AccountCreatedMessages(), RedirectUrl = "/Home/Lots", SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime() })); } else { foreach (var error in registerResult.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(View(model)); }
public async Task <IActionResult> PlaceBid(string lotId) { if (!string.IsNullOrWhiteSpace(lotId)) { User user = await userManager.FindByNameAsync(User.Identity.Name); try { await bidLogic.Create(new Bid { AuctionLot = (await lotLogic.Read(new AuctionLot { Id = lotId }))?.First(), User = user }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View("Redirect", new RedirectModel { InfoMessages = RedirectionMessageProvider.AuctionTimeUpMessages(), RedirectUrl = $"/User/OpenLot/?id={lotId}", SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime() })); } AuctionLot lotToAdd = new AuctionLot { Id = lotId }; await savedListLogic.Add(user, lotToAdd); await SendNotifications(lotId, User.Identity.Name); return(View("Redirect", new RedirectModel { InfoMessages = RedirectionMessageProvider.BidPlacedMessages(), RedirectUrl = $"/User/OpenLot/?id={lotId}", SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime() })); } return(NotFound()); }