Esempio n. 1
0
        public void SetupTest()
        {
            Settings = new MobileSettings();
            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability("app", Settings.App);
            capabilities.SetCapability("deviceName", Settings.DeviceName);
            capabilities.SetCapability("platformName", Settings.PlatformName);
            capabilities.SetCapability("platformVersion", Settings.PlatformVersion);

            this.Driver = new RemoteWebDriver(new Uri(Settings.Url), capabilities, TimeSpan.FromSeconds(180));
            this.Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
        }
Esempio n. 2
0
        public ActionResult CheckLogin(string data)
        {
            var authError = Authenticate();

            if (authError != null)
            {
                return(authError);
            }

            // Check to see if type matches
            BaseMessage dataIn = BaseMessage.createFromString(data);

            if (dataIn.type != BaseMessage.API_TYPE_LOGIN)
            {
                return(BaseMessage.createTypeErrorReturn());
            }

            var givingOrg = (from e in DbUtil.Db.Organizations
                             where e.RegistrationTypeId == 8
                             select e).FirstOrDefault();

            var roles = from r in DbUtil.Db.UserRoles
                        where r.UserId == Util.UserId
                        orderby r.Role.RoleName
                        select new MobileRole
            {
                id   = r.RoleId,
                name = r.Role.RoleName
            };

            MobileSettings ms = new MobileSettings();

            ms.peopleID = Util.UserPeopleId ?? 0;
            ms.userID   = Util.UserId;

            ms.givingEnabled = DbUtil.Db.Setting("EnableMobileGiving", "true") == "true" ? 1 : 0;
            ms.givingAllowCC = DbUtil.Db.Setting("NoCreditCardGiving", "false") == "false" ? 1 : 0;
            ms.givingOrgID   = givingOrg != null ? givingOrg.OrganizationId : 0;
            ms.roles         = roles.ToList();

            // Everything is in order, start the return
            BaseMessage br = new BaseMessage();

            br.error = 0;
            br.id    = Util.UserPeopleId ?? 0;
            br.data  = JsonConvert.SerializeObject(ms);

            return(br);
        }
Esempio n. 3
0
        private static RemoteWebDriver StartChromeDriver(DriverSettings settings, MobileSettings mobile)
        {
            var options = new ChromeOptions();

            settings.Capabilities?.ForEach(cap => options.AddAdditionalCapability(cap.Key, cap.Value));
            if (!string.IsNullOrEmpty(settings.BrowserBinaryPath))
            {
                options.BinaryLocation = settings.BrowserBinaryPath;
            }
            if (!string.IsNullOrEmpty(settings.Proxy))
            {
                options.Proxy = new Proxy {
                    HttpProxy = settings.Proxy
                }
            }
            ;
            if (settings.BrowserBinaryPath != null)
            {
                options.BinaryLocation = settings.BrowserBinaryPath;
            }
            if (settings.CmdArgs != null)
            {
                options.AddArguments(settings.CmdArgs);
            }
            if (settings.Extensions != null)
            {
                options.AddExtensions(settings.Extensions.Select(ext => ext.RelativeToBaseDirectory()));
            }
            settings.ProfilePrefs?.ForEach(pref => options.AddUserProfilePreference(pref.Key, pref.Value));
            if (mobile != null && mobile.Enable)
            {
                if (!string.IsNullOrEmpty(mobile.DeviceName))
                {
                    options.EnableMobileEmulation(mobile.DeviceName);
                }
                else
                {
                    var deviceSettings = new ChromeMobileEmulationDeviceSettings
                    {
                        EnableTouchEvents = mobile.EnableTouchEvents,
                        Width             = mobile.Width,
                        Height            = mobile.Height,
                        PixelRatio        = mobile.PixelRatio
                    };
                    options.EnableMobileEmulation(deviceSettings);
                }
            }
            return(new ChromeDriver(options));
        }
Esempio n. 4
0
        public static RemoteWebDriver StartNewDriver(DriverSettings settings, MobileSettings mobile)
        {
            switch (settings.Browser)
            {
            case Browser.Chrome:   return(StartChromeDriver(settings, mobile));

            case Browser.Firefox:  return(StartFirefoxDriver(settings));

            //case Browser.Opera:    return StartOperaDriver(settings);
            //case Browser.Safari:   return StartSafariDriver(settings);
            //case Browser.IE:       return StartIeDriver(settings);
            //case Browser.Edge:     return StartEdgeDriver(settings);
            default:               throw new Exception("Unsupported browser");
            }
        }
        private MobileSettings getUserInfo()
        {
            var roles = from r in DbUtil.Db.UserRoles
                        where r.UserId == Util.UserId
                        orderby r.Role.RoleName
                        select r.Role.RoleName;

            MobileSettings ms = new MobileSettings();

            ms.peopleID = Util.UserPeopleId ?? 0;
            ms.userID   = Util.UserId;
            ms.userName = Util.UserFullName;
            ms.roles    = roles.ToList();

            return(ms);
        }
        public ActionResult Authenticate(string data)
        {
            //DbUtil.LogActivity("calling authenticateuser");
            var result = AuthenticateUser(requirePin: true);

            if (!result.IsValid)
            {
                return(AuthorizationError(result));
            }

            MobileSettings ms = getUserInfo();

            var br = new BaseMessage();

            br.error = 0;
            br.data  = JsonConvert.SerializeObject(ms);
            br.token = result.User.ApiSessions.Single().SessionToken.ToString();
            return(br);
        }
        public ActionResult ResetSessionToken(string data)
        {
            var sessionToken = Request.Headers["SessionToken"];

            if (string.IsNullOrEmpty(sessionToken))
            {
                return(BaseMessage.createErrorReturn("SessionToken header is required.", BaseMessage.API_ERROR_IMPROPER_HEADER_STRUCTURE));
            }

            var pinHeader           = Request.Headers["PIN"];
            var authorizationHeader = Request.Headers["Authorization"];

            // if the user is resetting a session without their PIN, then credentials will be required
            if (string.IsNullOrEmpty(pinHeader))
            {
                // clear out the session token temporarily to ensure that authentication happens solely by credentials
                Request.Headers.Remove("SessionToken");

                if (string.IsNullOrEmpty(authorizationHeader))
                {
                    return(BaseMessage.createErrorReturn("Either the Authorization or PIN header is required because the session is getting reset.", BaseMessage.API_ERROR_IMPROPER_HEADER_STRUCTURE));
                }
            }

            var result = AccountModel.ResetSessionExpiration(sessionToken);

            if (!result.IsValid)
            {
                return(BaseMessage.createErrorReturn("You are not authorized!", MapStatusToError(result.Status)));
            }

            AuthenticateUser(requirePin: true);

            MobileSettings ms = getUserInfo();

            var br = new BaseMessage();

            br.error = 0;
            br.data  = JsonConvert.SerializeObject(ms);
            return(br);
        }