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")); }
public IActionResult NewUrl(string hashedUrl) { UrlRepository repo = new UrlRepository(_connectionString); string original = repo.GetOriginalUrl(hashedUrl).OriginalUrl; return(Json(original)); }
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)); } }
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) })); }
public ActionResult Register(User user, string password) { var manager = new UrlRepository(Properties.Settings.Default.ConStr); manager.AddUser(user, password); return(Redirect("LogIn")); }
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); }
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)); }
public IActionResult SignUp(User user) { var repository = new UrlRepository(_conn); repository.AddUser(user); return(Redirect("/account/login")); }
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)); }
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); }
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}")); }
public IActionResult Index() { var authDb = new Authentication(_connectionString); var user = authDb.GetByEmail(User.Identity.Name); var repo = new UrlRepository(_connectionString); return(View()); }
public IActionResult RedirectToUrl(string shortenedUrl) { var repo = new UrlRepository(_connectionString); Url url = repo.GetOriginalUrl(shortenedUrl); repo.UpdateUrl(url.Id); return(Redirect(url.UrlOriginal)); }
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); } }
public ActionResult Index(string shortName) { UrlRepository repo = new UrlRepository(); string url = repo.GetUrl(shortName); if (string.IsNullOrEmpty(url)) { return View(); } return Redirect(url); }
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)); }
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")); }
public ActionResult Index(string shortName) { UrlRepository repo = new UrlRepository(); string url = repo.GetUrl(shortName); if (string.IsNullOrEmpty(url)) { return(View()); } return(Redirect(url)); }
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)); }
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)); }
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")); } }
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)); }
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)); } }
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); }
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); }
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}")); }
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++; }; }
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); }
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)); }
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)); }
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}")); }
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); }
public void Test_GetUrlCountByUser() { UrlRepository repo = new UrlRepository(); int count = repo.GetUrlCountByUser("YuriMenko34"); }
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)); } }
protected void Application_BeginRequest() { COUNT_USERS = new UserRepository().Users.Count; COUNT_URLS = new UrlRepository().Urls.Count; IO.Reload(); }
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(); }