Esempio n. 1
0
        public async Task <IActionResult> Recording(ulong id, string type, string deviceName, int createdAt)
        {
            RingClient ring;

            try
            {
                var authToken = User.Claims.FirstOrDefault(e => e.Type == "auth_token")?.Value;
                ring = await RingClient.CreateAsync(authToken);
            }
            catch
            {
                return(Challenge());
            }

            try
            {
                RecordingViewModel model = new RecordingViewModel();

                var ding = new Ring.Models.Ding()
                {
                    Id = id, RecordingIsReady = true
                };
                model.RecordingUri = await ring.GetRecordingUriAsync(ding);

                model.Type       = type;
                model.DeviceName = deviceName;
                model.CreatedAt  = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(createdAt);

                return(View(model));
            }
            catch
            {
                return(NotFound());
            }
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            try
            {
                // Connect to the Ring API using a Ring account username and password.
                var ring = await RingClient.CreateAsync("*****@*****.**", "password");

                // Save the AuthToken for future connections instead of the Ring account username and password.
                // You can create a new connection using an auth token by calling: RingClient.CreateAsync(authToken)
                // The auth token may expire, but you can ask the user for their username and password at that point.
                var authToken = ring.AuthToken;

                // Get the list of the user's devices.
                var devices = await ring.GetDevicesAsync();

                // Check if any devices were returned.
                if (devices.Count > 0)
                {
                    // Get the battery life of the first device.
                    var batteryLife = devices[0].BatteryLife;

                    var deviceDescription = devices[0].Description;

                    Console.WriteLine($"{deviceDescription} battery life: {batteryLife}");
                }

                // Get the list of the user's active dings.
                var activeDings = await ring.GetActiveDingsAsync();

                // Check if there are any active dings.
                if (activeDings.Count > 0)
                {
                    // Get the type of the first active ding.
                    var activeDingType = activeDings[0].Type;

                    Console.WriteLine($"Active ding: {activeDingType}");
                }

                // Get the list of the user's last 15 dings.
                var dings = await ring.GetDingsAsync(15);

                // Check if any dings were returned.
                if (dings.Count > 0)
                {
                    // Get the URI of the recording of the most recent ding.
                    var recordingUri = await ring.GetRecordingUriAsync(dings[0]);

                    // Get the description of the Ring device that the most recent ding occurred from.
                    var dingDeviceDescription = dings[0].Device.Description;

                    Console.WriteLine($"Ding from {dingDeviceDescription}: {recordingUri}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var ring = await RingClient.CreateAsync(model.EmailAddress, model.Password);

                    var claims = new List <Claim>
                    {
                        new Claim("auth_token", ring.AuthToken)
                    };

                    var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

                    var authProperties = new AuthenticationProperties {
                        IsPersistent = model.StayLoggedIn
                    };

                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }

                    return(RedirectToAction("Index", "Activity"));
                }
                catch (SecurityException)
                {
                    ModelState.AddModelError("", "The provided email address and/or password are incorrect.");
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "The Ring service failed to login.");
                }
            }

            ViewData["ReturnUrl"] = returnUrl;

            return(View(model));
        }
Esempio n. 4
0
        public async Task <IActionResult> Index()
        {
            RingClient ring;

            try
            {
                var authToken = User.Claims.FirstOrDefault(e => e.Type == "auth_token")?.Value;
                ring = await RingClient.CreateAsync(authToken);
            }
            catch
            {
                return(Challenge());
            }

            try
            {
                return(View(await ring.GetDevicesAsync()));
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }