public ActionResult <Response <string> > Create([FromForm] string fullUrl) { var guid = HelperUrl.GetGuid(Request); Response.Cookies.Append("Guid", guid); string shortUrl = ""; List <string> errors = new List <string>(); if (string.IsNullOrWhiteSpace(fullUrl)) { errors.Add("Параметр url не должен быть пустым"); } if (errors.Count == 0) { shortUrl = GetShortUrlName(); var link = new Link() { FullUrl = fullUrl, ShortUrl = shortUrl, СlickThroughs = 0, Guid = guid }; _linkService.Create(link); } return(new Response <string>() { Errors = errors, Object = shortUrl }); }
public ActionResult <Response <List <Link> > > Get() { var guid = HelperUrl.GetGuid(Request); return(new Response <List <Link> >() { Errors = new List <string>(), Object = _linkService.GetByGuid(guid) }); }
private string GetShortUrlName() { string shortUrl = HelperUrl.GetShortUrlName(); Link link = _linkService.GetByUrlShort(shortUrl); if (link == null) { return(shortUrl); } return(GetShortUrlName()); }
public async Task <IActionResult> Login(string returnUrl) { // build a model so we know what to show on the login page Response.Cookies.Append("returnUrl", HelperUrl.GetRedirectUrl(returnUrl)); var vm = await BuildLoginViewModelAsync(returnUrl); if (vm.IsExternalLoginOnly) { // we only have one option for logging in and it's an external provider return(RedirectToAction("Challenge", "External", new { provider = vm.ExternalLoginScheme, returnUrl })); } return(View(vm)); }
public async Task <IActionResult> Login(LoginInputModel model, string button) { // check if we are in the context of an authorization request var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl); var redirectDomain = HelperUrl.GetRedirectDomain(model.ReturnUrl); var ReturnUrl = HelperUrl.GetRedirectUrl(model.ReturnUrl); var clientId = HelperUrl.GetClientId(model.ReturnUrl); var userNameTest = "adm"; var passwordTest = "123456"; model.Username = userNameTest; model.Password = passwordTest; //if (ModelState.IsValid) //{ model.RememberLogin = true; // validate username/password against in-memory store var user = await _usersServices.Auth(model.Username, model.Password); if (user.IsNull()) { await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials")); ModelState.AddModelError("", AccountOptions.InvalidCredentialsErrorMessage); } else if (user.Error.IsNotNullOrEmpty()) { await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials")); ModelState.AddModelError("", user.Error); } else { if (user.ChangePassword) { model.ReturnUrl = "/ChangePassword?ReturnUrl=" + ReturnUrl; } await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.SubjectId, user.Username)); // only set explicit expiration here if user chooses "remember me". // otherwise we rely upon expiration configured in cookie middleware. AuthenticationProperties props = null; if (AccountOptions.AllowRememberLogin && model.RememberLogin) { props = new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration) }; } ; // issue authentication cookie with subject ID and username await HttpContext.SignInAsync(user.SubjectId, user.Username, props, user.Claims.ToArray()); if (context != null) { if (await _clientStore.IsPkceClientAsync(context.ClientId)) { // if the client is PKCE then we assume it's native, so this change in how to // return the response is for better UX for the end user. return(View("Redirect", new RedirectViewModel { RedirectUrl = model.ReturnUrl })); } // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null return(Redirect(model.ReturnUrl)); } // request for a local page if (Url.IsLocalUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } else if (string.IsNullOrEmpty(model.ReturnUrl)) { return(Redirect("~/")); } else { // user might have clicked on a malicious link - should be logged throw new Exception("invalid return URL"); } } //} // something went wrong, show form with error var vm = await BuildLoginViewModelAsync(model); return(View(vm)); }