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")); } }
// GET: Equipment public async Task <ActionResult> Index() { ViewBag.Version = Global._sfAdminVersion; EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } try { /* Get JSON entiries that Pages need */ RestfulAPIHelper apiHelper = new RestfulAPIHelper(); ViewBag.EquipmentList = await apiHelper.callAPIService("GET", Global._equipmentInCompanyEndPoint, null); ViewBag.EquipmentClassList = await apiHelper.callAPIService("GET", Global._equipmentClassInCompanyEndPoint, null); ViewBag.FactoryList = await apiHelper.callAPIService("GET", Global._factoryInCompanyEndPoint, null); ViewBag.IoTDeviceList = await apiHelper.callAPIService("GET", Global._iotDeviceInCompanyEndPoint, null); /* Setup Company Name and Company Photo on Page */ CompanyModel companyModel = new CompanyModel(); CompanySession compSession = await companyModel.GetCompanySessionData(); ViewBag.CompanyId = compSession.id; ViewBag.CompanyName = compSession.shortName; ViewBag.CompanyPhotoURL = compSession.photoURL; /* Setup Employee Data on Page */ ViewBag.FirstName = empSession.firstName; ViewBag.LastName = empSession.lastName; ViewBag.Email = empSession.email; ViewBag.PhotoURL = empSession.photoURL; ViewBag.PermissionList = empSession.permissions; /* Setup Menu Item Active */ ViewBag.MenuNavigation = empSession.navigationMenu; ViewBag.MenuItem = "menuEquipment"; } 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")); } return(View()); }