Advertisement
HenX

LOGIN

Dec 19th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1.   [System.Web.Mvc.HttpPost]
  2.         [ValidateAntiForgeryToken]
  3.         [System.Web.Mvc.ActionName("Prihlaseni")]
  4.         public ActionResult Prihlaseni([Bind(Include = "Email, Password")] User model, string returnUrl)
  5.         {
  6.             try
  7.             {
  8.                 User userToFind = context.Users.Where(m => m.Email.ToLower() == model.Email.ToLower()).FirstOrDefault();
  9.                 if (model != null && userToFind != null)
  10.                 {
  11.  
  12.                     string hash = new MD5Cryptor().GetMd5Hash(model.Password + userToFind.Salt);
  13.                     if (userToFind.PasswordHash == hash)
  14.                     {
  15.                         FormsAuthentication.SetAuthCookie(model.Email, false);
  16.  
  17.                         LogWriter.Insert("Přihlášení", String.Format("Uživatel {0} se přihlásil.", model.Email), User);
  18.  
  19.                         string decodedUrl = "";
  20.  
  21.                         if (!string.IsNullOrEmpty(returnUrl))
  22.                             decodedUrl = Server.UrlDecode(returnUrl);
  23.  
  24.                         //Login logic...
  25.  
  26.                         if (Url.IsLocalUrl(decodedUrl))
  27.                         {
  28.                             return Redirect(decodedUrl);
  29.                         }
  30.                         else
  31.                         {
  32.                             return RedirectToAction("Index", "Home");
  33.                         }
  34.                     }
  35.                     else
  36.                     {
  37.                         LogWriter.Insert("Neplatné přihlášení", String.Format("Uživatel {0} zadal špatné heslo.", model.Email), User);
  38.                         ErrorNotification("Neplatné přihlašovací údaje.");
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     LogWriter.Insert("Neplatné přihlášení", String.Format("Uživatel {0} nenalezen.", model.Email), User);
  44.                     ErrorNotification("Neplatné přihlašovací údaje.");
  45.                 }
  46.             }
  47.             catch (InvalidOperationException e)
  48.             {
  49.                 ErrorNotification("Neplatné přihlašovací údaje.");
  50.             }
  51.  
  52.             return View();
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement