Example #1
0
        public ActionResult Login(string username, string password)
        {
            var credential = CredentialService.QueryCredentialByUsernameByPassword(username, password);

            if (credential == null)
            {
                return(Json(new { state = "error", message = "Invalid username and password combination" }, JsonRequestBehavior.AllowGet));
            }
            var appUserId = (Guid)credential.FirstOrDefault(x => x.Key == "AppUserId").Value;

            if (appUserId == Guid.Empty)
            {
                return(Json(new { state = "error", message = "Invalid username and password combination" }, JsonRequestBehavior.AllowGet));
            }

            var appUser = AppUserService.QueryAppUserById(appUserId);

            AccountService.SetCookie(Response, appUser);

            return(Json(new { state = "success", appUser = appUser }, JsonRequestBehavior.AllowGet));
        }