Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.95 KB | None | 0 0
  1. @{
  2.     // Set the layout page and page title
  3.     Layout = "~/_SiteLayout.cshtml";
  4.     Page.Title = "Log In";
  5.  
  6.     // Initialize general page variables
  7.     var username = "";
  8.     var password = "";
  9.     var rememberMe = false;
  10.  
  11.     // Validation
  12.     var isValid = true;
  13.     var usernameErrorMessage = "";
  14.     var passwordErrorMessage = "";
  15.  
  16.     // If this is a POST request, validate and process data
  17.     if (IsPost) {
  18.         username = Request.Form["username"];
  19.         password = Request.Form["password"];
  20.         rememberMe = Request.Form["rememberMe"].AsBool();
  21.  
  22.         // Validate the user's username
  23.         if (username.IsEmpty()) {
  24.             usernameErrorMessage = "You must specify a username.";
  25.             isValid = false;
  26.         }
  27.  
  28.         // Validate the user's password
  29.         if (password.IsEmpty()) {
  30.             passwordErrorMessage = "You must specify a password.";
  31.             isValid = false;
  32.         }
  33.  
  34.         // Confirm there are no validation errors
  35.         if (isValid) {
  36.             if (WebSecurity.UserExists(username) && WebSecurity.GetPasswordFailuresSinceLastSuccess(username) > 4 && WebSecurity.GetLastPasswordFailureDate(username).AddSeconds(60) > DateTime.UtcNow ) {
  37.                Response.Redirect("~/account/AccountLockedOut");
  38.                 return;
  39.             }
  40.  
  41.             // Attempt to login to the Security object using provided creds
  42.             if (WebSecurity.Login(username, password, rememberMe)) {
  43.                 var returnUrl = Request.QueryString["ReturnUrl"];
  44.                 if (returnUrl.IsEmpty()){
  45.                     Response.Redirect("~/");
  46.                 } else {
  47.                     Context.RedirectLocal(returnUrl);
  48.                 }
  49.             }
  50.  
  51.             // If we arrived here, the login failed; convey that to the user
  52.             isValid = false;
  53.         }    
  54.     }
  55. }
  56.  
  57. <p>
  58.    Please enter your username and password below. If you don't have an account,
  59.    visit the <a href="@Href("~/Account/Register")">registration page</a> and create one.
  60. </p>
  61.  
  62. @* If one or more validation errors exist, show an error *@
  63. @if (!isValid) {
  64.    <p class="message error">There was a problem with your login and/or errors exist in your form.</p>
  65. }
  66.  
  67. <form method="post" action="">
  68.     <fieldset>
  69.         <legend>Log In to Your Account</legend>
  70.         <ol>
  71.             <li class="username">
  72.                 <label for="username">Username:</label>
  73.                 <input type="text" id="username" name="username" value="@username" title="Username" @if(!usernameErrorMessage.IsEmpty()){<text>class="error-field"</text>} />
  74.                 @* Write any username validation errors to the page *@
  75.                 @if (!usernameErrorMessage.IsEmpty()) {
  76.                 <label for="username" class="validation-error">
  77.                     @usernameErrorMessage
  78.                 </label>
  79.                 }
  80.             </li>
  81.             <li class="password">
  82.                 <label for="password">Password:</label>
  83.                 <input type="password" id="password" name="password" title="Password" @if(!passwordErrorMessage.IsEmpty()){<text>class="error-field"</text>} />
  84.                 @* Write any password validation errors to the page *@
  85.                 @if (!passwordErrorMessage.IsEmpty()) {
  86.                 <label for="password" class="validation-error">
  87.                     @passwordErrorMessage
  88.                 </label>
  89.                 }
  90.             </li>
  91.             <li class="remember-me">
  92.                 <label class="checkbox" for="rememberMe">Remember Me?</label>
  93.                 <input type="checkbox" id="rememberMe" name="rememberMe" value="true" title="Remember Me" @if(rememberMe){<text>checked="checked"</text>} />
  94.             </li>
  95.         </ol>
  96.         <p class="form-actions">
  97.             <input type="submit" value="login" title="Login"/>
  98.         </p>
  99.         <p><a href="@Href("~/Account/ForgotPassword")">Did you forget your password?</a></p>
  100.     </fieldset>
  101. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement