Properly handle 401 error when adding city and key is invalid

master
Loic Blot 2017-07-03 22:30:38 +02:00
parent 3aa384b82d
commit 2a693ed161
4 changed files with 7 additions and 12 deletions

View File

@ -34,7 +34,7 @@ class CityController extends IntermediateController {
$this->userId = $userId; $this->userId = $userId;
$this->mapper = $mapper; $this->mapper = $mapper;
$this->settingsMapper = $settingsMapper; $this->settingsMapper = $settingsMapper;
$this->apiKey = $settingsMapper->getApiKey($this->userId); $this->apiKey = \OC::$server->getConfig()->getAppValue('weather', 'openweathermap_api_key', '');
} }
/** /**

View File

@ -37,7 +37,7 @@ class WeatherController extends IntermediateController {
$this->userId = $userId; $this->userId = $userId;
$this->mapper = $mapper; $this->mapper = $mapper;
$this->settingsMapper = $settingsMapper; $this->settingsMapper = $settingsMapper;
$this->apiKey = $settingsMapper->getApiKey($this->userId); $this->apiKey = \OC::$server->getConfig()->getAppValue('weather', 'openweathermap_api_key', '');
$this->metric = $settingsMapper->getMetric($this->userId); $this->metric = $settingsMapper->getMetric($this->userId);
} }

View File

@ -28,14 +28,6 @@ class SettingsMapper extends Mapper {
return $this->getSetting($userId, "home"); return $this->getSetting($userId, "home");
} }
public function setApiKey ($userId, $apiKey) {
$this->setSetting("apikey", $userId, $apiKey);
}
public function getApiKey ($userId) {
return $this->getSetting($userId, "apikey");
}
public function setMetric ($userId, $metric) { public function setMetric ($userId, $metric) {
$this->setSetting("metric", $userId, $metric); $this->setSetting("metric", $userId, $metric);
} }

View File

@ -198,7 +198,7 @@ app.controller('WeatherController', ['$scope', '$interval', '$timeout', '$compil
$scope.cityLoadNeedsAPIKey = false; $scope.cityLoadNeedsAPIKey = false;
} }
else if (r.status == 401) { else if (r.status == 401) {
$scope.cityLoadError = "Your OpenWeatherMap API key is invalid. Please provide a working API Key."; $scope.cityLoadError = "Your OpenWeatherMap API key is invalid. Contact your administrator to configure a valid API key in administration settings";
$scope.cityLoadNeedsAPIKey = true; $scope.cityLoadNeedsAPIKey = true;
} }
else { else {
@ -232,7 +232,10 @@ app.controller('WeatherController', ['$scope', '$interval', '$timeout', '$compil
} }
}, },
function (r) { function (r) {
if (r.status == 404) { if (r.status == 401) {
$scope.addCityError = "Your OpenWeatherMap API key is invalid. Contact your administrator to configure a valid API key in administration settings";
}
else if (r.status == 404) {
$scope.addCityError = "No city with this name found."; $scope.addCityError = "No city with this name found.";
} }
else if (r.status == 409) { else if (r.status == 409) {