Exemple #1
0
        private async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            if (!e.IsAuthenticated)
            {
                return;
            }

            //var token = e.Account.Properties["access_token"];
            //await SecureStorage.SetAsync("access_token", token);
            await Shell.Current.GoToAsync("//main");

            IsBusy = false;

            var request  = new OAuth2Request("GET", new Uri(GoogleOAuthManager.UserInfoUrl), null, e.Account);
            var response = await request.GetResponseAsync();

            if (response != null)
            {
                string userJson = await response.GetResponseTextAsync();

                var User     = JsonConvert.DeserializeObject <User>(userJson);
                var position = await Geolocation.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.Medium));

                User.Available = false;
                User.Busy      = false;
                User.Latitude  = position.Latitude;
                User.Longitude = position.Longitude;
                await SecureStorage.SetAsync("ID", User.Id);

                var Uri = new Uri("https://server-cy3lzdr3na-uc.a.run.app/user");
                await RestService.Create(User, Uri);
            }
            ;
        }
Exemple #2
0
        private async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            if (!e.IsAuthenticated)
            {
                return;
            }

            var token = e.Account.Properties["access_token"];

            //await SecureStorage.SetAsync("access_token", token);
            Application.Current.MainPage = new MainShell();

            var request  = new OAuth2Request("GET", new Uri(GoogleOAuthManager.UserInfoUrl), null, e.Account);
            var response = await request.GetResponseAsync();

            if (response != null)
            {
                string userJson = await response.GetResponseTextAsync();

                var User = JsonConvert.DeserializeObject <User>(userJson);
                User.Available = false;
                User.Busy      = false;
                await SecureStorage.SetAsync("id", User.Id);

                var Uri = new Uri("https://server-cy3lzdr3na-uc.a.run.app/user");
                await RestService.Create(User, Uri);
            }
            ;
        }
Exemple #3
0
        private async Task SetMeetup(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            string id1 = await SecureStorage.GetAsync("ID");

            var    Uri1  = new Uri("https://server-cy3lzdr3na-uc.a.run.app/user/" + id1);
            string Data1 = await RestService.Read(Uri1);

            var users1 = JsonConvert.DeserializeObject <List <User> >(Data1);
            var User1  = users1.Find(user => user.Id == id1);

            User1.Busy = true;
            await RestService.Update(User1, Uri1);

            string id2   = obj as string;
            var    Uri2  = new Uri("https://server-cy3lzdr3na-uc.a.run.app/user/" + id2);
            string Data2 = await RestService.Read(Uri2);

            var users2 = JsonConvert.DeserializeObject <List <User> >(Data2);
            var User2  = users2.Find(user => user.Id == id2);

            User2.Busy = true;
            await RestService.Update(User2, Uri2);

            var Uri    = new Uri("https://server-cy3lzdr3na-uc.a.run.app/meetup/");
            var Meetup = new Meetup();

            Meetup.Id        = id1 + id2;
            Meetup.User1     = id1;
            Meetup.User2     = id2;
            Meetup.Time      = DateTime.Now;
            Meetup.User1Name = User1.Name;
            Meetup.User2Name = User2.Name;

            await RestService.Create(Meetup, Uri);

            IsBusy = false;

            await GetAvailableUsers();
            await GetMeetups();
        }