Beispiel #1
0
        public void UpdateApp(DeveloperApplicationDTO updatedApp)
        {
            DeveloperApplicationDTO currentApp = applications.Get(updatedApp.Id);

            if (IsCurrentUserAppOwner(currentApp))
            {
                if (!string.IsNullOrWhiteSpace(updatedApp.Name))
                {
                    currentApp.Name = updatedApp.Name;
                }

                if (!string.IsNullOrWhiteSpace(updatedApp.Website))
                {
                    currentApp.Website = updatedApp.Website;
                }

                if (updatedApp.CurrentSetApiVersion > 0)
                {
                    currentApp.CurrentSetApiVersion = updatedApp.CurrentSetApiVersion;
                }

                applications.Update(currentApp);
            }
            else
            {
                throw new NotAppOwnerException();
            }
        }
Beispiel #2
0
 private bool IsCurrentUserAppOwner(DeveloperApplicationDTO app)
 {
     try
     {
         DeveloperAccountDTO currentUser = auth.CurrentUser;
         return(currentUser.Email == app.DeveloperId);
     }
     catch
     {
         throw new DatabaseErrorException();
     }
 }
Beispiel #3
0
        public DeveloperApplicationDTO AddNew(AddNewApplicationForm form)
        {
            DeveloperApplicationDTO newApp = new DeveloperApplicationDTO()
            {
                Name                 = form.Name,
                Website              = form.Website,
                DeveloperId          = auth.CurrentUser.Email,
                Status               = ApplicationStatus.Valid,
                CreationDate         = DateTime.Now,
                ApiKey               = GenerateApiKey(),
                OriginalApiVersion   = apiInfo.CurrentVersion,
                CurrentSetApiVersion = apiInfo.CurrentVersion
            };

            applications.Create(newApp);

            return(newApp);
        }
Beispiel #4
0
 public IActionResult Edit(DeveloperApplicationDTO app)
 {
     logger.Info("Developer Applications: Edit - Posted", app);
     if (auth.IsSignedIn)
     {
         try
         {
             applicationService.UpdateApp(app);
             logger.Info("Developer Applications: Edit - Posted - App Successfully Updated", app);
             return(RedirectToAction("AccountHome", "Developer"));
         }
         catch (Exception e)
         {
             logger.Error("Developer Applications: Edit - Error", e);
             ViewData["Title"] = "Error";
             return(View("Hardfall"));
         }
     }
     logger.Info("Developer Applications: Edit - Posted - Not signed in");
     return(RedirectToAction("SignIn", "Developer"));
 }
Beispiel #5
0
 public IActionResult Edit(string appId)
 {
     logger.Info("Developer Applications: Edit - Requested", appId);
     if (auth.IsSignedIn)
     {
         try
         {
             DeveloperApplicationDTO app = applicationService.GetApp(appId);
             logger.Info("Developer Applications: Edit - Requested - Application Info", app);
             ViewData["Title"] = "Edit Application";
             return(View(app));
         }
         catch (Exception e)
         {
             logger.Error("Developer Applications: Edit - Error", e);
             ViewData["Title"] = "Error";
             return(View("Hardfall"));
         }
     }
     logger.Info("Developer Applications: Edit - Requested - Not signed in");
     return(RedirectToAction("SignIn", "Developer"));
 }
Beispiel #6
0
 public IActionResult Delete(DeveloperApplicationDTO app)
 {
     logger.Info("Developer Applications: Delete - Posted", app);
     if (auth.IsSignedIn)
     {
         try
         {
             applicationService.DeleteApp(app.Id);
             logger.Info("Developer Applications: Delete - Posted - App Successfully Deleted", app);
             return(RedirectToAction("AccountHome", "Developer"));
         }
         catch (Exception e)
         {
             logger.Error("Developer Applications: Delete - Posted ERROR", e);
             ViewData["Title"] = "Error";
             return(View("Hardfall"));
         }
     }
     logger.Info("Developer Applications: Delete - Posted - Not signed in", app);
     ViewData["Title"] = "Confirm Delete";
     return(View());
 }
Beispiel #7
0
 public IActionResult Delete(string appId)
 {
     logger.Info("Developer Applications: Delete - Requested", appId);
     if (auth.IsSignedIn)
     {
         try
         {
             DeveloperApplicationDTO app = applicationService.GetApp(appId);
             logger.Info("Developer Applications: Delete - Requested - App Successfully Retrieved", app);
             ViewData["Title"] = "Confirm Delete";
             return(View(app));
         }
         catch (Exception e)
         {
             logger.Error("Developer Applications: Delete - Requested ERROR", e);
             ViewData["Title"] = "Error";
             return(View("Hardfall"));
         }
     }
     logger.Info("Developer Applications: Delete - Requested - Not signed in", appId);
     return(RedirectToAction("SignIn", "Developer"));
 }
Beispiel #8
0
        public async Task <IActionResult> Link(RedirectItem newLink)
        {
            string apiKey = HttpContext.Request.Headers[header_apiKey];

            logger.Info("API POST /link - Request using APY key " + apiKey, newLink);

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                var e = new SimpleError("API Key is missing");
                logger.Error("API POST /link", e);
                return(BadRequest(e));
            }
            else if (string.IsNullOrWhiteSpace(newLink.URL))
            {
                var e = new SimpleError("url cannot be blank.");
                logger.Error("API POST /link", e);
                return(BadRequest());
            }

            try
            {
                DeveloperApplicationDTO app = applications.GetByApiKey(apiKey);
                if (app != null)
                {
                    bool isSafe = await _sba.CheckUrl(newLink.URL);

                    if (!isSafe)
                    {
                        app.UnsafeURLSubmissions++;
                        applications.Update(app);
                        logger.Info("API POST /link - unsafe URL");
                        return(BadRequest(new SimpleError("This URL has been marked as unsafe and cannot be added")));
                    }

                    newLink.DateAdded              = DateTime.Now;
                    newLink.TimesLoaded            = 0;
                    newLink.CreatedByApplicationId = app.Id;
                    RedirectItem ri = _DAL.AddNewRedirectItem(newLink);

                    if (ri != null)
                    {
                        logger.Info("API POST /link - successfully created", ri);
                        return(StatusCode(201, new ApiPostResponse(ri)));
                    }
                    else
                    {
                        var e = new SimpleError("An error has occured, please try again");
                        logger.Error("API POST /link", e);
                        return(StatusCode(500, e));
                    }
                }
                else
                {
                    var e = new SimpleError("Invalid API Key");
                    logger.Error("API POST /link", e);
                    return(BadRequest(e));
                }
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(FormatException) && e.Message.Contains("is not a valid 24 digit hex string") ||
                    e.GetType() == typeof(InvalidOperationException) && e.Message.Contains("Sequence contains no elements"))
                {
                    logger.Error("API POST /link - Invalid API Key " + apiKey, e);
                    return(BadRequest(new SimpleError("Invalid API Key")));
                }

                logger.Error("Unknown error occured", e);
                return(StatusCode(500, new SimpleError("An error has occured, please try again")));
            }
        }
Beispiel #9
0
        public bool ValidateApiKey(string key)
        {
            DeveloperApplicationDTO app = applications.GetByApiKey(key);

            return(app != null);
        }