コード例 #1
0
ファイル: AllImages.aspx.cs プロジェクト: trevorpower/tadmap
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            if (HttpContext.Current.User.IsInRole(TadMapRoles.Administrator))
            {
                m_repMapRepeater.ItemDataBound += new RepeaterItemEventHandler(m_repMapRepeater_ItemDataBound);

                Tadmap db = new Tadmap(Database.TadMapConnection);

                var images = from i in db.UserImages
                             select i;

                m_repMapRepeater.DataSource = images;
                m_repMapRepeater.DataBind();
                divMapList.Visible = true;
            }
            else
            {
                throw new SecurityException("Must be administrator to access AllImages page");
            }
        }
        else
        {
            throw new SecurityException("Must authenticated to access AllImages page");
        }
    }
コード例 #2
0
ファイル: UpdateImage.cs プロジェクト: trevorpower/tadmap
   public bool UnMark(string id)
   {
       if (!HttpContext.Current.User.IsInRole(TadMapRoles.Administrator))
           throw new SecurityException("Only administrators can mark images as un-offensive.");

       Tadmap tadmap = new Tadmap(Database.TadMapConnection);

       UserImage image = tadmap.UserImages.Single(i => i.Id == new Guid(id));

       image.OffensiveCount = 0;

       tadmap.SubmitChanges();

       return true;
   }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: trevorpower/tadmap
   protected void Page_Load(object sender, EventArgs e)
   {
      m_repMapRepeater.ItemDataBound += new RepeaterItemEventHandler(m_repMapRepeater_ItemDataBound);

      Tadmap db = new Tadmap(Database.TadMapConnection);

      var images = from i in db.UserImages
                   where i.OffensiveCount == 0 && i.Privacy > 0
                   select i;

      m_repMapRepeater.DataSource = images;
      m_repMapRepeater.DataBind();
      divMapList.Visible = true;

      LoginText.Visible = !HttpContext.Current.User.Identity.IsAuthenticated;
   }
コード例 #4
0
ファイル: ViewMap.aspx.cs プロジェクト: trevorpower/tadmap
   protected void Page_Load(object sender, EventArgs e)
   {
      ScriptManager1.Scripts.Add(
         new System.Web.UI.ScriptReference(Page.ResolveClientUrl("WebServices/UpdateImage.asmx/js"))
      );

      if (string.IsNullOrEmpty(Request["ImageId"]))
         throw new Exception("This page requires a 'ImageId' as part of the request.");

      Guid imageId = new Guid(Request["ImageId"]);

      Tadmap db = new Tadmap(Database.TadMapConnection);

      Tadmap tadmap = new Tadmap(Database.TadMapConnection);

      UserImage image = tadmap.UserImages.Single(i => i.Id == imageId);

      if (image != null)
      {
         ScriptManager.RegisterClientScriptBlock(Page, GetType(), "MapId", "var imageId = '" + image.Id + "';", true);
         OwnerControls.Visible = false;

         if (image.OffensiveCount > 0)
         {
            if (!HttpContext.Current.User.IsInRole(TadMapRoles.Administrator))
               throw new SecurityException("Only administrator can view images marked as offensive");
         }
         else if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
            UserOpenId openId = tadmap.UserOpenIds.Single(i => i.OpenIdUrl == HttpContext.Current.User.Identity.Name);

            if (image.Privacy == 0 && image.UserId != openId.UserId)
            {
               if (!HttpContext.Current.User.IsInRole(TadMapRoles.Administrator))
                  throw new SecurityException("Cannot view another users image if it is marked as private.");
            }

            if (image.UserId == openId.UserId)
            {
               OwnerControls.Visible = true;
               ScriptManager.RegisterClientScriptInclude(Page, GetType(), "EditDetails", Page.ResolveClientUrl("JavaScript/ViewMap.js"));
               privacyCheckBox.Checked = image.Privacy > 0;
               PrivacyStatus.Text = image.Privacy == 0 ? "<b>Only you</b> can view this image." : "<b>Anyone</b> can view this image.";
            }
         }
         else
         {
            if (image.Privacy == 0)
               throw new Exception("Guest cannot view private image");
         }

         Title = "Tadmap - " + image.Title;
         m_lblTitle.Text = image.Title;
         m_lblDescription.Text = image.Description;

         m_imgPicture.ImageUrl = TadImage.GetPreviewUrl(image);

         DownloadOriginal.NavigateUrl = TadImage.GetOriginalUrl(image);

         // tilesets are not implemented for version the beta version one so we hide this button for now
         m_lbViewTileSet.Visible = false;
         m_lbCreateTileSet.Visible = false;
         //if (mImage.HasTileSet)
         //{
         //   m_lbViewTileSet.Visible = true;
         //   m_lbViewTileSet.PostBackUrl = "Dev.aspx?MapId=" + mImage.Id;
         //}
         //else
         //{
         //   m_lbViewTileSet.Visible = false;
         //}

         if (HttpContext.Current.User.IsInRole(TadMapRoles.Administrator))
         {
            Offensive.Visible = true;
            UnOffensive.Visible = true;
            Offensive.OnClientClick = "UpdateImage.Mark(imageId); return false;";
            UnOffensive.OnClientClick = "UpdateImage.UnMark(imageId); return false;";
         }
         else
         {
            Offensive.Visible = false;
            UnOffensive.Visible = false;
         }
      }
   }
コード例 #5
0
ファイル: ViewMap.aspx.cs プロジェクト: trevorpower/tadmap
   public static int MakePrivate(string id)
   {
      Tadmap tadmap = new Tadmap(Database.TadMapConnection);

      var images = from i in tadmap.UserImages
                   join u in tadmap.UserOpenIds on i.UserId equals u.UserId
                   where i.Id == new Guid(id) && u.OpenIdUrl == HttpContext.Current.User.Identity.Name
                   select i;

      if (images.Count() == 1)
      {
         UserImage image = images.First();

         image.Privacy = 0;

         tadmap.SubmitChanges();

         return image.Privacy;
      }
      else
      {
         throw new Exception("Could not marke as public");
      }
   }
コード例 #6
0
ファイル: Login.aspx.cs プロジェクト: trevorpower/tadmap
   private void CreateNewUser(string openIdUrl)
   {
      Tadmap db = new Tadmap(Database.TadMapConnection);

      User newUser = new User();
      newUser.Id = Guid.NewGuid();
      newUser.Name = string.Empty;

      UserRole newUserRole = new UserRole();
      newUserRole.UserId = newUser.Id;
      newUserRole.Role = TadMapRoles.Collector;

      UserOpenId newOpenId = new UserOpenId();
      newOpenId.UserId = newUser.Id;
      newOpenId.OpenIdUrl = openIdUrl;

      db.Users.InsertOnSubmit(newUser);
      db.UserRoles.InsertOnSubmit(newUserRole);
      db.UserOpenIds.InsertOnSubmit(newOpenId);

      db.SubmitChanges();
   }