예제 #1
0
        private void CheckAuth()
        {
            MFBOAuthScope sc = ScopeForService();

            if (!MFBOauthServer.CheckScope(Token.Scope, sc))
            {
                throw new UnauthorizedAccessException(String.Format(CultureInfo.CurrentCulture, "Requested action requires scope \"{0}\", which is not granted.", sc.ToString()));
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.Compare(Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return;
            }

            if (!Request.IsSecureConnection)
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "Image upload MUST be on a secure channel");
            }

            if (ShuntState.IsShunted)
            {
                throw new MyFlightbookException(ShuntState.ShuntMessage);
            }

            System.Web.UI.HtmlControls.HtmlInputFile imgPicture = (System.Web.UI.HtmlControls.HtmlInputFile)FindControl("imgPicture");
            if (imgPicture == null)
            {
                throw new MyFlightbookException("No control named 'imgPicture' found!");
            }

            string szErr = "OK";

            try
            {
                string szUser = string.Empty;
                string szAuth = Request.Form["txtAuthToken"];
                if (String.IsNullOrEmpty(szAuth))
                {
                    // check for an oAuth token
                    using (OAuthServiceCall service = new OAuthServiceCall(Request))
                    {
                        szAuth = service.GeneratedAuthToken;

                        // Verify that you're allowed to modify images.
                        if (!MFBOauthServer.CheckScope(service.Token.Scope, MFBOAuthScope.images))
                        {
                            throw new UnauthorizedAccessException(String.Format(CultureInfo.CurrentCulture, "Requested action requires scope \"{0}\", which is not granted.", MFBOAuthScope.images.ToString()));
                        }
                    }
                }

                using (MFBWebService ws = new MFBWebService())
                {
                    szUser = ws.GetEncryptedUser(szAuth);
                }

                if (string.IsNullOrEmpty(szUser))
                {
                    throw new MyFlightbookException(Resources.WebService.errBadAuth);
                }

                HttpPostedFile pf = imgPicture.PostedFile;
                if (pf == null || pf.ContentLength == 0)
                {
                    throw new MyFlightbookException(Resources.WebService.errNoImageProvided);
                }

                // Upload the image, and then perform a pseudo idempotency check on it.
                MFBImageInfo mfbii = UploadForUser(szUser, pf, Request.Form["txtComment"] ?? string.Empty);
                mfbii.IdempotencyCheck();
            }
            catch (MyFlightbookException ex)
            {
                szErr = ex.Message;
            }

            Response.Clear();
            Response.ContentType = "text/plain; charset=utf-8";
            Response.Write(szErr);
        }