public ActionResult Activation() { if (UserContext.Current != null && Request.IsAuthenticated) { var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.Id == UserContext.Current.Id); if (user == null) { throw new BusinessLogicException("Возникла ошибка. Система не знает такого пользователя."); } var justRegistered = user.RegistrationDate > (DateTime.Now - ConstHelper.UserOutdatedTime); var phoneNubmer = Regex.Replace(user.PhoneNumber, @"\D*", string.Empty); var model = new AccountActivationViewModel { Id = user.Id, AccountMail = user.Email, SubscribtionMail = user.SubscriptionSettings.SubscriptionEmail, Phone = phoneNubmer, ShowCode = false, JustRegistered = justRegistered }; return(View(model)); } return(RedirectToAction("signin", "account", null)); }
public ActionResult ActivateAccount(AccountActivationViewModel viewModel) { try { UserRegistrationService.ActivateAccount(viewModel.U, viewModel.VC); } catch (BusinessException exp) { viewModel.ErrorMessage = exp.Message; } return(View("AccountActivationResult", viewModel)); }
public ActionResult Activation(AccountActivationViewModel model) { if (!Request.IsAuthenticated) { return(RedirectToAction("signin", "account", null)); } if (ModelState.IsValid) { if (model.CodeId == Guid.Empty || string.IsNullOrWhiteSpace(model.Code)) { var phone = UserService.NormalizePhoneNumber(model.Phone); var encryptedPhoneNumber = CryptographyService.EncryptPhone(phone); var usersWithSamePhone = DataService.PerThread.BaseUserSet.OfType <User>().Count(u => u.EncryptedPhoneNumber == encryptedPhoneNumber && (u.Id != model.Id)); if (usersWithSamePhone != 0) { throw new ValidationException("Пользователь с таким номером телефона уже активирован"); } var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(u => u.Id == UserContext.Current.Id); if (user == null) { throw new BusinessLogicException("Неверный идентификатор пользователя!"); } user.PhoneNumber = phone; user.SubscriptionSettings.SubscriptionEmail = model.SubscribtionMail; UserService.NormalizePhoneNumber(user); ModelState.Clear(); model.CodeId = user.Id; model.ShowCode = true; var code = AccountService.GenerateSecretCode(user.Id); var sms = "Ваш секретный код для верификации на Демократии2: " + code; if (UserContext.Current.SentSmsCount >= 5) { throw new BusinessLogicException("Лимит ваших смс исчерпан. Обратитесь в техподдержку"); } SmsService.SendSms(user.PhoneNumber, sms); UserContext.Current.SentSmsCount++; } else { if (!AccountService.VerifySecretCode(model.CodeId, model.Code)) { throw new ValidationException("Введен неверный код!"); } if (UserContext.Current.Id != model.Id) { throw new BusinessLogicException("Возникла ошибка. Ключ пользователя начала и завершения активации аккаунта не совпадают."); } var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.Id == UserContext.Current.Id); if (user == null) { throw new BusinessLogicException("Возникла ошибка. Система не знает такого пользователя."); } user.IsOutdated = false; user.IsPhoneVerified = true; UserContext.Abandon(); return(RedirectToAction("profile", "user", null)); } } return(View(model)); }