// // см. также Global.Application_AuthenticateRequest // public static HtmlResult<HElement> HView(object _state, JsonData[] jsons, HContext context) { var logins = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase){{"Demo", "demodemo"}, {"Test", "test"}}; foreach (var json in jsons.Else_Empty()) { switch (json.JPath("data", "command").ToString_Fair()) { case "login": { var login = json.JPath("data", "login").ToString_Fair(); var password = json.JPath("data", "password").ToString_Fair(); if (logins.Find(login) == password) context.HttpContext.SetUserAndCookie(login); else { //display error } } break; case "logout": context.HttpContext.SetUserAndCookie(null); break; default: break; } if (context.HttpContext.UserName() != null) { switch (json.JPath("data", "command").ToString_Fair()) { case "login": { var login = json.JPath("data", "login").ToString_Fair(); var password = json.JPath("data", "password").ToString_Fair(); if (logins.Find(login) == password) context.HttpContext.SetUserAndCookie(login); else { //display error } } break; case "logout": context.HttpContext.SetUserAndCookie(null); break; default: break; } } } var account = context.HttpContext.UserName(); var page = Page(logins, account); return new HtmlResult<HElement> { Html = page, State = null, }; }