Created
September 19, 2009 21:04
-
-
Save cprieto/189589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using MvcContrib.Filters; | |
using Rioshu.Educa.Helpers; | |
using Rioshu.Educa.Models; | |
using Rioshu.Educa.NHibernate; | |
using Rioshu.Educa.Services; | |
namespace Rioshu.Educa.Controllers | |
{ | |
[HandleError] | |
public class MembershipController : Controller | |
{ | |
readonly IMembershipService membershipSvc; | |
public MembershipController(IMembershipService membershipSvc) | |
{ | |
Check.Require(membershipSvc != null, "Membership Service must not be null"); | |
this.membershipSvc = membershipSvc; | |
} | |
[Authorize] | |
[ModelStateToTempData] | |
public ViewResult SignUp() | |
{ | |
return View(); | |
} | |
[ModelStateToTempData] | |
[PostAction, Transaction] | |
[ValidateAntiForgeryToken] | |
public RedirectToRouteResult SignUp([Bind(Prefix = "")] SignUpForm form) | |
{ | |
if (!ModelState.IsValid) { | |
this.ErrorMessage("Hay errores en el formulario, favor corregir"); | |
return RedirectToAction("SignUp"); | |
} | |
try { | |
membershipSvc.Register(form); | |
return RedirectToAction("Thanks"); | |
} catch (ValidationException exception) { | |
this.AddValidationErrors(exception); | |
this.ErrorMessage("Hay errores en el formulario, favor corregir"); | |
return RedirectToAction("SignUp"); | |
} | |
} | |
[ModelStateToTempData] | |
public ViewResult Login(string ReturnUrl) | |
{ | |
if (!string.IsNullOrEmpty(ReturnUrl)) { | |
ViewData.Model = new LoginForm {ReturnUrl = ReturnUrl}; | |
} | |
return View(); | |
} | |
[ModelStateToTempData] | |
[PostAction, Transaction] | |
[ValidateAntiForgeryToken] | |
public ActionResult Login(LoginForm form) | |
{ | |
try { | |
membershipSvc.Login(form); | |
return Redirect(form.ReturnUrl); | |
} catch (ValidationException exception) { | |
this.ErrorMessage("Hay errores en el formulario, favor corregir"); | |
this.AddValidationErrors(exception); | |
} | |
return RedirectToAction("Login"); | |
} | |
[ActionName("Available")] | |
public JsonResult UsernameAvailable(string username) | |
{ | |
var isAvailable = membershipSvc.UsernameAvailable(username); | |
return Json(isAvailable); | |
} | |
[Authorize, ModelStateToTempData] | |
public PartialViewResult EditInfo(string username) | |
{ | |
Check.Require(!string.IsNullOrEmpty(username), "username must not be null or empty"); | |
var data = membershipSvc.GetMemberInformation(username); | |
return PartialView(data); | |
} | |
[ValidateAntiForgeryToken] | |
[PostAction, Authorize, ModelStateToTempData] | |
public PartialViewResult EditInfo(EditInfoForm info) | |
{ | |
Check.Require(info != null, "info must not be null"); | |
return PartialView(); | |
} | |
[Authorize, ModelStateToTempData] | |
public PartialViewResult EditPassword(string username) | |
{ | |
Check.Require(!string.IsNullOrEmpty(username), "username must not be null or empty"); | |
return PartialView(); | |
} | |
[Authorize, ModelStateToTempData] | |
public PartialViewResult EditSchool(string username) | |
{ | |
Check.Require(!string.IsNullOrEmpty(username), "username must not be null or empty"); | |
return PartialView(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment