Nos partenaires et nous-mêmes utilisons différentes technologies, telles que les cookies, pour personnaliser les contenus et les publicités, proposer des fonctionnalités sur les réseaux sociaux et analyser le trafic. Merci de cliquer sur le bouton ci-dessous pour donner votre accord. Vous pouvez changer d’avis et modifier vos choix à tout moment. Informations RGPD
using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Net; using System.Web; using System.Web.Mvc; using Inscription.Models; using Inscription.Context; using Inscription.Repository; using System.Net.Mail; using CaptchaMvc.HtmlHelpers; namespace Inscription.Controllers { public class UserController : Controller { private GenericRepository<User> db = new GenericRepository<User>(new InscriptionDBContext()); // GET: /User/ public ActionResult Index() { return View(db.All()); } public ActionResult CaptionVerify(string empty) { // Code for validating the CAPTCHA if (this.IsCaptchaValid("Captcha is not valid")) { return View("ConfirmAccount"); } ViewBag.ErrMessage = "Error: captcha is not valid."; return View(); } // GET: /User/Details/5 public ActionResult Details(long? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } User user = (User)db.GetById(id); //User user = db.Users.Find(id); if (user == null) { return HttpNotFound(); } return View(user); } // GET: /User/Create public ActionResult Create() { return View(); } // POST: /User/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "Id,Nom,Prenom,Email,DateDeNaissance,Societe,Site_Societe,MotDePasse")] User user) { if (ModelState.IsValid) { Inscription.Models.MailModel _objModelMail; MailMessage mail = new MailMessage(); mail.To.Add(user.Email); // mail.From = new MailAddress(_objModelMail.From); mail.From = new MailAddress("openbeeemailstage@gmail.com"); mail.Subject = "Inscription"; string Body = "An account successfully done welcome " + user.Nom + " " + user.Prenom + " thanks for trusting us\n this is your serial number 099384AHB45HFJG "; mail.Body = Body; mail.IsBodyHtml = true; try { if (this.IsCaptchaValid("Captcha is not valid")) { SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("openbeeemailstage@gmail.com", "123456789openbee"); smtp.EnableSsl = true; smtp.Send(mail); //il faut ajouter ici une logique de hashage de façon, tu appelles à une méthode qui fait le hachage du motdepasse String passwordHashed= hash(user.MotDePasse); // il faut travaller sur cette fonction user.MotDepasse = passwordHashed; db.Add(user); return View("ConfirmAccount"); } ViewBag.ErrMessage = "Error: captcha is not valid."; return View(user); //return RedirectToAction("ConfirmAccount"); } catch (Exception ex) { return View(user); } } return View(user); } // GET: /User/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } User user = db.GetById(id); if (user == null) { return HttpNotFound(); } return View(user); } // POST: /User/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include="Id,Nom,Prenom,Email,DateDeNaissance,Societe,Site_Societe,MotDePasse")] User user) { if (ModelState.IsValid) { db.Update(user); return RedirectToAction("Index"); } return View(user); } // GET: /User/Delete/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } User user = db.GetById(id); if (user == null) { return HttpNotFound(); } return View(user); } // POST: /User/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { User user = db.GetById(id); db.Delete(user); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { if (disposing) { //db.Dispose(); } base.Dispose(disposing); } } }