Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @using (Html.BeginForm("SignUp", "Authorization", FormMethod.Post))
- {
- @Html.AntiForgeryToken()
- <div class="col-md-2 padding0 feedback">
- <div class="form-group col-md-12 padding0">
- <label for="InputFIO">Фамилия</label>
- @Html.TextBoxFor(x => x.LastName, new { @class = "form-control", id = "InputFIO", placeholder = "Зареченская", type = "text" })
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="InputName">Имя</label>
- @Html.TextBoxFor(x => x.FirstName, new { @class = "form-control", id = "InputName", placeholder = "Анна", type = "text" })
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="InputSecondName">Отчество</label>
- @Html.TextBoxFor(x => x.MiddleName, new { @class = "form-control", id = "InputSecondName", placeholder = "Ивановна", type = "text" })
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="InputDate">Дата рождения</label>
- @Html.TextBoxFor(x => x.Birthday, new { @class = "form-control", id = "InputDate", placeholder = "22.04.1959", type = "text" })
- </div>
- <div class="radio1">
- <p>Пол</p>
- @Html.RadioButtonFor(x => x.Gender, Gender.Male, new { name = "rbtnGender", id = "optionsRadios2" })
- <label><span class="cbxGender"></span> Мужской</label>
- @Html.RadioButtonFor(x => x.Gender, Gender.Female, new { name = "rbtnGender", id = "optionsRadios1" })
- <label><span class="cbxGender"></span>Женский</label>
- </div>
- <div class="form-group col-md-5 padding0">
- <label for="weight">Рост (см.)</label>
- @Html.TextBoxFor(x => x.Growth, new { @class = "form-control", id = "weight", placeholder = "176", type = "text" })
- </div>
- <div class="form-group col-md-5 col-md-offset-2 padding0">
- <label for="height">Вес (кг.)</label>
- @Html.TextBoxFor(x => x.Weight, new { @class = "form-control", id = "height", placeholder = "69", type = "text" })
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="country">Страна проживания</label>
- @Html.DropDownListFor(x => x.CountryId, ViewBag.Countries as SelectList, "Выберите страну", new { @class = "form-control", id = "country", type = "text", placeholder = "Россия" })
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="city">Город</label>
- @Html.DropDownListFor(x => x.CityId, ViewBag.Cities as SelectList, "Выберите город", new { @class = "form-control", id = "city", type = "text", placeholder = "Москва" })
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="telephone">Телефон</label>
- @Html.TextBoxFor(x => x.Phone, new { @class = "form-control", id = "telephone", placeholder = "+7 949 545-55-55", type = "text" })
- <span><img src="~/Content/img/info.png" />для оперативной связи</span>
- </div>
- <div class="form-group col-md-12 padding0">
- <label for="email">Эл. почта</label>
- @Html.TextBoxFor(x => x.Email, new {@class = "form-control", id = "email", placeholder = "ekaterina@mail.com", type = "text"})
- <span><img src="~/Content/img/error.png" />Эл. почта не введена</span>
- </div>
- <div>
- <label for="password">Пароль</label>
- @Html.TextBoxFor(x => x.Password, new { @class = "form-control", id = "password", type = "password" })
- </div>
- <div>
- <label for="confirmPassword">Повторите пароль</label>
- @Html.TextBoxFor(x => x.ConfirmPassword, new { @class = "form-control", id = "confirmPassword", type = "password" })
- </div>
- </div>
- <div class="col-md-6">
- </div>
- <div class="clearfix"></div>
- <div class="checkbox1 col-md-8 padding0">
- <input type="checkbox" value="" checked>
- <label><span class="cbxUserAgreement"></span>Я прочитал и согласен с <a href="">Пользовательским соглашением</a></label>
- <input type="checkbox" value="" checked>
- <label><span class="cbxRegulationsPersonalData"></span>Я прочитал и согласен с <a href="">Положением о персональных данных</a> </label>
- <input type="checkbox" value="" checked>
- <label><span class="cbxLimitationPprofessionalLiability"></span>Я прочитал и согласен с <a href="">Ограничением профессиональной ответственности</a> </label>
- </div>
- <div class="clearfix"></div>
- <button type="submit" class="btn btn-send">Зарегистрироваться</button>
- }
- [HttpPost, ActionName("SignUp")]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> SignUpPost(SignUpModel model)
- {
- SelectList tempList;
- // 1 - Валидация
- if (ModelState.IsValid)
- {
- // 2 - Проверяем на дублирование почты пользователя
- User user = _unitOfWork.UserRepository.Get(x => x.Email.Equals(model.Email) && !x.IsDeleted).SingleOrDefault();
- if (user != null)
- {
- ModelState.AddModelError("user", "Пользователь с таким адресом электронной почты уже зарегистрирован.");
- model.Password = string.Empty;
- model.ConfirmPassword = string.Empty;
- tempList = GetCountrySelectList();
- ViewBag.Countries = tempList;
- ViewBag.Cities = GetCitiesSelectList(Int32.Parse(tempList.First().Value));
- return View(model);
- }
- // 3 - Валидация дня рождения
- DateTime currentDate = DateTime.UtcNow;
- if (model.Birthday < currentDate.AddYears(-100) || model.Birthday > currentDate.AddYears(-16))
- {
- ModelState.AddModelError("model.Birthday", "Допустимый возраст пользователей от 16 и старше.");
- model.Password = string.Empty;
- model.ConfirmPassword = string.Empty;
- tempList = GetCountrySelectList();
- ViewBag.Countries = tempList;
- ViewBag.Cities = GetCitiesSelectList(Int32.Parse(tempList.First().Value));
- return View(model);
- }
- // 4 - Шифруем пароль
- String hashedPassword = CryptographyHelper.HashPassword(model.Password);
- // 5 - Генерируем ключ активации
- String activationToken = CryptographyHelper.GenerateActivationToken();
- // 6 - Создаем пользователя и сохраняем его в БД
- User dataUser = new User
- {
- FirstName = model.FirstName,
- MiddleName = model.MiddleName,
- LastName = model.LastName,
- CountryId = model.CountryId,
- CityId = model.CityId,
- Birthday = model.Birthday,
- CreateDate = DateTime.UtcNow,
- Email = model.Email,
- ConfirmationToken = activationToken,
- UserPasswordHash = hashedPassword,
- Gender = (int)model.Gender,
- Growth = model.Growth,
- Weight = model.Weight,
- IsDeleted = false,
- LastVisitDate = DateTime.UtcNow,
- Phone = model.Phone
- };
- _unitOfWork.UserRepository.Insert(dataUser);
- await _unitOfWork.SaveAsync();
- // 7 - Отправляем письмо для подтверждения регистрации
- if (HttpContext.Request.Url != null)
- {
- ConfirmRegistrationMailMessage mailMessage =
- new ConfirmRegistrationMailMessage(dataUser, HttpContext.Request.Url.AbsoluteUri);
- await Emailer.SendMailAsync(mailMessage);
- }
- return RedirectToAction("RegistrationSuccess");
- }
- tempList = GetCountrySelectList();
- ViewBag.Countries = tempList;
- ViewBag.Cities = GetCitiesSelectList(Int32.Parse(tempList.First().Value));
- model.Password = string.Empty;
- model.ConfirmPassword = string.Empty;
- return View(model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement