| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Diagnostics;
- using System.ServiceModel;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using ReportWeb;
- using ReportWeb.Models;
- using SuperAdmin.Models;
- using SuperAdmin.Models.Http;
- using SuperAdmin.Models.Vsa;
- using SuperAdmin.Source;
- using SuperCms.Extensions;
- using SvVsa;
- namespace SuperAdmin.Controllers
- {
- public class HomeController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- DbConnector db = new DbConnector();
- public static int counter = 0;
- public static bool counterStart = false;
- public static string serviceName;
- //public static string subDomain;
- public HomeController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- // init
- }
- public IActionResult Index()
- {
- serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
- //subDomain = GetParameter(UtilsController.Constant.SUB_DOMAIN);
- HttpContext.Session.SetComplexData("serviceName", serviceName);
- HttpContext.Session.SetComplexData("subDomain", BaseController.subDomain);
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- return View();
- }
- [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
- public IActionResult Error()
- {
- return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
- }
- public IActionResult Login()
- {
- return View();
- }
- public IActionResult LoginAction(String account, String password)
- {
- var rs = db.GetUserByName(account);
- if (rs == null || rs.Count == 0)
- {
- ViewBag.username = "Welcome!";
- ViewBag.content = "Authen failed";
- return View("Login");
- }
- Users user = rs[0];
- // check password
- if (user.password != Common.EncryptPassword(account, password))
- {
- ViewBag.username = "Welcome!";
- ViewBag.content = "Authen failed";
- return View("Login");
- }
- // success
- CreateAuthToken(account, user);
- ViewBag.errorMessageCss = "none";
- string displayName = account;
- ViewBag.username = "Welcome, " + displayName;
- return Redirect(subDomain + "/Admin/Index");
- }
- public IActionResult Logout()
- {
- try
- {
- ClearCache();
- return View("Login");
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(subDomain + "/Shared/Error");
- }
- }
- }
- }
|