usercontroller.cs
À propos du fichier
- Type de fichier
- Fichier CS de 6 Ko (text/plain)
- Confidentialité
- Fichier public, envoyé le 3 juillet 2015 à 13:56, depuis l'adresse IP 197.15.x.x (TN)
- Sécurité
- Ne contient aucun Virus ou Malware connus - Dernière vérification: 3 jours
- Statistiques
- La présente page de téléchargement a été vue 841 fois depuis l'envoi du fichier
- Page de téléchargement
-
Aperçu du fichier
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);
using (MD5 md5Hash = MD5.Create())
{
string passwordHashed = Util.GetMd5Hash(md5Hash, user.MotDePasse);
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);
}
}
}
Partager le fichier usercontroller.cs sur le Web et les réseaux sociaux:
Télécharger le fichier usercontroller.cs
Télécharger usercontroller.cs