public ActionResult ProfileApiEdit(ApiAuthenticationModel form) { var user = _userService.GetUserById(_workContext.CurrentUser.Id); if (user == null || !user.Active) return RedirectToAction("error404", "error"); AddHomeBreadcrumb(); AddBreadcrumb("Profile for " + user.DisplayName, Url.RouteUrl("UserProfile", new { userName = user.UserName })); AddBreadcrumb("Api Details", Url.RouteUrl("UserProfileApi")); AddBreadcrumb("Edit Api Details", Url.RouteUrl("UserProfileApiEdit", new { form.Id })); var api = _apiAuthenticationService.GetApiAuthenticationByUserIdandId(user.Id, form.Id); var model = api.ToModel(); if (model == null) { ErrorNotification("You do not have permissions to access this page"); return RedirectToAction("index", "home"); } if (!string.IsNullOrEmpty(form.WebsiteAddress)) model.WebsiteAddress = form.WebsiteAddress.ToLower().Replace("http://", "").TrimEnd('/'); if (!string.IsNullOrEmpty(form.NameOfApplication)) model.NameOfApplication = form.NameOfApplication; if (!string.IsNullOrEmpty(form.Description)) model.Description = form.Description; if (ModelState.IsValid) { api.ApiUser = user; api.WebsiteAddress = model.WebsiteAddress; api.NameOfApplication = model.NameOfApplication; api.Description = model.Description; _apiAuthenticationService.UpdateApiUsage(api); model.ShowToken = true; model.AccessToken = api.AccessToken; } return View(model); }
public UserApiModel() { ApiAuthentication = new ApiAuthenticationModel(); ShowToken = false; }
public static ApiAuthenticationModel ToModel(this ApiAuthentication entity) { if (entity == null) return null; var encryptionService = EngineContext.Current.Resolve<IEncryptionService>(); var model = new ApiAuthenticationModel { Active = entity.Active, CreatedDate = entity.CreatedDate, Deleted = entity.Deleted, Id = entity.Id, LastModifiedBy = entity.LastModifiedBy, LastModifiedDate = entity.LastModifiedDate, NameOfApplication = entity.NameOfApplication, ApiUser = entity.ApiUser.ToModel(), Description = entity.Description, SecretKey = entity.SecretKey, WebsiteAddress = entity.WebsiteAddress, AccessToken = encryptionService.EncryptText(entity.SecretKey + entity.WebsiteAddress) }; return model; }