Пример #1
0
        async public Task<bool> CreateUser(string facebookToken)
        {
            IPersistantStorage iPersistant = ServiceLocator.Instance.Resolve<IPersistantStorage>();
            if (iPersistant == null) { AppCenterManager.Report("4.4"); return false; }
            iPersistant.SetFacebookToken(facebookToken);

            try
            {
                await RealmUserServices.LoginToServerAsync(facebookToken);
            }
            catch (Exception er)
            {
                AppCenterManager.Report(er);
                AppCenterManager.Report("4.1");
                return false;
            }

            try
            {
                var result = await WebServices.UserController.CreateUser();
                if (result.StatusCode == System.Net.HttpStatusCode.OK) return true;

                //user already exists, that's fine.
                if (result.StatusCode == System.Net.HttpStatusCode.Conflict) return true;
            }
            catch (Exception er)
            {
                AppCenterManager.Report(er);
                AppCenterManager.Report("4.2");
            }

            return false;
        }
Пример #2
0
        public static async Task LoginToServerAsync(string facebookToken)
        {
            System.Diagnostics.Debug.WriteLine("facebookToken:" + facebookToken);
            //AppCenterManager.Report("Facebook: " + facebookToken);

            var credentials = Credentials.Facebook(facebookToken);
            await User.LoginAsync(credentials, new Uri(NotSensitive.SystemUrls.realm_server_ip));

            if (User.Current == null)
            {
                AppCenterManager.Report("4.3");
                throw new Exception();
            }
        }
Пример #3
0
        public static string GetPresignedURL(string remoteUrl, string fileName, DateTime expiry)
        {
            string url = String.Empty;

            try
            {
                url = S3Client.GeneratePreSignedURL(BUCKET_NAME + "/" + remoteUrl, fileName, expiry, null);
            }
            catch (System.Net.WebException) { }
            catch (Exception e)
            {
                AppCenterManager.Report(e);
            }
            return(url);
        }
Пример #4
0
        async public static Task <string> BoardcastCard(Card card, string UUID)
        {
            var permissionStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

            if (permissionStatus != PermissionStatus.Granted)
            {
                return(null);
            }

            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            Position position = null;

            try
            {
                position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));
            }
            catch (Exception e)
            {
                AppCenterManager.Report(e);
            }
            if (position == null)
            {
                return(null);
            }

            var lat  = position.Latitude;
            var lon  = position.Longitude;
            var time = DateTimeOffset.UtcNow;

            System.Diagnostics.Debug.WriteLine("Lat: " + lat, " Lon: " + lon);

            //get users name to replace the card name
            var me = RealmUserServices.GetMe(false);

            if (me == null)
            {
                return(null);
            }

            await WebServices.UserController.UpdateUser(lat, lon);

            var transactionId = await WebServices.TransactionsController.CreateTransaction(lat, lon, card, me.Name);

            return(transactionId);
        }
Пример #5
0
        async public Task <bool> ShareChard()
        {
            try
            {
                SessionUUID = await RealmServices.BoardcastCard(SelectedCard, SessionUUID);

                Sharing = !String.IsNullOrEmpty(SessionUUID);
            }
            catch (Exception e)
            {
                Sharing = false;
                AppCenterManager.Report(e);
            }

            return(Sharing);
        }
Пример #6
0
        async public static Task <GithubResponse> GetGithubAccount(string token)
        {
            var client = new HttpClient();

            client.Timeout = TimeSpan.FromSeconds(10);

            Dictionary <string, string> Parameters = new Dictionary <string, string>();

            Parameters.Add("code", token);
            Parameters.Add("client_id", NotSensitive.SlinkKeys.github_client_id);
            Parameters.Add("client_secret", NotSensitive.SlinkKeys.github_client_secret);
            Parameters.Add("accept", "json");

            HttpResponseMessage contentsTask = null;

            try
            {
                contentsTask = await client.PostAsync("https://github.com/login/oauth/access_token", new FormUrlEncodedContent(Parameters));
            }
            catch (Exception e)
            {
                AppCenterManager.Report(e);
                return(null);
            }

            if (contentsTask == null)
            {
                return(null);
            }

            //access_token=01805dc46a84d7b7547f5d430629a0354fe7ddcd&scope=user%3Aemail&token_type=bearer
            string accessToken = null;
            string result      = contentsTask.Content.ReadAsStringAsync().Result;

            if (!String.IsNullOrEmpty(result))
            {
                var splitByAmpersand = result.Split('&');
                foreach (String sub in splitByAmpersand)
                {
                    if (sub.Contains("access_token"))
                    {
                        var seperatedByEquals = sub.Split('=');
                        accessToken = seperatedByEquals.Last();
                    }
                }


                if (!String.IsNullOrEmpty(accessToken))
                {
                    var client2 = new HttpClient();
                    client2.Timeout = TimeSpan.FromSeconds(10);
                    client2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    client2.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
                    var contentsTask2 = await client2.GetAsync("https://api.github.com/user?access_token=" + accessToken);

                    if (contentsTask2 != null)
                    {
                        var result2 = JToken.Parse(contentsTask2.Content.ReadAsStringAsync().Result);
                        if (result2 != null)
                        {
                            var response = JsonConvert.DeserializeObject <GithubResponse>(result2.ToString());

                            var outlet = new Outlet();
                            outlet.Handle = response.id;
                            outlet.Type   = Outlet.outlet_type_github;
                            outlet.Name   = response.login;

                            RealmServices.SaveOutlet(outlet);

                            return(response);
                        }
                    }
                }
            }
            return(null);
        }