protected void Submit_click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(email.Text) && !string.IsNullOrEmpty(password.Text)) { if (email.Text.Length > 50 || password.Text.Length > 40) { notification.Style.Add("color", "red"); notification.InnerText = "Les données sont trop longues"; notification.Visible = true; } else { UserFactory uf = new UserFactory(cnnStr); User user = uf.Connexion(email.Text, password.Text); if (user == null) { //Email ou mot de passe incorrect password.Text = ""; notification.Style.Add("color", "red"); notification.InnerText = "Adresse e-mail ou mot de passe incorrect"; notification.Visible = true; } else { //User existe if (user.activated == false) { //Compte pas activé password.Text = ""; notification.Style.Add("color", "red"); notification.InnerText = "Votre compte n'est pas activé. Un e-mail de confirmation vous a été renvoyé."; notification.Visible = true; EmailController ec = new EmailController(); string body = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Email/ActivationEmail.html"))) { body = reader.ReadToEnd(); } body = body.Replace("{email}", email.Text); body = body.Replace("{token}", user.token); ec.SendMail(email.Text, "Bienvenue!", body); } else { //Compte activé Session["User"] = user; Response.Redirect("Default.aspx"); //Renvoie à la page d'ou il arrive } } } } else { //Manque une info notification.Visible = true; notification.Style.Add("color", "red"); notification.InnerText = "Veuillez remplir tous les champs"; } }
protected void btnConfirm_Click(object sender, EventArgs e) { //Check si les truc du form sont valide //Affiche page de confirmation //Send email de confirmation if (!string.IsNullOrEmpty(txtNewPassword.Text) && !string.IsNullOrEmpty(txtOldPassword.Text) && !string.IsNullOrEmpty(txtConfirm.Text)) { if (txtNewPassword.Text != txtConfirm.Text) { notification.Visible = true; notification.Style.Add("color", "red"); notification.InnerText = "Le nouveau mot de passe et le mot de passe dans la boite de confirmation doivent être identique"; } else { UserFactory uf = new UserFactory(cnnStr); //if le mot de passe en haut est le bon //if les 2 mdp sont pareil User curr = (User)Session["User"]; User user = uf.Connexion(curr.email, txtOldPassword.Text); if (user == null) { //Email ou mot de passe incorrect txtOldPassword.Text = ""; txtNewPassword.Text = ""; txtConfirm.Text = ""; notification.Style.Add("color", "red"); notification.InnerText = "Mot de passe incorrecte"; notification.Visible = true; } else { uf.addNewPassword(curr.userId, txtNewPassword.Text); txtOldPassword.Text = ""; txtNewPassword.Text = ""; txtConfirm.Text = ""; //envoi du email de confirmation EmailController ec = new EmailController(); string body = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Email/ConfirmationPassword.html"))) { body = reader.ReadToEnd(); } string strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery; string strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/"); string lienActivation = strUrl + "ConfirmationChangementMdp.aspx" + "?email=" + curr.email + "&tkn=" + curr.token; body = body.Replace("{email}", user.email); body = body.Replace("{lienActivation}", lienActivation); ec.SendMail(user.email, "Changement de mot de passe", body); notification.Style.Add("color", "red"); notification.InnerText = "Un courriel de confirmation a été envoyé dans votre boite de courriel."; } } } else { notification.Visible = true; notification.Style.Add("color", "red"); notification.InnerText = "Veuillez remplir tous les champs"; } }