コード例 #1
0
ファイル: GenController.cs プロジェクト: subhendude/Wutnu
        public ActionResult Index(string url)
        {
            //create the record
            var oUrl = new WutLink
            {
                RealUrl     = url,
                CreateDate  = DateTime.UtcNow,
                CreatedByIp = Request.UserHostAddress
            };

            //tag it if logged in, for posterity or cool reporting later
            if (User.Identity.IsAuthenticated)
            {
                oUrl.UserId = User.Identity.GetClaim <int>(CustomClaimTypes.UserId);
            }

            //save it
            oUrl = ShortUrlUtils.AddUrlToDatabase(oUrl, Wutcontext);

            //set it up to display
            ViewBag.ShortUrl    = ShortUrlUtils.PublicShortUrl(oUrl.ShortUrl);
            ViewBag.NavigateUrl = oUrl.RealUrl;

            //go back home
            return(View("~/Views/Home/Index.cshtml"));
        }
コード例 #2
0
        /// <summary>
        ///Grab the short URL and look it up for redirection
        ///see MVC routes for definition
        ///(if we wanted to authenticate the user that is trying to expand a link, here's where we'd do it)
        /// </summary>
        /// <param name="shortUrl"></param>
        /// <returns></returns>
        public ActionResult Redir(string id)
        {
            if (id == null)
            {
                return(View("Index"));
            }

            var res = ShortUrlUtils.RetrieveUrlFromDatabase(id, Wutcontext);

            if (res == null || (res != null && res.RealUrl == null))
            {
                ViewBag.Error = "Sorry, that URL wasn't found. Please check your source and try again.";
                return(View("Index"));
            }
            if (res.IsProtected)
            {
                //redirect to the authorized entry point
                return(Redirect("/a/" + id));
            }

            if (res.IsAzureBlob)
            {
                res = GenToken(res);
            }

            return(LogAndRedir(res));
        }
コード例 #3
0
 public Url(string realUrl)
 {
     RealUrl      = realUrl;
     Date         = DateTime.Now;
     ShortenedUrl = ShortUrlUtils.GetRandomChars();
     //Image = Thumbnail.CreateThumbnailImage(RealUrl, 240, 160);
 }
コード例 #4
0
        public PartialViewResult _GenerateUrl(UrlGeneratorViewModel model)
        {
            ShortUrlContainer oShortUrl = new ShortUrlContainer();
            ShortUrlUtils     utils     = new ShortUrlUtils();

            oShortUrl.Title       = model.Title;
            oShortUrl.Description = model.Description;
            oShortUrl.RealUrl     = model.Link;
            oShortUrl.Image       = model.Image;


            oShortUrl.ShortenedUrl = utils.UniqueShortUrl();
            oShortUrl.CreateDate   = DateTime.Now;
            oShortUrl.CreatedBy    = Request.UserHostAddress;

            //utils.AddUrlToDatabase(oShortUrl);

            oShortUrl.ShortenedUrl = utils.PublicShortUrl(oShortUrl.ShortenedUrl);

            var generatedUrl = new GeneratedUrlViewModel();

            generatedUrl.Link = oShortUrl.ShortenedUrl;

            return(PartialView("_GeneratedUrlResult", generatedUrl));
        }
コード例 #5
0
        public WutLinkPoco CreateUrl(dynamic data)
        {
            var oUrl = new WutLink
            {
                RealUrl     = data.realUrl,
                IsAzureBlob = data.isBlob,
                CreateDate  = DateTime.UtcNow,
                CreatedByIp = ((System.Web.HttpContextWrapper)Request.Properties["MS_HttpContext"]).Request.Se‌​rverVariables["HTTP_HOST"]
            };

            if (User.Identity.IsAuthenticated)
            {
                oUrl.UserId = UserId;
            }

            oUrl = ShortUrlUtils.AddUrlToDatabase(oUrl, Wutcontext);

            return(WutLinkPoco.GetPocoFromObject(oUrl));
        }
コード例 #6
0
        /// <summary>
        ///Grab the short URL and look it up for redirection
        ///see MVC routes for definition
        ///(if we wanted to authenticate the user that is trying to expand a link, here's where we'd do it)
        /// </summary>
        /// <param name="shortUrl"></param>
        /// <returns></returns>
        public ActionResult RedirAuth(string id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Signin", "Account", new { redir = "/a/" + id }));
            }

            if (id == null)
            {
                return(View("Index"));
            }

            var userId = User.Identity.GetClaim <int>(CustomClaimTypes.UserId);
            var email  = User.Identity.GetClaim(ClaimTypes.Email);
            var res    = ShortUrlUtils.RetrieveUrlFromDatabase(id, Wutcontext, userId, email);

            if (res == null || (res != null && res.RealUrl == null))
            {
                ViewBag.Error = "Sorry, that URL wasn't found or access is denied. Please check your source and try again.";
                return(View("Index"));
            }

            //checking to see if this user was granted access to this file
            var isAuth = res.UserEmailColl.Any(u => u == email);

            if (!isAuth)
            {
                Logging.WriteMessageToErrorLog(String.Format("User \"{0}\" attempted unauthorized retrieval of url \"{1}\" resolving to \"{2}\".", email, res.ShortUrl, res.RealUrl), Wutcontext);
                ViewBag.Error = "Sorry, you are not authorized to view this resource. This attempt has been logged. Please check with the issuer.";
                return(View("Index"));
            }

            if (res.IsAzureBlob)
            {
                res = GenToken(res);
            }

            return(LogAndRedir(res, userId));
        }
コード例 #7
0
 public WutLinkPoco GetUrl(string short_url)
 {
     short_url = ShortUrlUtils.InternalShortUrl(short_url);
     return(ShortUrlUtils.RetrieveUrlFromDatabase(short_url, Wutcontext));
 }
コード例 #8
0
 public IEnumerable <WutLinkPoco> DeleteUrl(WutLinkPoco oUrl)
 {
     ShortUrlUtils.DeleteUrl(oUrl, Wutcontext);
     return(GetUrls());
 }
コード例 #9
0
        public IEnumerable <WutLinkPoco> SaveUrl(WutLinkPoco oUrl)
        {
            oUrl = ShortUrlUtils.UpdateUrl(oUrl, Wutcontext, UserId);

            return(GetUrls());
        }
コード例 #10
0
        public Url()
        {
            Date = DateTime.Now;

            ShortenedUrl = ShortUrlUtils.GetRandomChars();
        }