118 lines
3.9 KiB
C#
118 lines
3.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Security;
|
|
|
|
using BeWoPlanerMobil.Service;
|
|
using BeWoPlanerMobil.Util;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using RestSharp;
|
|
using HttpCookie = System.Web.HttpCookie;
|
|
|
|
|
|
namespace BeWoPlanerMobil.Controllers
|
|
{
|
|
public class LoginController : AbstractBaseController
|
|
{
|
|
public static string LoginErrorIndex => "LoginErrorIndex";
|
|
|
|
[HttpPost]
|
|
public ActionResult Index()
|
|
{
|
|
ViewData[LoginErrorIndex] = string.Empty;
|
|
|
|
if (MobileSessionFacade.IsUserLoggedIn() && !Request.Browser.Browser.Equals("InternetExplorer"))
|
|
{
|
|
var loginState = MobileUtils.GetLoginState(MobileSessionFacade.Tenant);
|
|
|
|
if (loginState.Message != null && loginState.State > -1)
|
|
{
|
|
TempData[MobileUtils.TempDataLoginStateKey] = loginState;
|
|
}
|
|
|
|
Log.Info($"LoginController.Index(): Loggedin User: {MobileSessionFacade.LoggedInUser.LoginName}");
|
|
|
|
if (!MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_View))) &&
|
|
!MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ViewAll))))
|
|
{
|
|
ViewData[LoginErrorIndex] = HttpUtility.HtmlDecode("Sie haben keine ausreichenden Berechtigungen, um die Zeiterfassung anzeigen zu lassen.");
|
|
MobileSessionFacade.LogUserOut();
|
|
FormsAuthentication.SignOut();
|
|
return View("Index");
|
|
}
|
|
|
|
FormsAuthentication.SetAuthCookie(MobileSessionFacade.LoggedInUser.LoginName, true);
|
|
ViewData[LoginErrorIndex] = string.Empty;
|
|
|
|
var keks = new HttpCookie("tenantKeks") { Value = MobileSessionFacade.Tenant, Expires = DateTime.Now.AddDays(1) };
|
|
HttpContext.Response.SetCookie(keks);
|
|
|
|
var brauser = Request.Browser;
|
|
var brauserInfoDC = new BeWoMobilBrowserInfoDC
|
|
{
|
|
Type = brauser.Type,
|
|
Name = brauser.Browser,
|
|
BrowserVersion = brauser.Version,
|
|
Platform = brauser.Platform,
|
|
Tenant = MobileSessionFacade.Tenant
|
|
};
|
|
|
|
BS.Shared.Core.Utils.WriteToLogFile("Browser_Info.txt", $"{brauser.Browser} {brauser.Version}");
|
|
|
|
OperationsService.InsertBeWoMobilBrowserInfo(brauserInfoDC);
|
|
|
|
return RedirectToActionPermanent("Main", "Main");
|
|
}
|
|
|
|
if(MobileSessionFacade.IsUserLoggedIn() && Request.Browser.Browser.Equals("InternetExplorer"))
|
|
{
|
|
MobileSessionFacade.LogUserOut();
|
|
FormsAuthentication.SignOut();
|
|
}
|
|
|
|
Log.Info($"LoginController.Index(): Login failed! Tenant = {MobileSessionFacade.Tenant}");
|
|
|
|
ViewData[LoginErrorIndex] = Request.Browser.Browser.Equals("InternetExplorer") ?
|
|
"Dieser Browser ist nicht mit dem mobilen BeWoPlaner komptatibel. Bitte benutzen Sie einen anderen Browser als den Internet Explorer." :
|
|
"Die Anmeldung ist fehlgeschlagen. Bitte überprüfen Sie Benutzername und Passwort.";
|
|
|
|
return View("Index");
|
|
}
|
|
|
|
public ActionResult Index(string tenant, string returnUrl)
|
|
{
|
|
if (returnUrl != null)
|
|
{
|
|
return RedirectToAction("Index", new {tenant = MobileSessionFacade.Tenant});
|
|
}
|
|
|
|
if (tenant == null)
|
|
{
|
|
var keks = HttpContext.Request.Cookies.Get("tenantKeks");
|
|
|
|
if(keks != null)
|
|
{
|
|
tenant = keks.Value;
|
|
}
|
|
}
|
|
|
|
if (MobileSessionFacade.IsUserLoggedIn())
|
|
{
|
|
//https://support.bewoplaner.de/api/getstate.php?k=[KUNDENNUMMER]&type=1
|
|
|
|
var baseUrl = "https://support.bewoplaner.de/api/getstate.php";
|
|
|
|
var client = new RestClient(baseUrl);
|
|
var request = new RestRequest();
|
|
|
|
return RedirectToActionPermanent("Main", "Main");
|
|
}
|
|
|
|
MobileSessionFacade.Tenant = tenant;
|
|
return View("Index");
|
|
}
|
|
}
|
|
}
|