diff options
author | matthewsotoudeh <matthewsot@outlook.com> | 2015-04-26 11:17:34 -0700 |
---|---|---|
committer | matthewsotoudeh <matthewsot@outlook.com> | 2015-04-26 11:17:34 -0700 |
commit | faf624b6ce119afeaa913a8030a57299823b5362 (patch) | |
tree | 0feaf1550c601420cba5d9f8639d6a39c8a8e136 | |
parent | 31304200c4c56b42e040a0a243ead5f274139dcf (diff) |
cleaned out AccountController
-rw-r--r-- | LHSCamp/LHSCamp/Controllers/AccountAPIController.cs | 5 | ||||
-rw-r--r-- | LHSCamp/LHSCamp/Controllers/AccountController.cs | 113 | ||||
-rw-r--r-- | LHSCamp/LHSCamp/Models/AccountViewModels.cs | 89 | ||||
-rw-r--r-- | LHSCamp/LHSCamp/Views/Account/Manage.cshtml | 59 |
4 files changed, 2 insertions, 264 deletions
diff --git a/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs b/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs index 5fc2ad9..e271deb 100644 --- a/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs +++ b/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs @@ -1,13 +1,8 @@ using LHSCamp.Models; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.Owin; -using System; using System.Collections.Generic; using System.Linq; -using System.Net.Mail; using System.Threading.Tasks; -using System.Web; -using System.Web.Configuration; using System.Web.Http; namespace LHSCamp.Controllers diff --git a/LHSCamp/LHSCamp/Controllers/AccountController.cs b/LHSCamp/LHSCamp/Controllers/AccountController.cs index 5cdb9e0..02fd57b 100644 --- a/LHSCamp/LHSCamp/Controllers/AccountController.cs +++ b/LHSCamp/LHSCamp/Controllers/AccountController.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Threading.Tasks; using System.Web; using System.Web.Mvc; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Owin.Security; using Owin; using LHSCamp.Models; @@ -89,32 +84,6 @@ namespace LHSCamp.Controllers return View(); } - [AllowAnonymous] - public ActionResult ForgotPass() - { - return View(); - } - - [AllowAnonymous] - [HttpGet] - public ActionResult ResetPass(string token, string userId) - { - ViewBag.Token = token; - ViewBag.UserId = userId; - return View(); - } - - // - // GET: /Account/Manage - public async Task<ActionResult> Manage(ManageMessageId? message) - { - var model = new ManageUserViewModel(); - model.Email = await UserManager.GetEmailAsync(User.Identity.GetUserId()); - ViewBag.HasLocalPassword = HasPassword(); - ViewBag.ReturnUrl = Url.Action("Manage"); - return View(model); - } - [HttpGet] [Route("Account/LogOff")] public ActionResult LogOff() @@ -138,15 +107,6 @@ namespace LHSCamp.Controllers return RedirectToAction("Index", controllerName: "Default"); } - - [ChildActionOnly] - public ActionResult RemoveAccountList() - { - var linkedAccounts = UserManager.GetLogins(User.Identity.GetUserId()); - ViewBag.ShowRemoveButton = HasPassword() || linkedAccounts.Count > 1; - return (ActionResult)PartialView("_RemoveAccountPartial", linkedAccounts); - } - protected override void Dispose(bool disposing) { if (disposing && UserManager != null) @@ -158,9 +118,6 @@ namespace LHSCamp.Controllers } #region Helpers - // Used for XSRF protection when adding external logins - private const string XsrfKey = "XsrfId"; - private IAuthenticationManager AuthenticationManager { get @@ -169,77 +126,11 @@ namespace LHSCamp.Controllers } } - private async Task SignInAsync(User user, bool isPersistent) + private async Task SignInAsync(Candidate user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager)); } - - private void AddErrors(IdentityResult result) - { - foreach (var error in result.Errors) - { - ModelState.AddModelError("", error); - } - } - - private bool HasPassword() - { - var user = UserManager.FindById(User.Identity.GetUserId()); - if (user != null) - { - return user.PasswordHash != null; - } - return false; - } - - public enum ManageMessageId - { - ChangePasswordSuccess, - SetPasswordSuccess, - RemoveLoginSuccess, - Error - } - - private ActionResult RedirectToLocal(string returnUrl) - { - if (Url.IsLocalUrl(returnUrl)) - { - return Redirect(returnUrl); - } - else - { - return RedirectToAction("Index", "Home"); - } - } - - private class ChallengeResult : HttpUnauthorizedResult - { - public ChallengeResult(string provider, string redirectUri) : this(provider, redirectUri, null) - { - } - - public ChallengeResult(string provider, string redirectUri, string userId) - { - LoginProvider = provider; - RedirectUri = redirectUri; - UserId = userId; - } - - public string LoginProvider { get; set; } - public string RedirectUri { get; set; } - public string UserId { get; set; } - - public override void ExecuteResult(ControllerContext context) - { - var properties = new AuthenticationProperties() { RedirectUri = RedirectUri }; - if (UserId != null) - { - properties.Dictionary[XsrfKey] = UserId; - } - context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider); - } - } #endregion } }
\ No newline at end of file diff --git a/LHSCamp/LHSCamp/Models/AccountViewModels.cs b/LHSCamp/LHSCamp/Models/AccountViewModels.cs index 9321355..7caac60 100644 --- a/LHSCamp/LHSCamp/Models/AccountViewModels.cs +++ b/LHSCamp/LHSCamp/Models/AccountViewModels.cs @@ -2,45 +2,6 @@ namespace LHSCamp.Models { - public class ExternalLoginConfirmationViewModel - { - [Required] - [Display(Name = "Username")] - public string UserName { get; set; } - - [EmailAddress] - [Display(Name = "Email (optional)")] - public string Email { get; set; } - } - public class ChangeEmailViewModel - { - [EmailAddress] - [Display(Name = "Email")] - public string Email { get; set; } - } - public class ManageUserViewModel - { - [EmailAddress] - [Display(Name = "Email")] - public string Email { get; set; } - - [Required] - [DataType(DataType.Password)] - [Display(Name = "Current password")] - public string OldPassword { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "New password")] - public string NewPassword { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm new password")] - [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - public class LoginViewModel { [Required] @@ -55,54 +16,4 @@ namespace LHSCamp.Models [Display(Name = "Remember me?")] public bool RememberMe { get; set; } } - - public class RegisterViewModel - { - [Required] - [Display(Name = "Username")] - public string UserName { get; set; } - - [EmailAddress] - [Display(Name = "Email (optional)")] - public string Email { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "Password")] - public string Password { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm password")] - [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - - public class ResetPasswordViewModel - { - [Required] - [Display(Name = "Username")] - public string UserName { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "Password")] - public string Password { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm password")] - [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - - public string Code { get; set; } - } - - public class ForgotPasswordViewModel - { - [Required] - [EmailAddress] - [Display(Name = "Email")] - public string Email { get; set; } - } } diff --git a/LHSCamp/LHSCamp/Views/Account/Manage.cshtml b/LHSCamp/LHSCamp/Views/Account/Manage.cshtml deleted file mode 100644 index 1257083..0000000 --- a/LHSCamp/LHSCamp/Views/Account/Manage.cshtml +++ /dev/null @@ -1,59 +0,0 @@ -@using LHSCamp.Models; -@using Microsoft.AspNet.Identity; -@model ManageUserViewModel -@{ - ViewBag.Title = "Account Settings"; -} - -<h2>@ViewBag.Title</h2> -<h3>Email</h3> -<p class="text-success">@ViewBag.StatusMessage</p> -<input id="email" type="email" class="default-input standard-input" placeholder="email" value="@Model.Email" /> -<br /> -<button id="save-email" class="standard-btn default-btn">Update Email</button> -<br /><br /> -<h3>Password</h3> -<input type="password" id="curr-pass" class="default-input standard-input" placeholder="current password" /><br /> -<input type="password" id="new-pass" class="default-input standard-input" placeholder="new password" /><br /> -<input type="password" id="conf-pass" class="default-input standard-input" placeholder="confirm new password" /><br /> -<button id="change-pass" class="standard-btn default-btn">Change Password</button> -@section Scripts { - @Scripts.Render("~/bundles/jqueryval") - <script type="text/javascript"> - $("#save-email").click(function () { - var email = $("#email").val(); - - $.post("/API/Account/SetEmail", { - "email": email - }, function (data) { - if (data == "set") { - //Somehow we need to indicate that something happened, I guess this works for now - window.location.reload(true); - } - }); - }); - - $("#change-pass").click(function () { - var currPass = $("#curr-pass").val(); - var newPass = $("#new-pass").val(); - var confPass = $("#conf-pass").val(); - - if (newPass != confPass) { - alert("Confirmation didn't match!"); - } - else { - $.post("/API/Account/SetPass", { - "currPass": currPass, - "newPass": newPass - }, function (data) { - if (data == "set") { - window.location.reload(true); - } - else { - alert("Current password is incorrect."); - } - }); - } - }); - </script> -} |