Exemplo n.º 1
0
        public async Task <TokenResponse> LoginInstagram(
            string urlBase,
            string servicePrefix,
            string controller,
            Models.InstagramUser profile)
        {
            try
            {
                var request = JsonConvert.SerializeObject(profile);
                var content = new StringContent(
                    request,
                    Encoding.UTF8,
                    "application/json");
                var client = new HttpClient();
                client.BaseAddress = new Uri(urlBase);
                var url      = string.Format("{0}{1}", servicePrefix, controller);
                var response = await client.PostAsync(url, content);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }

                var tokenResponse = await GetToken(
                    urlBase,
                    profile.Id,
                    profile.Id);

                return(tokenResponse);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public static async Task NavigateToInstagramProfile(Models.InstagramUser profile)
        {
            if (profile == null)
            {
                Application.Current.MainPage = new NavigationPage(new LoginPage());
                return;
            }

            var apiService  = new ApiService();
            var dataService = new DataService();

            var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            var token       = await apiService.LoginInstagram(
                apiSecurity,
                "/api",
                "/Users/LoginInstagram",
                profile);

            if (token == null)
            {
                Application.Current.MainPage = new NavigationPage(new LoginPage());
                return;
            }

            var user = await apiService.GetUserByEmail(
                apiSecurity,
                "/api",
                "/Users/GetUserByEmail",
                token.TokenType,
                token.AccessToken,
                token.UserName);

            UserLocal userLocal = null;

            if (user != null)
            {
                userLocal = Converter.ToUserLocal(user);
                dataService.DeleteAllAndInsert(userLocal);
                dataService.DeleteAllAndInsert(token);
            }

            var mainViewModel = MainViewModel.GetInstance();

            mainViewModel.Token          = token;
            mainViewModel.User           = userLocal;
            mainViewModel.Barbershops    = new BarbershopsViewModel();
            Application.Current.MainPage = new MasterPage();
            Settings.IsRemembered        = "true";
        }