Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.93 KB | None | 0 0
  1. @using (Html.BeginForm("SignUp", "Authorization", FormMethod.Post))
  2. {
  3. @Html.AntiForgeryToken()
  4. <div class="col-md-2 padding0 feedback">
  5. <div class="form-group col-md-12 padding0">
  6. <label for="InputFIO">Фамилия</label>
  7. @Html.TextBoxFor(x => x.LastName, new { @class = "form-control", id = "InputFIO", placeholder = "Зареченская", type = "text" })
  8. </div>
  9. <div class="form-group col-md-12 padding0">
  10. <label for="InputName">Имя</label>
  11. @Html.TextBoxFor(x => x.FirstName, new { @class = "form-control", id = "InputName", placeholder = "Анна", type = "text" })
  12. </div>
  13. <div class="form-group col-md-12 padding0">
  14. <label for="InputSecondName">Отчество</label>
  15. @Html.TextBoxFor(x => x.MiddleName, new { @class = "form-control", id = "InputSecondName", placeholder = "Ивановна", type = "text" })
  16. </div>
  17. <div class="form-group col-md-12 padding0">
  18. <label for="InputDate">Дата рождения</label>
  19. @Html.TextBoxFor(x => x.Birthday, new { @class = "form-control", id = "InputDate", placeholder = "22.04.1959", type = "text" })
  20. </div>
  21. <div class="radio1">
  22. <p>Пол</p>
  23. @Html.RadioButtonFor(x => x.Gender, Gender.Male, new { name = "rbtnGender", id = "optionsRadios2" })
  24. <label><span class="cbxGender"></span> Мужской</label>
  25. @Html.RadioButtonFor(x => x.Gender, Gender.Female, new { name = "rbtnGender", id = "optionsRadios1" })
  26. <label><span class="cbxGender"></span>Женский</label>
  27. </div>
  28. <div class="form-group col-md-5 padding0">
  29. <label for="weight">Рост (см.)</label>
  30. @Html.TextBoxFor(x => x.Growth, new { @class = "form-control", id = "weight", placeholder = "176", type = "text" })
  31. </div>
  32. <div class="form-group col-md-5 col-md-offset-2 padding0">
  33. <label for="height">Вес (кг.)</label>
  34. @Html.TextBoxFor(x => x.Weight, new { @class = "form-control", id = "height", placeholder = "69", type = "text" })
  35. </div>
  36. <div class="form-group col-md-12 padding0">
  37. <label for="country">Страна проживания</label>
  38. @Html.DropDownListFor(x => x.CountryId, ViewBag.Countries as SelectList, "Выберите страну", new { @class = "form-control", id = "country", type = "text", placeholder = "Россия" })
  39. </div>
  40. <div class="form-group col-md-12 padding0">
  41. <label for="city">Город</label>
  42. @Html.DropDownListFor(x => x.CityId, ViewBag.Cities as SelectList, "Выберите город", new { @class = "form-control", id = "city", type = "text", placeholder = "Москва" })
  43. </div>
  44. <div class="form-group col-md-12 padding0">
  45. <label for="telephone">Телефон</label>
  46. @Html.TextBoxFor(x => x.Phone, new { @class = "form-control", id = "telephone", placeholder = "+7 949 545-55-55", type = "text" })
  47. <span><img src="~/Content/img/info.png" />для оперативной связи</span>
  48. </div>
  49. <div class="form-group col-md-12 padding0">
  50. <label for="email">Эл. почта</label>
  51. @Html.TextBoxFor(x => x.Email, new {@class = "form-control", id = "email", placeholder = "ekaterina@mail.com", type = "text"})
  52. <span><img src="~/Content/img/error.png" />Эл. почта не введена</span>
  53. </div>
  54.  
  55. <div>
  56. <label for="password">Пароль</label>
  57. @Html.TextBoxFor(x => x.Password, new { @class = "form-control", id = "password", type = "password" })
  58. </div>
  59.  
  60. <div>
  61. <label for="confirmPassword">Повторите пароль</label>
  62. @Html.TextBoxFor(x => x.ConfirmPassword, new { @class = "form-control", id = "confirmPassword", type = "password" })
  63. </div>
  64. </div>
  65.  
  66. <div class="col-md-6">
  67. </div>
  68. <div class="clearfix"></div>
  69. <div class="checkbox1 col-md-8 padding0">
  70. <input type="checkbox" value="" checked>
  71. <label><span class="cbxUserAgreement"></span>Я прочитал и согласен с <a href="">Пользовательским соглашением</a></label>
  72. <input type="checkbox" value="" checked>
  73. <label><span class="cbxRegulationsPersonalData"></span>Я прочитал и согласен с <a href="">Положением о персональных данных</a> </label>
  74. <input type="checkbox" value="" checked>
  75. <label><span class="cbxLimitationPprofessionalLiability"></span>Я прочитал и согласен с <a href="">Ограничением профессиональной ответственности</a> </label>
  76. </div>
  77. <div class="clearfix"></div>
  78. <button type="submit" class="btn btn-send">Зарегистрироваться</button>
  79. }
  80.  
  81. [HttpPost, ActionName("SignUp")]
  82. [ValidateAntiForgeryToken]
  83. public async Task<ActionResult> SignUpPost(SignUpModel model)
  84. {
  85. SelectList tempList;
  86.  
  87. // 1 - Валидация
  88. if (ModelState.IsValid)
  89. {
  90. // 2 - Проверяем на дублирование почты пользователя
  91. User user = _unitOfWork.UserRepository.Get(x => x.Email.Equals(model.Email) && !x.IsDeleted).SingleOrDefault();
  92.  
  93. if (user != null)
  94. {
  95. ModelState.AddModelError("user", "Пользователь с таким адресом электронной почты уже зарегистрирован.");
  96. model.Password = string.Empty;
  97. model.ConfirmPassword = string.Empty;
  98. tempList = GetCountrySelectList();
  99. ViewBag.Countries = tempList;
  100. ViewBag.Cities = GetCitiesSelectList(Int32.Parse(tempList.First().Value));
  101.  
  102. return View(model);
  103. }
  104.  
  105. // 3 - Валидация дня рождения
  106. DateTime currentDate = DateTime.UtcNow;
  107. if (model.Birthday < currentDate.AddYears(-100) || model.Birthday > currentDate.AddYears(-16))
  108. {
  109. ModelState.AddModelError("model.Birthday", "Допустимый возраст пользователей от 16 и старше.");
  110. model.Password = string.Empty;
  111. model.ConfirmPassword = string.Empty;
  112. tempList = GetCountrySelectList();
  113. ViewBag.Countries = tempList;
  114. ViewBag.Cities = GetCitiesSelectList(Int32.Parse(tempList.First().Value));
  115.  
  116. return View(model);
  117. }
  118.  
  119. // 4 - Шифруем пароль
  120. String hashedPassword = CryptographyHelper.HashPassword(model.Password);
  121.  
  122. // 5 - Генерируем ключ активации
  123. String activationToken = CryptographyHelper.GenerateActivationToken();
  124.  
  125. // 6 - Создаем пользователя и сохраняем его в БД
  126. User dataUser = new User
  127. {
  128. FirstName = model.FirstName,
  129. MiddleName = model.MiddleName,
  130. LastName = model.LastName,
  131. CountryId = model.CountryId,
  132. CityId = model.CityId,
  133. Birthday = model.Birthday,
  134. CreateDate = DateTime.UtcNow,
  135. Email = model.Email,
  136. ConfirmationToken = activationToken,
  137. UserPasswordHash = hashedPassword,
  138. Gender = (int)model.Gender,
  139. Growth = model.Growth,
  140. Weight = model.Weight,
  141. IsDeleted = false,
  142. LastVisitDate = DateTime.UtcNow,
  143. Phone = model.Phone
  144. };
  145. _unitOfWork.UserRepository.Insert(dataUser);
  146. await _unitOfWork.SaveAsync();
  147.  
  148. // 7 - Отправляем письмо для подтверждения регистрации
  149. if (HttpContext.Request.Url != null)
  150. {
  151. ConfirmRegistrationMailMessage mailMessage =
  152. new ConfirmRegistrationMailMessage(dataUser, HttpContext.Request.Url.AbsoluteUri);
  153. await Emailer.SendMailAsync(mailMessage);
  154. }
  155.  
  156. return RedirectToAction("RegistrationSuccess");
  157. }
  158.  
  159. tempList = GetCountrySelectList();
  160. ViewBag.Countries = tempList;
  161. ViewBag.Cities = GetCitiesSelectList(Int32.Parse(tempList.First().Value));
  162.  
  163. model.Password = string.Empty;
  164. model.ConfirmPassword = string.Empty;
  165. return View(model);
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement