You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

104 lines
4.9 KiB

using Business.Account;
using Business.Configuration;
using Common.Helper;
using Common.Model.Account;
using Newtonsoft.Json;
using System;
using System.Data;
namespace JMEAgentSystem.WebPages.Account
{
public partial class Login : System.Web.UI.Page
{
private readonly IAccountServices _accountServices = AutoFacContainer.Resolve<IAccountServices>();
protected void Page_Load(object sender, EventArgs e)
{
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 agentUniqueId = Request.Form["AgentUniqueId"];
//if (string.IsNullOrEmpty(agentUniqueId))
//{
// Response.ContentType = "text/plain";
// string errorjson = JsonConvert.SerializeObject(new DbResult { ErrorCode = "1", Msg = "Invalid login attemp!" });
// Response.Write(errorjson);
// Response.End();
//}
LoginModel loginModel = new LoginModel()
{
Password = GetStatic.ReadFormData("Password", ""),
ReferralCode = GetStatic.ReadFormData("ReferralCode", ""),
IpAddress = GetStatic.GetIpAddress(Request),
UserDetails = GetStatic.GetUserInfo(Request),
AgentUniqueId = agentUniqueId
};
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");
}
}
}