HomeController.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Diagnostics;
  3. using System.ServiceModel;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Configuration;
  7. using ReportWeb;
  8. using ReportWeb.Models;
  9. using SuperAdmin.Models;
  10. using SuperAdmin.Models.Http;
  11. using SuperAdmin.Models.Vsa;
  12. using SuperAdmin.Source;
  13. using SuperCms.Extensions;
  14. using SvVsa;
  15. namespace SuperAdmin.Controllers
  16. {
  17. public class HomeController : BaseController
  18. {
  19. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  20. DbConnector db = new DbConnector();
  21. public static int counter = 0;
  22. public static bool counterStart = false;
  23. public static string serviceName;
  24. //public static string subDomain;
  25. public HomeController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
  26. {
  27. // init
  28. }
  29. public IActionResult Index()
  30. {
  31. serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
  32. //subDomain = GetParameter(UtilsController.Constant.SUB_DOMAIN);
  33. HttpContext.Session.SetComplexData("serviceName", serviceName);
  34. HttpContext.Session.SetComplexData("subDomain", BaseController.subDomain);
  35. if (!CheckAuthToken())
  36. {
  37. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  38. }
  39. return View();
  40. }
  41. [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  42. public IActionResult Error()
  43. {
  44. return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  45. }
  46. public IActionResult Login()
  47. {
  48. return View();
  49. }
  50. public IActionResult LoginAction(String account, String password)
  51. {
  52. var rs = db.GetUserByName(account);
  53. if (rs == null || rs.Count == 0)
  54. {
  55. ViewBag.username = "Welcome!";
  56. ViewBag.content = "Authen failed";
  57. return View("Login");
  58. }
  59. Users user = rs[0];
  60. // check password
  61. if (user.password != Common.EncryptPassword(account, password))
  62. {
  63. ViewBag.username = "Welcome!";
  64. ViewBag.content = "Authen failed";
  65. return View("Login");
  66. }
  67. // success
  68. CreateAuthToken(account, user);
  69. ViewBag.errorMessageCss = "none";
  70. string displayName = account;
  71. ViewBag.username = "Welcome, " + displayName;
  72. return Redirect(subDomain + "/Admin/Index");
  73. }
  74. public IActionResult Logout()
  75. {
  76. try
  77. {
  78. ClearCache();
  79. return View("Login");
  80. }
  81. catch (Exception ex)
  82. {
  83. log.Error("Exception " + ex);
  84. return Redirect(subDomain + "/Shared/Error");
  85. }
  86. }
  87. }
  88. }