Create User works
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using MileageTraker.Web.Membership;
|
||||
using MileageTraker.Web.ViewModels.Account;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
@@ -21,10 +20,15 @@ namespace MileageTraker.Web.Controllers
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Login(LoginViewModel model, string returnUrl)
|
||||
{
|
||||
if (ModelState.IsValid && WebSecurity.Login(model.EmailAddress, model.Password, model.RememberMe))
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// TODO: send notification to user
|
||||
return RedirectToLocal(returnUrl);
|
||||
var success = Membership.ValidateUser(model.Username, model.Password);
|
||||
if (success)
|
||||
{
|
||||
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
|
||||
// TODO: send notification to user
|
||||
return RedirectToLocal(returnUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
@@ -36,48 +40,47 @@ namespace MileageTraker.Web.Controllers
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult LogOff()
|
||||
{
|
||||
WebSecurity.Logout();
|
||||
FormsAuthentication.SignOut();
|
||||
|
||||
// TODO: send notification to user
|
||||
return RedirectToAction("Index", "CreateLog");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
//[AllowAnonymous]
|
||||
//public ActionResult Register()
|
||||
//{
|
||||
// return View();
|
||||
//}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Register(RegisterModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Attempt to register the user
|
||||
try
|
||||
{
|
||||
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
|
||||
WebSecurity.Login(model.UserName, model.Password);
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
catch (MembershipCreateUserException e)
|
||||
{
|
||||
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
|
||||
}
|
||||
}
|
||||
//[HttpPost]
|
||||
//[AllowAnonymous]
|
||||
//[ValidateAntiForgeryToken]
|
||||
//public ActionResult Register(RegisterModel model)
|
||||
//{
|
||||
// if (ModelState.IsValid)
|
||||
// {
|
||||
// // Attempt to register the user
|
||||
// try
|
||||
// {
|
||||
// WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
|
||||
// WebSecurity.Login(model.UserName, model.Password);
|
||||
// return RedirectToAction("Login");
|
||||
// }
|
||||
// catch (MembershipCreateUserException e)
|
||||
// {
|
||||
// ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
|
||||
// }
|
||||
// }
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
return View(model);
|
||||
}
|
||||
// // If we got this far, something failed, redisplay form
|
||||
// return View(model);
|
||||
//}
|
||||
|
||||
public ActionResult Manage(ManageMessageId? message)
|
||||
{
|
||||
ViewBag.StatusMessage =
|
||||
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
|
||||
: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
|
||||
: message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
|
||||
: "";
|
||||
ViewBag.ReturnUrl = Url.Action("Manage");
|
||||
return View();
|
||||
@@ -95,9 +98,10 @@ namespace MileageTraker.Web.Controllers
|
||||
bool changePasswordSucceeded;
|
||||
try
|
||||
{
|
||||
changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
|
||||
var currentUser = Membership.GetUser(User.Identity.Name, true);
|
||||
changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
changePasswordSucceeded = false;
|
||||
}
|
||||
@@ -106,10 +110,7 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
|
||||
}
|
||||
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
@@ -129,7 +130,6 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
ChangePasswordSuccess,
|
||||
SetPasswordSuccess,
|
||||
RemoveLoginSuccess,
|
||||
}
|
||||
|
||||
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
|
||||
|
||||
Reference in New Issue
Block a user