using Business.Account; using Business.Configuration; using Common.Helper; using Common.Model.Account; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Web; namespace JMEAgentSystem.WebPages.Account { public partial class Login : System.Web.UI.Page { private readonly IAccountServices _accountServices = AutoFacContainer.Resolve(); protected string _agentPlatform; protected string _agentPlatformId; protected void Page_Load(object sender, EventArgs e) { _agentPlatform = HttpContext.Current.Request.Headers.Get("Agent-Platform"); _agentPlatformId = HttpContext.Current.Request.Headers.Get("Agent-Platform-Id"); var methodName = GetStatic.ReadFormData("MethodName", ""); var isLogout = Convert.ToBoolean(GetStatic.ReadQueryString("isLogout", "false")); if (methodName.Equals("login")) SystemLogin(); if (isLogout == true) { Logout(); } CheckRememberMe(); } private void CheckRememberMe() { string dt = DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Year.ToString(); var userData = GetStatic.ReadCookie("JME_Agent_System_UserData_" + dt, ""); if (!string.IsNullOrEmpty(userData)) { string[] userDatas = userData.Split('|'); referralCode.Text = userDatas[0]; password.Attributes.Add("value", userDatas[1]); checkbox_signup.Checked = true; } } protected void SystemLogin() { var agentPlatform = HttpContext.Current.Request.Headers.Get("Agent-Platform"); var agentPlatformId = HttpContext.Current.Request.Headers.Get("Agent-Platform-Id"); LoginModel loginModel = new LoginModel() { Password = GetStatic.ReadFormData("Password", ""), ReferralCode = GetStatic.ReadFormData("ReferralCode", ""), IpAddress = GetStatic.GetIpAddress(Request), UserDetails = GetStatic.GetUserInfo(Request), AgentPlatform = agentPlatform, AgentPlatformId = agentPlatformId }; bool RememberMe = Convert.ToBoolean(GetStatic.ReadFormData("RememberMe", "false")); DataSet ds = _accountServices.LoginSystem(loginModel); var result = GetStatic.ParseDbResult(ds.Tables[0]); if (result.ResponseCode == "0") { GetStatic.WriteSession("admin", ds.Tables[1].Rows[0]["REFERRAL_CODE"].ToString()); GetStatic.WriteSession("agentName", ds.Tables[1].Rows[0]["REFERRAL_NAME"].ToString()); GetStatic.WriteSession("agentAddress", ds.Tables[1].Rows[0]["REFERRAL_ADDRESS"].ToString()); GetStatic.WriteSession("agentMobile", ds.Tables[1].Rows[0]["REFERRAL_MOBILE"].ToString()); GetStatic.WriteSession("agentEmail", ds.Tables[1].Rows[0]["REFERRAL_EMAIL"].ToString()); GetStatic.WriteSession("agentAssignedBranch", ds.Tables[1].Rows[0]["AGENTNAME"].ToString()); GetStatic.WriteSession("agentType", ds.Tables[1].Rows[0]["REFERRAL_TYPE_CODE"].ToString()); GetStatic.WriteSession("agentLimit", ds.Tables[1].Rows[0]["REFERRAL_LIMIT"].ToString()); GetStatic.WriteSession("agentId", ds.Tables[1].Rows[0]["BRANCH_ID"].ToString()); GetStatic.WriteSession("isForceChangePassword", ds.Tables[1].Rows[0]["FORCE_CHANGE_PWD"].ToString()); GetStatic.WriteSession("countryId","113"); if (!string.IsNullOrEmpty(GetStatic.ReadCookie("JME_Agent_System_UserData_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.AddDays(-1).Day.ToString() + "_" + DateTime.Now.Year.ToString(), ""))) { GetStatic.DeleteCookie("JME_Agent_System_UserData_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.AddDays(-1).Day.ToString() + "_" + DateTime.Now.Year.ToString()); } string dt = DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Year.ToString(); if (RememberMe) GetStatic.WriteCookie("JME_Agent_System_UserData_" + dt, loginModel.ReferralCode + "|" + loginModel.Password); else GetStatic.DeleteCookie("JME_Agent_System_UserData_" + dt); } Response.ContentType = "text/plain"; string json = JsonConvert.SerializeObject(result); Response.Write(json); Response.End(); } private void Logout() { Session.Clear(); Session.Abandon(); Response.Redirect("/Webpages/Account/Login"); } } }