Ejemplo n.º 1
0
        public ActionResult gateurllogin(DataTree formParameters)
        {
            logger.LogInfo("Gate url login called.");

            string redirectUrl = string.Empty;

            try
            {
                DataTree common = LegacyRegister.ContentDataToDataTree((string)formParameters["yleiset_contentdata"]);
                DataTree menu   = LegacyRegister.ContentDataToDataTree((string)formParameters["menureg_contentdata"]);
                DataTree silmu2 = LegacyRegister.ContentDataToDataTree((string)formParameters["silmu2_contentdata"]);

                string loginGuid = (string)formParameters["sov_varmistus_guid"];

                if (string.IsNullOrEmpty(loginGuid) || loginGuid != (string)Runtime.Config["security"]["loginguid"])
                {
                    logger.LogWarning("Login attempt with invalid login GUID");
                    throw new AccessDeniedException();
                }

                string userEmail = (string)silmu2["account"]["email"].GetValueOrDefault(string.Empty);

                var userQuery = new DBQuery("core", "userbyemail");
                userQuery.AddParameter("email", userEmail);

                // User must be found when redirecting to addresses
                DataTree user = userQuery.FindOneAsync().Result;
                if (user == null)
                {
                    return(new AjaxResult(SilmuErrorHeader + "User was not found in database."));
                }

                string target = (string)silmu2["app"]["parameters"]["target"].GetValueOrDefault(String.Empty);
                string url    = (string)silmu2["app"]["parameters"]["url"].GetValueOrDefault(String.Empty);

                if (!string.IsNullOrEmpty(target))
                {
                    redirectUrl = Runtime.Config["gateurls"][target];
                }
                else
                {
                    redirectUrl = url;
                }

                if (string.IsNullOrEmpty(redirectUrl))
                {
                    return(new AjaxResult(SilmuErrorHeader + "Redirect url was not found."));
                }

                Interlocked.Increment(ref gateUserRedirects);
            }

            catch (Exception ex)
            {
                return(new AjaxResult(SilmuErrorHeader + ex.ToString()));
            }

            return(new AjaxResult("<url>" + redirectUrl + "</url>"));
        }
Ejemplo n.º 2
0
        private DataTree GetLocalRelationItems(string localCollection, string relation, string id)
        {
            var localRelationQuery = new DBQuery();

            localRelationQuery[localCollection][DBQuery.Condition] = Query.EQ(DBQuery.Id, new ObjectId(id)).ToString();

            return(localRelationQuery.FindOneAsync().Result[relation]);
        }