public ActionResult SetLanguage(string langtag, string returnUrl) { if (langtag == null) { langtag = "en"; } // If valid 'langtag' passed. i18n.LanguageTag lt = i18n.LanguageTag.GetCachedInstance(langtag); EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); empSession.Lang = langtag; Session["empSession"] = empSession.Serialize(); } if (lt.IsValid()) { // Set persistent cookie in the client to remember the language choice. Response.Cookies.Add(new HttpCookie("i18n.langtag") { Value = lt.ToString(), HttpOnly = true, Expires = DateTime.UtcNow.AddYears(1) }); } // Owise...delete any 'language' cookie in the client. else { var cookie = Response.Cookies["i18n.langtag"]; if (cookie != null) { cookie.Value = null; cookie.Expires = DateTime.UtcNow.AddMonths(-1); } } // Update PAL setting so that new language is reflected in any URL patched in the // response (Late URL Localization). System.Web.HttpContext.Current.SetPrincipalAppLanguageForRequest(lt); // Patch in the new langtag into any return URL. if (returnUrl.IsSet()) { returnUrl = LocalizedApplication.Current.UrlLocalizerForApp.SetLangTagInUrlPath(HttpContext, returnUrl, UriKind.RelativeOrAbsolute, lt == null ? null : lt.ToString()).ToString(); } // Redirect user agent as approp. return(Json(new { status = "success", NewURL = returnUrl })); }
public async Task <ActionResult> DoLogin() { if (Request.Form["email"] != null && Request.Form["password"] != null) { EmployeeSession empSession = new EmployeeSession(); empSession.email = Request.Form["email"]; empSession.password = Request.Form["password"]; if (Request.Form["rememberMe"] != null) { empSession.rememberMe = true; } else { empSession.rememberMe = false; } Session["empSession"] = empSession.Serialize(); return(await GetAuthenticationToken()); } return(View("Login")); }
public async Task <ActionResult> LoginBySA() { EmployeeSession empSession = new EmployeeSession(); try { string inputCredential = Request.Form["inputCredential"]; var inputCredentialByte = System.Convert.FromBase64String(inputCredential); string inputCredentialString = System.Text.Encoding.UTF8.GetString(inputCredentialByte); string[] credential = inputCredentialString.Split(':'); empSession.email = credential[0]; empSession.password = credential[1]; empSession.companyId = int.Parse(Request.Form["inputCompanyId"]); empSession.adminFlag = true; Session["empSession"] = empSession.Serialize(); Session["loginBySA"] = true; /* Set Company Entity */ RestfulAPIHelper apiHelper = new RestfulAPIHelper(); string CompanyEntiry = await apiHelper.callAPIService("GET", Global._companyEndPoint, null); dynamic companyObj = JObject.Parse(CompanyEntiry); CompanySession compSession = new CompanySession(); if (companyObj.ShortName != null) { compSession.shortName = companyObj.ShortName; } else { compSession.shortName = companyObj.Name; } compSession.name = companyObj.Name; compSession.photoURL = companyObj.LogoURL; compSession.id = companyObj.Id; compSession.lat = companyObj.Latitude; compSession.lng = companyObj.Longitude; Session["compSession"] = compSession.Serialize(); /* Get User Authentication */ return(await GetAuthenticationToken()); } catch (Exception ex) { LoginMsgSession loginMsgSession = new LoginMsgSession(); if (ex.Message.ToLower() == "invalid session") { loginMsgSession.toastLevel = "warning"; loginMsgSession.message = "[[[Please Login]]]"; } else { loginMsgSession.toastLevel = "error"; loginMsgSession.message = "[[[Authentication Fail]]]."; StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("audit: Authentication Fail."); logMessage.AppendLine("email:" + empSession.email); logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize(); return(RedirectToAction("Index", "Home")); } }