Example #1
0
        public ActionResult SubmitSite(SiteSelectionViewModel model)
        {
            var redirMsg = $"Redirecting to {Url.Action("Signin", "Account")}.";
            var selectedSiteIsUnusable = string.IsNullOrWhiteSpace(model.SelectedSite);

            if (!ModelState.IsValid || selectedSiteIsUnusable)
            {
                LogError($"Model state is not valid or submitted site is null or whitespace. {redirMsg}");
                return(RedirectToAction("Signin", "Account"));
            }

            if (!IsLoginDataAvailable)
            {
                LogError($"Login data not available in session or the stored object is null. {redirMsg}");
                return(RedirectToAction("Signin", "Account"));
            }

            SigninResponse signinResponse;

            CurrentLoginData.SelectedSite = model.SelectedSite;

            LogMessage($"Signing in to {CurrentLoginData.SelectedSite}");

            if (CurrentLoginData.SelectedSite != TsCurrentSiteName)
            {
                if (TsUserToken != null)
                {
                    LogMessage($"User {TsUserName} was logged in before as user token was found. Going with switch site API method.");
                    signinResponse = _tService.TrySwitchSite(CurrentLoginData.Username, CurrentLoginData.SelectedSite, TsUserToken);
                }
                else
                {
                    LogMessage($"Token not found for user {TsUserName}. Going with sign in API method.");
                    signinResponse = _tService.TrySignin(CurrentLoginData.Username, CurrentLoginData.Password, CurrentLoginData.SelectedSite);
                }
                signinResponse.TrustedToken = _tService.TryGetTrustedToken(CurrentLoginData.Username, CurrentLoginData.SelectedSite);
                SetSessionValues(signinResponse);
            }

            return(RedirectToAction("Index", "Home"));
        }
Example #2
0
 public string GetVizToken(string userName, string siteName)
 {
     return(_tService.TryGetTrustedToken(userName, siteName));
 }