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.

92 lines
4.4 KiB

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. LoginModel loginModel = new LoginModel()
  40. {
  41. Password = GetStatic.ReadFormData("Password", ""),
  42. ReferralCode = GetStatic.ReadFormData("ReferralCode", ""),
  43. IpAddress = GetStatic.GetIpAddress(Request),
  44. UserDetails = GetStatic.GetUserInfo(Request)
  45. };
  46. bool RememberMe = Convert.ToBoolean(GetStatic.ReadFormData("RememberMe", "false"));
  47. DataSet ds = _accountServices.LoginSystem(loginModel);
  48. var result = GetStatic.ParseDbResult(ds.Tables[0]);
  49. if (result.ResponseCode == "0")
  50. {
  51. GetStatic.WriteSession("admin", ds.Tables[1].Rows[0]["REFERRAL_CODE"].ToString());
  52. GetStatic.WriteSession("agentName", ds.Tables[1].Rows[0]["REFERRAL_NAME"].ToString());
  53. GetStatic.WriteSession("agentAddress", ds.Tables[1].Rows[0]["REFERRAL_ADDRESS"].ToString());
  54. GetStatic.WriteSession("agentMobile", ds.Tables[1].Rows[0]["REFERRAL_MOBILE"].ToString());
  55. GetStatic.WriteSession("agentEmail", ds.Tables[1].Rows[0]["REFERRAL_EMAIL"].ToString());
  56. GetStatic.WriteSession("agentAssignedBranch", ds.Tables[1].Rows[0]["AGENTNAME"].ToString());
  57. GetStatic.WriteSession("agentType", ds.Tables[1].Rows[0]["REFERRAL_TYPE_CODE"].ToString());
  58. GetStatic.WriteSession("agentLimit", ds.Tables[1].Rows[0]["REFERRAL_LIMIT"].ToString());
  59. GetStatic.WriteSession("agentId", ds.Tables[1].Rows[0]["BRANCH_ID"].ToString());
  60. GetStatic.WriteSession("isForceChangePassword", ds.Tables[1].Rows[0]["FORCE_CHANGE_PWD"].ToString());
  61. GetStatic.WriteSession("countryId","113");
  62. if (!string.IsNullOrEmpty(GetStatic.ReadCookie("JME_Agent_System_UserData_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.AddDays(-1).Day.ToString() + "_" + DateTime.Now.Year.ToString(), "")))
  63. {
  64. GetStatic.DeleteCookie("JME_Agent_System_UserData_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.AddDays(-1).Day.ToString() + "_" + DateTime.Now.Year.ToString());
  65. }
  66. string dt = DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Year.ToString();
  67. if (RememberMe)
  68. GetStatic.WriteCookie("JME_Agent_System_UserData_" + dt, loginModel.ReferralCode + "|" + loginModel.Password);
  69. else
  70. GetStatic.DeleteCookie("JME_Agent_System_UserData_" + dt);
  71. }
  72. Response.ContentType = "text/plain";
  73. string json = JsonConvert.SerializeObject(result);
  74. Response.Write(json);
  75. Response.End();
  76. }
  77. private void Logout()
  78. {
  79. Session.Clear();
  80. Session.Abandon();
  81. Response.Redirect("/Webpages/Account/Login");
  82. }
  83. }
  84. }