コード例 #1
0
        public ResultViewModel Verify(LoginVerification verification)
        {
            if (verification == null)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "Missing required parameters"));
            }

            Uri link = new Uri(verification.VerificationLink);
            NameValueCollection linkQueryParams = HttpUtility.ParseQueryString(link.Query);

            if (linkQueryParams["code"] == null)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "Invalid verification link"));
            }

            FxSyncNet.SyncClient syncClient = new FxSyncNet.SyncClient();

            try
            {
                syncClient.VerifyLogin(verification.UID, linkQueryParams["code"]);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    Utility.GetExceptionMessage(ex)));
            }

            return(new ResultViewModel());
        }
コード例 #2
0
        public ResultViewModel Login(BookmarkBrowser.Api.Models.Credentials creds)
        {
            if (creds == null)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "Missing required parameters"));
            }

            FxSyncNet.SyncClient           syncClient = new FxSyncNet.SyncClient();
            FxSyncNet.Models.LoginResponse response;

            try
            {
                response = syncClient.Login(creds.Username, creds.Password);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    Utility.GetExceptionMessage(ex)));
            }

            return(new ResultViewModel()
            {
                Content = JsonConvert.SerializeObject(response)
            });
        }
コード例 #3
0
        public ResultViewModel GetData(string collection)
        {
            ResultViewModel result = new ResultViewModel();
            Directory       mainDir;

            var parms = Request.RequestUri.ParseQueryString();
            int count;

            if (parms["username"] == null || parms["password"] == null)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "You must supply Sync credentials"));
            }

            if (parms["keyFetchToken"] == null || parms["sessionToken"] == null)
            {
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "You must supply the proper Sync tokens"));
            }

            FxSyncNet.SyncClient syncClient = new FxSyncNet.SyncClient();

            switch (collection.ToLower())
            {
            case "bookmark":
                try
                {
                    syncClient.OpenSyncAccount(parms["userName"],
                                               parms["password"],
                                               parms["keyFetchToken"],
                                               parms["sessionToken"]);

                    IEnumerable <FxSyncNet.Models.Bookmark> bookmarks = syncClient.GetBookmarks();
                    mainDir        = Utility.BuildBookmarks(bookmarks);
                    count          = bookmarks.Where(x => x.Type == FxSyncNet.Models.BookmarkType.Bookmark).Count();
                    mainDir.Tag    = count.ToString();
                    result.Content = JsonConvert.SerializeObject(mainDir);
                }
                catch (ServiceNotAvailableException ex)
                {
                    throw new HttpResponseException(Request.CreateResponse(
                                                        HttpStatusCode.GatewayTimeout,
                                                        Utility.GetExceptionMessage(ex)));
                }
                catch (InvalidOperationException ex)
                {
                    throw new HttpResponseException(Request.CreateResponse(
                                                        HttpStatusCode.BadRequest,
                                                        Utility.GetExceptionMessage(ex)));
                }
                catch (AuthenticationException ex)
                {
                    throw new HttpResponseException(Request.CreateResponse(
                                                        HttpStatusCode.BadRequest,
                                                        Utility.GetExceptionMessage(ex)));
                }
                catch (Exception ex)
                {
                    throw new HttpResponseException(Request.CreateResponse(
                                                        HttpStatusCode.BadRequest,
                                                        Utility.GetExceptionMessage(ex)));
                }

                break;

            default:
                throw new HttpResponseException(Request.CreateResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "Unsupported collection type"));
            }

            return(result);
        }