123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using System.Globalization;
- using System.Text.RegularExpressions;
- namespace ARM_spec_otdelenia
- {
- public partial class ChangePassword : Form
- {
- public ChangePassword()
- {
- InitializeComponent();
- }
- public static bool IsValidEmail(string email)
- {
- if (string.IsNullOrWhiteSpace(email))
- return false;
- try
- {
- // Normalize the domain
- email = Regex.Replace(email, @"(@)(.+)$", DomainMapper,
- RegexOptions.None, TimeSpan.FromMilliseconds(200));
- // Examines the domain part of the email and normalizes it.
- string DomainMapper(Match match)
- {
- var idn = new IdnMapping();
- string domainName = idn.GetAscii(match.Groups[2].Value);
- return match.Groups[1].Value + domainName;
- }
- }
- catch (RegexMatchTimeoutException e)
- {
- MessageBox.Show(e.Message);
- return false;
- }
- catch (ArgumentException e)
- {
- MessageBox.Show(e.Message);
- return false;
- }
- try
- {
- return Regex.IsMatch(email,
- @"^[^@\s]+@[^@\s]+\.[^@\s]+$",
- RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
- }
- catch (RegexMatchTimeoutException)
- {
- return false;
- }
- }
- private void backBtn_Click(object sender, EventArgs e)
- {
- Close();
- Authorization authorization = new Authorization();
- authorization.Show();
- }
- private void enterBtn_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(mailText.Text))
- {
- MessageBox.Show("Заполните поле!");
- }
- if (IsValidEmail(mailText.Text) == false)
- {
- MessageBox.Show("Почта введена некорректно!");
- return;
- }
- else
- {
- MailGet.Email = mailText.Text;
- MailGet.SMS = mailText.Text;
- using (var db = new ARMClassesDataContext())
- {
- var user = db.Пользователи.FirstOrDefault(u => mailText.Text == u.Почта);
- if (user != null)
- {
- CheckMail check = new CheckMail();
- check.ShowDialog();
- if (check.flag == true)
- {
- PasswordSubmit passwordSubmit = new PasswordSubmit();
- passwordSubmit.Show();
- this.Close();
- }
- else
- {
- return;
- }
- }
- else
- {
- MessageBox.Show("Пользователь с такой почтой не найден");
- }
- }
- }
- }
- private void enterBtn_MouseMove(object sender, MouseEventArgs e)
- {
- enterBtn.ForeColor = Color.FromArgb(24, 186, 96);
- enterBtn.FlatAppearance.BorderColor = Color.FromArgb(24, 186, 96);
- }
- private void enterBtn_MouseLeave(object sender, EventArgs e)
- {
- enterBtn.ForeColor = Color.Black;
- enterBtn.FlatAppearance.BorderColor = Color.Black;
- }
- private void backBtn_MouseMove(object sender, MouseEventArgs e)
- {
- backBtn.ForeColor = Color.FromArgb(24, 186, 96);
- backBtn.FlatAppearance.BorderColor = Color.FromArgb(24, 186, 96);
- }
- private void backBtn_MouseLeave(object sender, EventArgs e)
- {
- backBtn.ForeColor = Color.Black;
- backBtn.FlatAppearance.BorderColor = Color.Black;
- }
- }
- }
|