Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.67 KB | None | 0 0
  1. [<HttpPost>]
  2. member x.Login (viewModel:LoginViewModel) =
  3.     if String.IsNullOrWhiteSpace viewModel.UserName || String.IsNullOrWhiteSpace viewModel.Password then
  4.         x.ModelState.AddModelError("", "Incorrect username or password")
  5.  
  6.     if x.ModelState.IsValid then
  7.         let userToGet = ctx.Users |> Seq.tryFind(fun z -> z.UserName = viewModel.UserName && z.Password = viewModel.Password)
  8.  
  9.         match userToGet with
  10.         | Some u ->
  11.             FormsAuthentication.SetAuthCookie(u.UserName, false)
  12.             x.RedirectToAction "index" :> ActionResult
  13.         | None -> HttpNotFoundResult() :> ActionResult
  14.  
  15.     else x.View("login", viewModel) :> ActionResult
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement