- RazorApp.zip
- RazorApp
- packages
- EntityFramework.4.1.10331.0
- EntityFramework.4.1.10331.0.nupkg
- lib
- jQuery.1.5.1
- Content
- Scripts
- jQuery.1.5.1.nupkg
- jQuery.UI.Combined.1.8.11
- Content
- Content
- themes
- base
- Scripts
- jQuery.UI.Combined.1.8.11.nupkg
- jQuery.Validation.1.8.0
- Content
- Scripts
- jQuery.Validation.1.8.0.nupkg
- jQuery.vsdoc.1.5.1
- Content
- Scripts
- jQuery.vsdoc.1.5.1.nupkg
- Modernizr.1.7
- Content
- Scripts
- Modernizr.1.7.nupkg
- repositories.config
- RazorApp.sln
- RazorApp.suo
- RazorApp
- App_Data
- ASPNETDB.MDF
- aspnetdb_log.ldf
- MvcMusicStore.sdf
- Content
- chosen.css
- images
- admin-privilege-icon.png
- chosen-sprite.png
- Home-icon.png
- home-showcase.png
- img_logo.gif
- logo.png
- placeholder.gif
- shopping-cart-icon.png
- textbox_bg.jpg
- ui-bg_flat_55_999999_40x100.png
- ui-bg_flat_75_aaaaaa_40x100.png
- ui-bg_glass_45_0078ae_1x400.png
- ui-bg_glass_55_f8da4e_1x400.png
- ui-bg_glass_75_79c9ec_1x400.png
- ui-bg_gloss-wave_45_e14f1c_500x100.png
- ui-bg_gloss-wave_50_6eac2c_500x100.png
- ui-bg_gloss-wave_75_2191c0_500x100.png
- ui-bg_gloss-wave_85_9fda58_500x100.png
- ui-bg_inset-hard_100_fcfdfd_1x100.png
- ui-icons_0078ae_256x240.png
- ui-icons_056b93_256x240.png
- ui-icons_d8e7f3_256x240.png
- ui-icons_e0fdff_256x240.png
- ui-icons_f5e175_256x240.png
- ui-icons_f7a50d_256x240.png
- ui-icons_fcd113_256x240.png
- jquery-ui-1.8.18.custom.css
- Site.css
- themes
- base
- ui.jqgrid.css
- Controllers
- Global.asax
- Global.asax.cs
- Helper
- Models
- packages.config
- Properties
- RazorApp.csproj
- RazorApp.csproj.user
- Scripts
- ViewModels
- Views
- web.config
- Web.Debug.config
- Web.Release.config
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using RazorApp.Models;
using Mvc3ToolsUpdateWeb_Default.Models;
namespace RazorApp.Controllers
{
public class AccountController : Controller
{
private void MigrateShoppingCart(string UserName)
{
// Associate shopping cart items with logged-in user
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.MigrateCart(UserName);
Session[ShoppingCart.CartSessionKey] = UserName;
}
//
// GET: /Account/LogOn
public ActionResult LogOn()
{
return View();
}
//
// POST: /Account/LogOn
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
MigrateShoppingCart(model.UserName);
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
//
// GET: /Account/LogOff
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Home");
}
//
// GET: /Account/Register
public ActionResult Register()
{
return View();
}
//
// POST: /Account/Register
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, "question", "answer", true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
MigrateShoppingCart(model.UserName);
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
//
// GET: /Account/ChangePassword
[Authorize]
public ActionResult ChangePassword()
{
return View();
}
//
// POST: /Account/ChangePassword
[Authorize]
[HttpPost]
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
// ChangePassword will throw an exception rather
// than return false in certain failure scenarios.
bool changePasswordSucceeded;
try
{
MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
}
catch (Exception)
{
changePasswordSucceeded = false;
}
if (changePasswordSucceeded)
{
return RedirectToAction("ChangePasswordSuccess");
}
else
{
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
//
// GET: /Account/ChangePasswordSuccess
public ActionResult ChangePasswordSuccess()
{
return View();
}
#region Status Codes
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
{
// See http://go.microsoft.com/fwlink/?LinkID=177550 for
// a full list of status codes.
switch (createStatus)
{
case MembershipCreateStatus.DuplicateUserName:
return "User name already exists. Please enter a different user name.";
case MembershipCreateStatus.DuplicateEmail:
return "A user name for that e-mail address already exists. Please enter a different e-mail address.";
case MembershipCreateStatus.InvalidPassword:
return "The password provided is invalid. Please enter a valid password value.";
case MembershipCreateStatus.InvalidEmail:
return "The e-mail address provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidAnswer:
return "The password retrieval answer provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidQuestion:
return "The password retrieval question provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidUserName:
return "The user name provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.ProviderError:
return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
case MembershipCreateStatus.UserRejected:
return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
default:
return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.