daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Jan 17th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div class="login-wrapper">
  2.         <div id="login" class="login loginpage col-lg-offset-4 col-lg-4 col-md-offset-3 col-md-6 col-sm-offset-3 col-sm-6 col-xs-offset-0 col-xs-12">
  3.             <h1><a href="#" title="Login Page" tabindex="-1">ESH HRMS</a></h1>
  4.  
  5.  
  6.             @using (Html.BeginForm("login", "admin", FormMethod.Post,new { ReturnUrl = ViewBag.ReturnUrl }))
  7.             {
  8.                 @Html.AntiForgeryToken()
  9.                 <p>
  10.                     <label for="user_login">
  11.                         Username<br />
  12.                         @Html.TextBoxFor(m => m.LoginID, new { @class = "input", @id = "txtUserName", @placeholder = "UserName", @size = "20" })
  13.                     </label>
  14.                 </p>
  15.                 <p>
  16.                     <label for="user_pass">
  17.                         Password<br />
  18.                         @Html.TextBoxFor(m => m.Password, new { @class = "input", @id = "txtPassword", type = "password", @size = "20" })
  19.  
  20.                     </label>
  21.                 </p>
  22.                 <p>
  23.                         <div class="g-recaptcha" style="width:130%;" data-sitekey="6LdY2TMUAAAAAEmHk8ZeNF3AwdJ8D92Lm-U3LinQ"></div>
  24.  
  25.                 </p>
  26.                     <p class="forgetmenot">
  27.  
  28.                         <label class="icheck-label form-label" for="rememberme">
  29.                             @Html.CheckBoxFor(m => m.RememberMe, new { @class = "skin-square-orange", @id = "rememberme" })
  30.                             Remember me
  31.                         </label>
  32.                     </p>
  33.  
  34.                     <p class="submit">
  35.                         <input type="submit" name="wp-submit" id="btnSubmit" class="btn btn-orange btn-block" value="Sign In" />
  36.                     </p>
  37.             }
  38.  
  39.             @*<p id="nav">
  40.                 <a class="pull-left" href="#" title="Password Lost and Found">Forgot password?</a>
  41.                 <a class="pull-right" href="ui-register.html" title="Sign Up">Sign Up</a>
  42.             </p>*@
  43.  
  44.  
  45.         </div>
  46.     </div>
  47.    
  48. // POST: /Account/Login
  49.     [HttpPost]
  50.     [AllowAnonymous]
  51.    [ValidateAntiForgeryToken]
  52.     public ActionResult Login(LoginViewModel model, string returnUrl)
  53.     {
  54.         try
  55.         {
  56.             if (!ModelState.IsValid)
  57.                 return View(model);
  58.             if (ValidateHuman())
  59.             {
  60.                 string loginID = model.LoginID.ToUpper().TrimEnd();
  61.                 string password = model.Password;
  62.                 string hashedPassword = AccountManager.PassEncrypt(password);
  63.                 HRMSEntities db = new HRMSEntities();
  64.                 db.Configuration.ValidateOnSaveEnabled = false;
  65.                 db.SaveChanges();
  66.                 bool userExist = db.LetoUsers.Any(x => x.Suspend == 0 && x.Username.ToLower().TrimEnd() == loginID && x.CompanyId == Utility.CompanyID);
  67.                 if (userExist && (string.Compare(hashedPassword, db.LetoUsers.First(x => x.Suspend == 0 && x.Username.ToLower().TrimEnd() == loginID && x.CompanyId == Utility.CompanyID).Password.ToString()) == 0))
  68.                 {
  69.                     // var user = db.LetoUsers.Where(x => x.Suspend == 0 && x.Username.ToLower().TrimEnd() == loginID && x.CompanyId == Utility.CompanyID && x.Password == hashedPassword).FirstOrDefault(); original
  70.                    var user = db.LetoUsers.Where(x => x.Suspend == 0 && x.Username.ToLower().TrimEnd() == loginID && x.CompanyId == Utility.CompanyID).FirstOrDefault();
  71.                     var emp = db.Employees.SingleOrDefault(x => x.Suspend == 0 && x.Status == 1 && x.AlternateEmployeeCode == user.EmployeeCode && x.CompanyId == Utility.CompanyID);
  72.  
  73.  
  74.                     //---- Generate Authentication Ticket
  75.                     DateTime cookieIssuedDate = DateTime.UtcNow;
  76.                     LoggedInUser loginUser = new LoggedInUser();
  77.                     loginUser.EmpID = Convert.ToInt32(emp.EmployeeId);
  78.                     loginUser.UserID = user.LetoUserId;
  79.                     loginUser.UserTypeID = Convert.ToInt32(user.UserTypeId);
  80.  
  81.                     loginUser.UserName = user.Username;
  82.  
  83.                     loginUser.EmployeeCode = user.EmployeeCode;
  84.                     loginUser.EmployeeName = emp.FirstName;
  85.                     //FormsAuthentication.SetAuthCookie(user.Username, model.RememberMe);
  86.                     //Session["UserType"] = Convert.ToInt32(user.UserTypeId);
  87.                     //Session["UserID"] = user.LetoUserId;
  88.                     //Session["EmployeeCode"] = user.EmployeeCode;
  89.                     //Session["UserName"] = user.Username;
  90.                     // Getting New Guid
  91.                     //string guid = Convert.ToString(Guid.NewGuid());
  92.                     ////Storing new Guid in Session
  93.                     //Session["AuthenticationToken"] = guid;
  94.                     ////Adding Cookie in Browser
  95.                     //Response.Cookies.Add(new HttpCookie("AuthenticationToken", guid));
  96.                     string userData = JsonConvert.SerializeObject(loginUser);
  97.  
  98.                     var ticket = new FormsAuthenticationTicket(0,
  99.                         model.LoginID,
  100.                         cookieIssuedDate,
  101.                         cookieIssuedDate.AddMinutes(30),// (model.RememberMe) ? cookieIssuedDate.AddDays(7) : cookieIssuedDate.AddMinutes(30),//FormsAuthentication.Timeout.TotalMinutes),
  102.                         model.RememberMe,
  103.                         userData,
  104.                         FormsAuthentication.FormsCookiePath);
  105.  
  106.  
  107.                     string encryptedCookieContent = FormsAuthentication.Encrypt(ticket);
  108.  
  109.                     var formsAuthenticationTicketCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedCookieContent)
  110.                     {
  111.                         Domain = FormsAuthentication.CookieDomain,
  112.                         Path = FormsAuthentication.FormsCookiePath,
  113.                         HttpOnly = true,
  114.                         Secure = FormsAuthentication.RequireSSL
  115.                     };
  116.  
  117.                     // ---- if remember me is checked then the cookie will expire after 7 days else at end of session
  118.                     if (model.RememberMe)
  119.                         formsAuthenticationTicketCookie.Expires = cookieIssuedDate.AddDays(7);
  120.  
  121.                     System.Web.HttpContext.Current.Response.Cookies.Add(formsAuthenticationTicketCookie);
  122.                     return RedirectToAction("UserDashBoard");
  123.                 }
  124.                 else
  125.                 {
  126.                     TempData["Error"] = "please enter correct username/password..!!";
  127.                 }
  128.             }
  129.             else {
  130.                 TempData["Error"] = "Incorrect Captcha..!!";
  131.             }
  132.         }
  133.         catch (Exception ex)
  134.         {
  135.  
  136.         }
  137.  
  138.         // If we got this far, something failed, redisplay form
  139.         //ModelState.AddModelError("", "The user name or password provided is incorrect.");
  140.         return View(model);
  141.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top