ChangePassword.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. using System.Globalization;
  12. using System.Text.RegularExpressions;
  13. namespace ARM_spec_otdelenia
  14. {
  15. public partial class ChangePassword : Form
  16. {
  17. public ChangePassword()
  18. {
  19. InitializeComponent();
  20. }
  21. public static bool IsValidEmail(string email)
  22. {
  23. if (string.IsNullOrWhiteSpace(email))
  24. return false;
  25. try
  26. {
  27. // Normalize the domain
  28. email = Regex.Replace(email, @"(@)(.+)$", DomainMapper,
  29. RegexOptions.None, TimeSpan.FromMilliseconds(200));
  30. // Examines the domain part of the email and normalizes it.
  31. string DomainMapper(Match match)
  32. {
  33. var idn = new IdnMapping();
  34. string domainName = idn.GetAscii(match.Groups[2].Value);
  35. return match.Groups[1].Value + domainName;
  36. }
  37. }
  38. catch (RegexMatchTimeoutException e)
  39. {
  40. MessageBox.Show(e.Message);
  41. return false;
  42. }
  43. catch (ArgumentException e)
  44. {
  45. MessageBox.Show(e.Message);
  46. return false;
  47. }
  48. try
  49. {
  50. return Regex.IsMatch(email,
  51. @"^[^@\s]+@[^@\s]+\.[^@\s]+$",
  52. RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
  53. }
  54. catch (RegexMatchTimeoutException)
  55. {
  56. return false;
  57. }
  58. }
  59. private void backBtn_Click(object sender, EventArgs e)
  60. {
  61. Close();
  62. Authorization authorization = new Authorization();
  63. authorization.Show();
  64. }
  65. private void enterBtn_Click(object sender, EventArgs e)
  66. {
  67. if (string.IsNullOrEmpty(mailText.Text))
  68. {
  69. MessageBox.Show("Заполните поле!");
  70. }
  71. if (IsValidEmail(mailText.Text) == false)
  72. {
  73. MessageBox.Show("Почта введена некорректно!");
  74. return;
  75. }
  76. else
  77. {
  78. MailGet.Email = mailText.Text;
  79. MailGet.SMS = mailText.Text;
  80. using (var db = new ARMClassesDataContext())
  81. {
  82. var user = db.Пользователи.FirstOrDefault(u => mailText.Text == u.Почта);
  83. if (user != null)
  84. {
  85. CheckMail check = new CheckMail();
  86. check.ShowDialog();
  87. if (check.flag == true)
  88. {
  89. PasswordSubmit passwordSubmit = new PasswordSubmit();
  90. passwordSubmit.Show();
  91. this.Close();
  92. }
  93. else
  94. {
  95. return;
  96. }
  97. }
  98. else
  99. {
  100. MessageBox.Show("Пользователь с такой почтой не найден");
  101. }
  102. }
  103. }
  104. }
  105. private void enterBtn_MouseMove(object sender, MouseEventArgs e)
  106. {
  107. enterBtn.ForeColor = Color.FromArgb(24, 186, 96);
  108. enterBtn.FlatAppearance.BorderColor = Color.FromArgb(24, 186, 96);
  109. }
  110. private void enterBtn_MouseLeave(object sender, EventArgs e)
  111. {
  112. enterBtn.ForeColor = Color.Black;
  113. enterBtn.FlatAppearance.BorderColor = Color.Black;
  114. }
  115. private void backBtn_MouseMove(object sender, MouseEventArgs e)
  116. {
  117. backBtn.ForeColor = Color.FromArgb(24, 186, 96);
  118. backBtn.FlatAppearance.BorderColor = Color.FromArgb(24, 186, 96);
  119. }
  120. private void backBtn_MouseLeave(object sender, EventArgs e)
  121. {
  122. backBtn.ForeColor = Color.Black;
  123. backBtn.FlatAppearance.BorderColor = Color.Black;
  124. }
  125. }
  126. }