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.

103 lines
4.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. using Business.Account;
  2. using Business.Configuration;
  3. using Common.Helper;
  4. using Common.Model.Account;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Data;
  8. namespace JMEAgentSystem.WebPages.Account
  9. {
  10. public partial class Login : System.Web.UI.Page
  11. {
  12. private readonly IAccountServices _accountServices = AutoFacContainer.Resolve<IAccountServices>();
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. var methodName = GetStatic.ReadFormData("MethodName", "");
  16. var isLogout = Convert.ToBoolean(GetStatic.ReadQueryString("isLogout", "false"));
  17. if (methodName.Equals("login"))
  18. SystemLogin();
  19. if (isLogout == true)
  20. {
  21. Logout();
  22. }
  23. //CheckRememberMe();
  24. }
  25. private void CheckRememberMe()
  26. {
  27. string dt = DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Year.ToString();
  28. var userData = GetStatic.ReadCookie("JME_Agent_System_UserData_" + dt, "");
  29. if (!string.IsNullOrEmpty(userData))
  30. {
  31. string[] userDatas = userData.Split('|');
  32. referralCode.Text = userDatas[0];
  33. password.Attributes.Add("value", userDatas[1]);
  34. checkbox_signup.Checked = true;
  35. }
  36. }
  37. protected void SystemLogin()
  38. {
  39. var agentUniqueId = Request.Form["AgentUniqueId"];
  40. //if (string.IsNullOrEmpty(agentUniqueId))
  41. //{
  42. // Response.ContentType = "text/plain";
  43. // string errorjson = JsonConvert.SerializeObject(new DbResult { ErrorCode = "1", Msg = "Invalid login attemp!" });
  44. // Response.Write(errorjson);
  45. // Response.End();
  46. //}
  47. LoginModel loginModel = new LoginModel()
  48. {
  49. Password = GetStatic.ReadFormData("Password", ""),
  50. ReferralCode = GetStatic.ReadFormData("ReferralCode", ""),
  51. IpAddress = GetStatic.GetIpAddress(Request),
  52. UserDetails = GetStatic.GetUserInfo(Request),
  53. AgentUniqueId = agentUniqueId
  54. };
  55. bool RememberMe = Convert.ToBoolean(GetStatic.ReadFormData("RememberMe", "false"));
  56. DataSet ds = _accountServices.LoginSystem(loginModel);
  57. var result = GetStatic.ParseDbResult(ds.Tables[0]);
  58. if (result.ResponseCode == "0")
  59. {
  60. GetStatic.WriteSession("admin", ds.Tables[1].Rows[0]["REFERRAL_CODE"].ToString());
  61. GetStatic.WriteSession("agentName", ds.Tables[1].Rows[0]["REFERRAL_NAME"].ToString());
  62. GetStatic.WriteSession("agentAddress", ds.Tables[1].Rows[0]["REFERRAL_ADDRESS"].ToString());
  63. GetStatic.WriteSession("agentMobile", ds.Tables[1].Rows[0]["REFERRAL_MOBILE"].ToString());
  64. GetStatic.WriteSession("agentEmail", ds.Tables[1].Rows[0]["REFERRAL_EMAIL"].ToString());
  65. GetStatic.WriteSession("agentAssignedBranch", ds.Tables[1].Rows[0]["AGENTNAME"].ToString());
  66. GetStatic.WriteSession("agentType", ds.Tables[1].Rows[0]["REFERRAL_TYPE_CODE"].ToString());
  67. GetStatic.WriteSession("agentLimit", ds.Tables[1].Rows[0]["REFERRAL_LIMIT"].ToString());
  68. GetStatic.WriteSession("agentId", ds.Tables[1].Rows[0]["BRANCH_ID"].ToString());
  69. GetStatic.WriteSession("isForceChangePassword", ds.Tables[1].Rows[0]["FORCE_CHANGE_PWD"].ToString());
  70. GetStatic.WriteSession("countryId","113");
  71. if (!string.IsNullOrEmpty(GetStatic.ReadCookie("JME_Agent_System_UserData_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.AddDays(-1).Day.ToString() + "_" + DateTime.Now.Year.ToString(), "")))
  72. {
  73. GetStatic.DeleteCookie("JME_Agent_System_UserData_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.AddDays(-1).Day.ToString() + "_" + DateTime.Now.Year.ToString());
  74. }
  75. string dt = DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Year.ToString();
  76. if (RememberMe)
  77. GetStatic.WriteCookie("JME_Agent_System_UserData_" + dt, loginModel.ReferralCode + "|" + loginModel.Password);
  78. else
  79. GetStatic.DeleteCookie("JME_Agent_System_UserData_" + dt);
  80. }
  81. Response.ContentType = "text/plain";
  82. string json = JsonConvert.SerializeObject(result);
  83. Response.Write(json);
  84. Response.End();
  85. }
  86. private void Logout()
  87. {
  88. Session.Clear();
  89. Session.Abandon();
  90. Response.Redirect("/Webpages/Account/Login");
  91. }
  92. }
  93. }