示例#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>"));
        }
示例#2
0
        public ActionResult gatelogin(DataTree formParameters)
        {
            string token = Guid.NewGuid().ToString();

            try
            {
                logger.LogInfo("Gate login (post) called.");

                DataTree silmu2         = LegacyRegister.ContentDataToDataTree((string)formParameters["silmu2_contentdata"]);
                DataTree gateParameters = LegacyRegister.ContentDataToDataTree((string)formParameters["gate_parameters"]);


                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");
                    return(new AjaxResult(SilmuErrorHeader + ": Login attempt with invalid GUID"));
                }

                string userEmail = gateParameters["v001"]["account"]["email"];

                if (string.IsNullOrEmpty(userEmail))
                {
                    userEmail = silmu2["account"]["email"];
                }

                userEmail = userEmail.ToLower();

                logger.LogInfo("Login info received for user. Passing a token.", userEmail);

                lock (loginTokens)
                {
                    loginTokens.Add(token, userEmail);
                }

                SetupCordovaSessionVariables(gateParameters);
            }
            catch (Exception e)
            {
                Interlocked.Increment(ref failedGateLogins);
                return(new AjaxResult(SilmuErrorHeader + e.ToString()));
            }

            return(new AjaxResult((MC2Value)("<url>" + Runtime.CurrentActionCall.RootAddress + "/main.aspx?controller=login&action=silmulogin2&token=" + token + "</url>")));
        }