Пример #1
0
        private async Task LogIn()
        {
            if (string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                  AppResources.EmailAddress), AppResources.Ok);

                return;
            }

            if (string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                  AppResources.MasterPassword), AppResources.Ok);

                return;
            }

            await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn);

            var result = await _authService.TokenPostAsync(EmailCell.Entry.Text, PasswordCell.Entry.Text);

            await _deviceActionService.HideLoadingAsync();

            if (!result.Success)
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, result.ErrorMessage, AppResources.Ok);

                return;
            }

            PasswordCell.Entry.Text = string.Empty;

            if (result.TwoFactorRequired)
            {
                _googleAnalyticsService.TrackAppEvent("LoggedIn To Two-step");
                await Navigation.PushAsync(new LoginTwoFactorPage(EmailCell.Entry.Text, result));

                return;
            }

            _googleAnalyticsService.TrackAppEvent("LoggedIn");

            if (Device.RuntimePlatform == Device.Android)
            {
                _pushNotification.Register();
            }

            var task = Task.Run(async() => await _syncService.FullSyncAsync(true));

            Application.Current.MainPage = new MainPage();
        }
        public async Task <IActionResult> Register(DeviceRegistrationRequest registration)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (TryExtractPlatform(out MobilePlatform platform))
            {
                var registrationId = await _pushNotificationService.CreateRegistrationId(registration.Handle);

                await _pushNotificationService.Register(platform, registration.Handle, registrationId, new[] { registration.Tag });

                return(Ok(new DeviceRegistrationResult {
                    RegistrationId = registrationId
                }));
            }

            return(BadRequest("Unknown device platform or missing user-agent."));
        }
Пример #3
0
        public async Task <IActionResult> RegisterDevice([FromBody] RegisterDeviceRequest request)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound());
            }
            var device = await _dbContext.UserDevices.SingleOrDefaultAsync(x => x.UserId == user.Id && x.DeviceId == request.DeviceId);

            await _pushNotificationService.Register(request.DeviceId.ToString(), request.PnsHandle, request.DevicePlatform, user.Id, request.Tags?.ToArray());

            var deviceId = default(Guid);

            if (device != null)
            {
                device.IsPushNotificationsEnabled = true;
                device.DeviceName = request.DeviceName;
                deviceId          = device.Id;
            }
            else
            {
                var deviceToAdd = new UserDevice {
                    DeviceId                   = request.DeviceId,
                    DeviceName                 = request.DeviceName,
                    DevicePlatform             = request.DevicePlatform,
                    IsPushNotificationsEnabled = true,
                    UserId      = user.Id,
                    DateCreated = DateTimeOffset.Now
                };
                _dbContext.UserDevices.Add(deviceToAdd);
                deviceId = deviceToAdd.Id;
            }
            await _dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetDevices), Name, new { deviceId }));
        }
Пример #4
0
 /// <summary>
 /// Register a device for userId.
 /// </summary>
 /// <param name="service">Instance of <see cref="IPushNotificationService"/>.</param>
 /// <param name="deviceId">DeviceId to register.</param>
 /// <param name="pnsHandle">Platform notification service (pns) obtained from client platform.</param>
 /// <param name="devicePlatform">Client device platform.</param>
 /// <param name="userId">UserId to be passed as tag.</param>
 /// <param name="tags">Optional tag parameters.</param>
 public static async Task Register(this IPushNotificationService service, string deviceId, string pnsHandle, DevicePlatform devicePlatform, string userId, params string[] tags) =>
 await service.Register(deviceId, pnsHandle, devicePlatform, new string[] { userId }.Concat(tags ?? new string[0]).ToList());
Пример #5
0
 /// <summary>
 /// Register a device for userId.
 /// </summary>
 /// <param name="service">Instance of <see cref="IPushNotificationService"/>.</param>
 /// <param name="deviceId">DeviceId to register.</param>
 /// <param name="pnsHandle">Platform notification service (PNS) obtained from client platform.</param>
 /// <param name="devicePlatform">Client device platform.</param>
 /// <param name="userTag">UserId to be passed as tag.</param>
 /// <param name="tags">Optional tag parameters.</param>
 public static Task Register(this IPushNotificationService service, string deviceId, string pnsHandle, DevicePlatform devicePlatform, string userTag, params string[] tags) =>
 service.Register(deviceId, pnsHandle, devicePlatform, new string[] { userTag }.Concat(tags ?? Array.Empty <string>()).ToList());