示例#1
0
        /// <summary>
        /// Start a session with the Web Report Server using the user name, password, token (may be optional according to the authentication configured on the server) and returns information of the logged user (SWIUserProfile).
        /// </summary>
        public ActionResult SWILogin(string user, string password, string token)
        {
            writeDebug("SWILogin");

            try
            {
                bool newAuthentication = false;
                if (WebUser == null || !WebUser.IsAuthenticated || (!string.IsNullOrEmpty(user) && WebUser.WebUserName != user) || (!string.IsNullOrEmpty(token) && WebUser.Token != token))
                {
                    CreateRepository();
                    CreateWebUser();
                    WebUser.WebPrincipal = User;
                    WebUser.WebUserName  = user;
                    WebUser.WebPassword  = password;
                    WebUser.Token        = token;
                    WebUser.Request      = Request;
                    Authenticate();

                    if (!WebUser.IsAuthenticated)
                    {
                        throw new LoginException(string.IsNullOrEmpty(WebUser.Error) ? Translate("Invalid user name or password") : WebUser.Error);
                    }
                    //Load profile
                    if (System.IO.File.Exists(WebUser.ProfilePath))
                    {
                        WebUser.Profile = SecurityUserProfile.LoadFromFile(WebUser.ProfilePath);
                    }
                    checkRecentFiles();
                    WebUser.Profile.Path = WebUser.ProfilePath;
                    newAuthentication    = true;
                }

                //Audit
                Audit.LogAudit(AuditType.Login, WebUser);
                Audit.LogEventAudit(AuditType.EventLoggedUsers, SealSecurity.LoggedUsers.Count(i => i.IsAuthenticated).ToString());

                //Set repository defaults
                var defaultGroup = WebUser.DefaultGroup;
                if (!string.IsNullOrEmpty(defaultGroup.LogoName))
                {
                    Repository.Configuration.LogoName = defaultGroup.LogoName;
                }

                string culture = WebUser.Profile.Culture;
                if (!string.IsNullOrEmpty(culture))
                {
                    Repository.SetCultureInfo(culture);
                }
                else if (!string.IsNullOrEmpty(defaultGroup.Culture))
                {
                    Repository.SetCultureInfo(defaultGroup.Culture);
                }
                else if (Repository.CultureInfo.EnglishName != Repository.Instance.CultureInfo.EnglishName)
                {
                    Repository.SetCultureInfo(Repository.Instance.CultureInfo.EnglishName);
                }

                string reportToExecute = "", reportToExecuteName = "";
                bool   executeLast = false;
                if (defaultGroup.EditProfile && WebUser.Profile.OnStartup != StartupOptions.Default)
                {
                    if (WebUser.Profile.OnStartup == StartupOptions.ExecuteLast && WebUser.Profile.RecentReports.Count > 0)
                    {
                        executeLast = true;
                    }
                    else if (WebUser.Profile.OnStartup == StartupOptions.ExecuteReport)
                    {
                        reportToExecute     = WebUser.Profile.StartUpReport;
                        reportToExecuteName = WebUser.Profile.StartupReportName;
                    }
                }
                else
                {
                    if (defaultGroup.OnStartup == StartupOptions.ExecuteLast)
                    {
                        executeLast = true;
                    }
                    else if (defaultGroup.OnStartup == StartupOptions.ExecuteReport)
                    {
                        reportToExecute     = defaultGroup.StartupReport;
                        reportToExecuteName = Repository.TranslateFileName(defaultGroup.StartupReport);
                    }
                }

                if (executeLast && WebUser.Profile.RecentReports.Count > 0)
                {
                    reportToExecute     = WebUser.Profile.RecentReports[0].Path;
                    reportToExecuteName = WebUser.Profile.RecentReports[0].Name;
                }

                //Refresh menu reports
                if (newAuthentication)
                {
                    MenuReportViewsPool.ForceReload();
                }

                var profile = new SWIUserProfile()
                {
                    name              = WebUser.Name,
                    group             = WebUser.SecurityGroupsDisplay,
                    culture           = culture,
                    folder            = WebUser.Profile.LastFolder,
                    showfolders       = WebUser.ShowFoldersView,
                    editprofile       = defaultGroup.EditProfile,
                    usertag           = WebUser.Tag,
                    onstartup         = WebUser.Profile.OnStartup,
                    startupreport     = WebUser.Profile.StartUpReport,
                    startupreportname = WebUser.Profile.StartupReportName,
                    report            = reportToExecute,
                    reportname        = reportToExecuteName,
                };

                if (!string.IsNullOrEmpty(profile.startupreport))
                {
                    try
                    {
                        getFileDetail(profile.startupreport);
                    }
                    catch {
                        profile.startupreport     = "";
                        profile.startupreportname = "";
                    }
                }
                if (!string.IsNullOrEmpty(profile.report))
                {
                    try
                    {
                        getFileDetail(profile.report);
                    }
                    catch
                    {
                        profile.report     = "";
                        profile.reportname = "";
                    }
                }

                return(Json(profile, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }
        /// <summary>
        /// Start a session with the Web Report Server using the user name, password, token (may be optional according to the authentication configured on the server) and returns information of the logged user (SWIUserProfile).
        /// </summary>
        public ActionResult SWILogin(string user, string password, string token)
        {
            writeDebug("SWILogin");

            try
            {
                bool newAuthentication = false;
                if (WebUser == null || !WebUser.IsAuthenticated || (!string.IsNullOrEmpty(user) && WebUser.WebUserName != user) || (!string.IsNullOrEmpty(token) && WebUser.Token != token))
                {
                    CreateRepository();
                    CreateWebUser();
                    WebUser.WebPrincipal = User;
                    WebUser.WebUserName  = user;
                    WebUser.WebPassword  = password;
                    WebUser.Token        = token;
                    WebUser.Request      = Request;
                    Authenticate();

                    if (!WebUser.IsAuthenticated)
                    {
                        throw new LoginException(string.IsNullOrEmpty(WebUser.Error) ? Translate("Invalid user name or password") : WebUser.Error);
                    }
                    //Load profile
                    if (System.IO.File.Exists(WebUser.ProfilePath))
                    {
                        WebUser.Profile = SecurityUserProfile.LoadFromFile(WebUser.ProfilePath);
                    }
                    checkRecentFiles();
                    WebUser.Profile.Path = WebUser.ProfilePath;
                    newAuthentication    = true;
                }

                //Audit
                Audit.LogAudit(AuditType.Login, WebUser);
                Audit.LogEventAudit(AuditType.EventLoggedUsers, SealSecurity.LoggedUsers.Count(i => i.IsAuthenticated).ToString());

                //Set culture
                string culture = WebUser.Profile.Culture;
                if (string.IsNullOrEmpty(culture) || string.IsNullOrEmpty(WebUser.WebUserName))
                {
                    culture = getCookie(SealCultureCookieName);
                }
                if (!string.IsNullOrEmpty(culture))
                {
                    Repository.SetCultureInfo(culture);
                }

                //Refresh menu reports
                if (newAuthentication)
                {
                    MenuReportViewsPool.ForceReload();
                }

                return(Json(new SWIUserProfile()
                {
                    name = WebUser.Name,
                    group = WebUser.SecurityGroupsDisplay,
                    culture = Repository.CultureInfo.EnglishName,
                    folder = getCookie(SealLastFolderCookieName),
                    showfolders = WebUser.ShowFoldersView,
                    usertag = WebUser.Tag
                }));;
            }
            catch (Exception ex)
            {
                return(HandleSWIException(ex));
            }
        }