Exemplo n.º 1
0
        public IActionResult Login(User user)
        {
            var  repository = new UrlRepository(_conn);
            User u          = repository.GetUserByEmail(user.Email);

            if (u == null)
            {
                return(Redirect("/account/login"));
            }

            else if (!repository.Match(user.Password, u.Password))
            {
                return(Redirect("/account/login"));
            }

            var claims = new List <Claim>
            {
                new Claim("user", user.Email)
            };

            HttpContext.SignInAsync(new ClaimsPrincipal(
                                        new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait();


            return(Redirect("/home/index"));
        }
Exemplo n.º 2
0
        public IActionResult NewUrl(string hashedUrl)
        {
            UrlRepository repo     = new UrlRepository(_connectionString);
            string        original = repo.GetOriginalUrl(hashedUrl).OriginalUrl;

            return(Json(original));
        }
Exemplo n.º 3
0
        public void Test_Upsert_100_SameDomain()
        {
            UrlRepository repo = new UrlRepository();

            for (int i = 0; i < 100; i++)
            {
                Url entity = new Url();
                entity.Href = String.Format("http://demo.com/{0}", i);

                Url response = repo.Upsert(entity);
                Assert.IsNotNull(response);
                Assert.IsInstanceOfType(response, typeof(Url));
                Assert.IsNotNull(response.Id);
                Assert.IsNotNull(response.CasValue);

                Url responseCheck = repo.Get(response.Id);
                Assert.IsNotNull(responseCheck);
                Assert.IsInstanceOfType(responseCheck, typeof(Url));
                Assert.IsNotNull(responseCheck.Id);
                Assert.IsNotNull(responseCheck.CasValue);

                Assert.IsTrue(response.Id.Equals(responseCheck.Id));
                Assert.IsTrue(response.Href.Equals(responseCheck.Href));
            }
        }
Exemplo n.º 4
0
        public IActionResult ShortenUrl(string url)
        {
            var     authDb = new UserRepository(_connectionString);
            var     repo   = new UrlRepository(_connectionString);
            UrlLink ul     = new UrlLink();

            if (User.Identity.IsAuthenticated)
            {
                ul.HashedUrl = repo.GetHashedUrlForUser(url, authDb.GetIdForEmail(User.Identity.Name));
            }
            else
            {
                ul.HashedUrl = repo.GetHashedUrl(url);
            }

            if (ul.HashedUrl == null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    repo.AddUrl(url, authDb.GetIdForEmail(User.Identity.Name));
                }
                else
                {
                    repo.AddUrl(url, null);
                }
                ul.HashedUrl = repo.GetHashedUrl(url);
            }
            return(Json(new HashedObj {
                HashedUrl = GetFullUrl(ul.HashedUrl)
            }));
        }
Exemplo n.º 5
0
        public ActionResult Register(User user, string password)
        {
            var manager = new UrlRepository(Properties.Settings.Default.ConStr);

            manager.AddUser(user, password);
            return(Redirect("LogIn"));
        }
Exemplo n.º 6
0
        public static List <Log> ListByUrlAndStatus(DateTime start, DateTime end, ErrorType errorType)
        {
            var logRepository = new LogRepository();
            var urlRepository = new UrlRepository();

            var items = logRepository.List(start, end, ErrorType.ERR);

            List <Log> logItems = new List <Log>();

            foreach (var logItem in items)
            {
                var url = urlRepository.GetByName(logItem.Url);
                if (url != null)
                {
                    if (url.MonitorInactivity == true)
                    {
                        logItems.Add(logItem);
                    }
                }
                else
                {
                    logItems.Add(logItem);
                }
            }

            return(logItems);
        }
Exemplo n.º 7
0
        public IActionResult ShortenURL(Url url)
        {
            var authDb = new Authentication(_connectionString);
            var user   = authDb.GetByEmail(User.Identity.Name);

            var repo = new UrlRepository(_connectionString);

            if (!repo.DoesOriginalUrlExist(url.UrlOriginal))
            {
                url.UserId = user.Id;
                url.Views  = 0;
                var foo = true;
                while (foo)
                {
                    url.UrlShortened = ShortId.Generate(8);
                    if (!repo.DoesShortenedUrlExist(url.UrlShortened))
                    {
                        repo.AddUrl(url);
                        foo = false;
                        break;
                    }
                }
            }

            return(Json(url.UrlShortened));
        }
Exemplo n.º 8
0
        public IActionResult SignUp(User user)
        {
            var repository = new UrlRepository(_conn);

            repository.AddUser(user);
            return(Redirect("/account/login"));
        }
Exemplo n.º 9
0
        public IActionResult MyAccount()
        {
            var urlRepo = new UrlRepository(_connectionString);
            var authDb  = new UserRepository(_connectionString);
            var urls    = urlRepo.GetUrlsForUser(authDb.GetIdForEmail(User.Identity.Name));

            return(View(urls));
        }
Exemplo n.º 10
0
        public string AddUrl(string completeUrl, int userId)
        {
            var    repo    = new UrlRepository(_conn);
            string urlHash = repo.AddUrl(completeUrl, userId);

            //return Json(new { urlHash = completeUrl });
            return(urlHash);
        }
Exemplo n.º 11
0
        public new ActionResult View(string shortUrl)
        {
            var manager  = new UrlRepository(Properties.Settings.Default.ConStr);
            var original = manager.GetOriginal(shortUrl);

            manager.IncremementViews(original.Id);

            return(Redirect($"{original.OriginalUrl}"));
        }
Exemplo n.º 12
0
        public IActionResult Index()
        {
            var authDb = new Authentication(_connectionString);
            var user   = authDb.GetByEmail(User.Identity.Name);

            var repo = new UrlRepository(_connectionString);

            return(View());
        }
Exemplo n.º 13
0
        public IActionResult RedirectToUrl(string shortenedUrl)
        {
            var repo = new UrlRepository(_connectionString);
            Url url  = repo.GetOriginalUrl(shortenedUrl);

            repo.UpdateUrl(url.Id);

            return(Redirect(url.UrlOriginal));
        }
Exemplo n.º 14
0
        private void LoadDataCache(IApplicationBuilder app)
        {
            var repo   = new UrlRepository();
            var result = repo.GetAll();

            if (result != null && result.Count > 0)
            {
                var cache = app.ApplicationServices.GetService <IDataCache>();
                cache.SetValue(StrategyConstants.SingleLayerCache, result);
            }
        }
Exemplo n.º 15
0
        public ActionResult Index(string shortName)
        {
            UrlRepository repo = new UrlRepository();
            string url = repo.GetUrl(shortName);

            if (string.IsNullOrEmpty(url)) {
                return View();
            }

            return Redirect(url);
        }
Exemplo n.º 16
0
        public ActionResult ViewShortenedUrl(string shortenedurl)
        {
            var urlRepo = new UrlRepository(Properties.Settings.Default.ConStr);
            var url     = urlRepo.Get(shortenedurl);

            if (url == null)
            {
                return(View("/"));
            }
            urlRepo.IncrementViews(url.id);
            return(Redirect(url.RealURL));
        }
Exemplo n.º 17
0
        public ActionResult LoggedIn(string email, string password)
        {
            var manager = new UrlRepository(Properties.Settings.Default.ConStr);
            var user    = manager.LogIn(email, password);

            if (user == null)
            {
                return(RedirectToAction("LogIn"));
            }
            FormsAuthentication.SetAuthCookie(email, true);
            return(Redirect("Index"));
        }
Exemplo n.º 18
0
        public ActionResult Index(string shortName)
        {
            UrlRepository repo = new UrlRepository();
            string        url  = repo.GetUrl(shortName);

            if (string.IsNullOrEmpty(url))
            {
                return(View());
            }

            return(Redirect(url));
        }
Exemplo n.º 19
0
        public ActionResult ViewShortenedUrl(string urlHash)
        {
            var urlRepo = new UrlRepository(Properties.Settings.Default.ConStr);
            var url     = urlRepo.Get(urlHash);

            if (url == null)
            {
                return(View("NotFound"));
            }
            urlRepo.IncrementViews(url.Id);
            return(Redirect(url.OriginalUrl));
        }
Exemplo n.º 20
0
        public IActionResult ViewShortUrl(string hash)
        {
            var repo = new UrlRepository(_connectionString);
            var url  = repo.GetULByHash(hash);

            if (url == null)
            {
                return(Redirect("/"));
            }
            //var ul = repo.GetULByHash(hash);
            repo.AddView(url.Id);
            return(Redirect(url.Url));
        }
Exemplo n.º 21
0
 public IActionResult MyUrls()
 {
     if (User.Identity.IsAuthenticated)
     {
         var repo = new UrlRepository(_conn);
         var urls = repo.GetUrlsForUser(User.Identity.Name);
         return(View(urls));
     }
     else
     {
         return(Redirect("/account/login"));
     }
 }
Exemplo n.º 22
0
        public IActionResult ListOfUrLs()
        {
            var authDb = new Authentication(_connectionString);
            var user   = authDb.GetByEmail(User.Identity.Name);

            var          repo = new UrlRepository(_connectionString);
            UrlViewModel vm   = new UrlViewModel();

            vm.Urls     = repo.GetUrls(user.Id);
            vm.UserName = $"{user.FirstName} {user.LastName}";

            return(View(vm));
        }
Exemplo n.º 23
0
 public IActionResult Index()
 {
     if (User.Identity.IsAuthenticated)
     {
         var repo = new UrlRepository(_conn);
         var user = repo.GetUserByEmail(User.Identity.Name);
         return(View(user.Id));
     }
     else
     {
         return(View(0));
     }
 }
Exemplo n.º 24
0
        public void Test_GetSystemStatsAggregate()
        {
            UrlRepository repo = new UrlRepository();

            DateTime startDate = new DateTime(2013, 11, 18, 0, 0, 0);
            DateTime endDate = new DateTime(2013, 11, 20, 0, 0, 0);

            List<DataPoint> dataPoints = new List<DataPoint>();

            object[] startKey = { startDate.Year.ToString(), startDate.Month.ToString(), startDate.Day.ToString(), startDate.Hour.ToString() };
            object[] endKey = { endDate.Year.ToString(), endDate.Month.ToString(), endDate.Day.ToString(), endDate.Hour.ToString() };

            dataPoints = repo.GetSystemStatsAggregate(startKey, endKey, 100, false, 0, true);
            Assert.IsNotNull(dataPoints);
        }
Exemplo n.º 25
0
        public void Test_GetSystemStatsAggregate()
        {
            UrlRepository repo = new UrlRepository();

            DateTime startDate = new DateTime(2013, 11, 18, 0, 0, 0);
            DateTime endDate = new DateTime(2013, 11, 20, 0, 0, 0);

            List<DataPoint> dataPoints = new List<DataPoint>();

            object[] startKey = { startDate.Year.ToString(), startDate.Month.ToString(), startDate.Day.ToString(), startDate.Hour.ToString() };
            object[] endKey = { endDate.Year.ToString(), endDate.Month.ToString(), endDate.Day.ToString(), endDate.Hour.ToString() };

            dataPoints = repo.GetSystemStatsAggregate(startKey, endKey, 100, false, 0, true);
            Assert.IsNotNull(dataPoints);
        }
Exemplo n.º 26
0
        public void Test_UrlRepository_GetUrlList()
        {
            UrlRepository repo = new UrlRepository();

            // select first page
            Dto<Url> results = repo.GetUrlList();

            // start paging (10 docs per page)
            for (int page = 1; page < 100; page++)
            {
                string lastDocId = results.EId;
                string lastViewKey = results.EKey;
                results = repo.GetUrlList(page, 10, 0, lastViewKey, null, lastDocId, null);
            }

            Assert.IsNotNull(results);
        }
Exemplo n.º 27
0
        public ActionResult Shorten(string originalurl)
        {
            var manager = new UrlRepository(Properties.Settings.Default.ConStr);

            var url = manager.Check(originalurl, User.Identity.Name);

            if (url == null)
            {
                url = new Url
                {
                    OriginalUrl  = originalurl,
                    ShortenedUrl = ShortId.Generate(true, false),
                    UserId       = manager.GetByEmail(User.Identity.Name).Id
                };
                manager.AddUrl(url);
            }
            return(Json(Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "") + $"/{url.ShortenedUrl}"));
        }
Exemplo n.º 28
0
        public void Test_Remove_AllDocuments()
        {
            UrlRepository repo = new UrlRepository();

            // select first page
            Dto<Url> results = repo.GetUrlList();
            int page = 1;
            while (!results.Entities.IsNullOrEmpty())
            {
                foreach (var entity in results.Entities)
                    repo.Remove(entity.Id);

                string lastDocId = results.EId;
                string lastViewKey = results.EKey;

                results = repo.GetUrlList(page, 10, 0, lastViewKey, null, lastDocId, null);
                page++;
            };
        }
Exemplo n.º 29
0
        public void Test_Remove_AllDocuments()
        {
            UrlRepository repo = new UrlRepository();

            // select first page
            Dto<Url> results = repo.GetUrlList();
            int page = 1;
            while (!results.Entities.IsNullOrEmpty())
            {
                foreach (var entity in results.Entities)
                    repo.Remove(entity.Id);

                string lastDocId = results.EId;
                string lastViewKey = results.EKey;

                results = repo.GetUrlList(page, 10, 0, lastViewKey, null, lastDocId, null);
                page++;
            };
        }
Exemplo n.º 30
0
        public void Test_Upsert_Remove()
        {
            UrlRepository repo = new UrlRepository();

            Url entity = new Url();
            entity.Href = "http://test.com";

            Url response = repo.Upsert(entity);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Id);
            Assert.IsInstanceOfType(response, typeof(Url));

            // remove
            Assert.IsTrue(repo.Remove(response.Id));

            var oldEntity = repo.Get(response.Id);
            Assert.IsNull(oldEntity);
        }
Exemplo n.º 31
0
        public void Test_Serialize_Deserialize()
        {
            string test = "this_is_a_test";
            object[] o = { test };
            string a = JsonConvert.SerializeObject(o);
            string b = JsonConvert.SerializeObject(o.ToArray());
            string t = a.ToString();
            string t1 = b.ToString();

            Url entity = new Url();
            entity.Href = "http://www.test.com";

            UrlRepository repo = new UrlRepository();
            string json = repo.Serialize(entity);
            Assert.IsNotNull(json);

            Url result = repo.Deserialize(json);
            Assert.IsNotNull(result);
            Assert.IsTrue(entity.Href.Equals(result.Href));
        }
Exemplo n.º 32
0
        public IActionResult UrlShortener(string url)
        {
            UrlRepository repo = new UrlRepository(_connectionString);

            UserRepository ur        = new UserRepository(_connectionString);
            string         hashedUrl = null;

            if (User.Identity.IsAuthenticated)
            {
                int id = ur.GetByEmail(User.Identity.Name).Id;
                hashedUrl = repo.AddUrl(url, id);
            }
            else
            {
                hashedUrl = repo.AddUrl(url);
            }


            return(Json(hashedUrl));
        }
Exemplo n.º 33
0
        public ActionResult ShortenUrl(string Realurl)
        {
            var urlrepo  = new UrlRepository(Properties.Settings.Default.ConStr);
            var userrepo = new UserRepository(Properties.Settings.Default.ConStr);
            var url      = urlrepo.GetUrl(User.Identity.Name, Realurl);

            if (url == null)
            {
                var user         = userrepo.GetByEmail(User.Identity.Name);
                var shortenedUrl = ShortId.Generate(true, false);
                url = new URL
                {
                    RealURL      = Realurl,
                    ShortenedURL = shortenedUrl,
                    UserId       = user.Id
                };
                urlrepo.AddUrl(url);
            }
            return(Json($"{ Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "")}/{url.ShortenedURL}"));
        }
Exemplo n.º 34
0
        public void Test_Serialize_Deserialize()
        {
            string test = "this_is_a_test";
            object[] o = { test };
            string a = JsonConvert.SerializeObject(o);
            string b = JsonConvert.SerializeObject(o.ToArray());
            string t = a.ToString();
            string t1 = b.ToString();

            Url entity = new Url();
            entity.Href = "http://www.test.com";

            UrlRepository repo = new UrlRepository();
            string json = repo.Serialize(entity);
            Assert.IsNotNull(json);

            Url result = repo.Deserialize(json);
            Assert.IsNotNull(result);
            Assert.IsTrue(entity.Href.Equals(result.Href));
        }
Exemplo n.º 35
0
        public ActionResult Index(FormCollection collection)
        {
            //TODO check for valid URL

            ShortUrl shortUrl = new ShortUrl();
            UrlRepository repo = new UrlRepository();

            string url = collection["url"];

            string shortName = repo.GetShortName(url);

            shortUrl.URL = url;
            shortUrl.ShortName = shortName;
            if (string.IsNullOrEmpty(shortName)) {
                shortUrl.ShortName = repo.GetNewShortName();
                repo.SaveUrl(shortUrl);
            }

            shortUrl.URL = string.Format("http://uurl.co/{0}", shortUrl.ShortName);
            return View(shortUrl);
        }
Exemplo n.º 36
0
 public void Test_GetUrlCountByUser()
 {
     UrlRepository repo = new UrlRepository();
     int count = repo.GetUrlCountByUser("YuriMenko34");
 }
Exemplo n.º 37
0
        public void Test_UrlRepository_GetUrlList()
        {
            UrlRepository repo = new UrlRepository();

            // select first page
            Dto<Url> results = repo.GetUrlList();

            // start paging (10 docs per page)
            for (int page = 1; page < 100; page++)
            {
                string lastDocId = results.EId;
                string lastViewKey = results.EKey;
                results = repo.GetUrlList(page, 10, 0, lastViewKey, null, lastDocId, null);
            }

            Assert.IsNotNull(results);
        }
Exemplo n.º 38
0
        public void Test_Upsert_100()
        {
            UrlRepository repo = new UrlRepository();

            for (int i = 0; i < 100; i++)
            {

                Url entity = new Url();
                entity.Href = String.Format("http://testdomain{0}.com", i);
                entity.Tags.Add("demo");
                entity.Tags.Add("test");
                Url response = repo.Upsert(entity);
                Assert.IsNotNull(response);
                Assert.IsInstanceOfType(response, typeof(Url));
                Assert.IsNotNull(response.Id);
                Assert.IsNotNull(response.CasValue);

                Url responseCheck = repo.Get(response.Id);
                Assert.IsNotNull(responseCheck);
                Assert.IsInstanceOfType(responseCheck, typeof(Url));
                Assert.IsNotNull(responseCheck.Id);
                Assert.IsNotNull(responseCheck.CasValue);

                Assert.IsTrue(response.Id.Equals(responseCheck.Id));
                Assert.IsTrue(response.Href.Equals(responseCheck.Href));
            }
        }
Exemplo n.º 39
0
 protected void Application_BeginRequest()
 {
     COUNT_USERS = new UserRepository().Users.Count;
     COUNT_URLS = new UrlRepository().Urls.Count;
     IO.Reload();
 }
Exemplo n.º 40
0
        public void Test_UrlRepository_GetDto()
        {
            UrlRepository repo = new UrlRepository();

            int page = 1;
            int pageSize = 10;
            string endKey = null;
            string endDocId = null;

            string endKey2 = null;
            string endDocId2 = null;
            int rowCount = 0;
            do
            {
                Dto<Url> results = repo.GetUrlList(page, pageSize, 0, endKey, null, endDocId, null);
                Assert.IsNotNull(results.Entities);
                rowCount = results.TotalRows - page * pageSize;
                endKey = results.EKey;
                endDocId = results.EId;

                page++;

            } while (rowCount > 0);
        }
 public ForwardsController()
 {
     _repo = new UrlRepository();
     _usersRepo = new UserRepository();
 }
Exemplo n.º 42
0
        public void Test_Upsert_Remove()
        {
            UrlRepository repo = new UrlRepository();

            Url entity = new Url();
            entity.Href = "http://test.com";

            Url response = repo.Upsert(entity);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Id);
            Assert.IsInstanceOfType(response, typeof(Url));

            // remove
            Assert.IsTrue(repo.Remove(response.Id));

            var oldEntity = repo.Get(response.Id);
            Assert.IsNull(oldEntity);
        }