Add client side handling of user login throttling
This commit is contained in:
parent
07c7cdd51d
commit
066b3ed8f0
2 changed files with 50 additions and 14 deletions
|
@ -4,17 +4,24 @@
|
||||||
placeholder="Username or E-mail Address" ng-model="user.username" autofocus>
|
placeholder="Username or E-mail Address" ng-model="user.username" autofocus>
|
||||||
<input type="password" class="form-control input-lg" name="password"
|
<input type="password" class="form-control input-lg" name="password"
|
||||||
placeholder="Password" ng-model="user.password">
|
placeholder="Password" ng-model="user.password">
|
||||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign In</button>
|
|
||||||
|
|
||||||
<span class="social-alternate" quay-require="['GITHUB_LOGIN']">
|
<div class="alert alert-warning" ng-show="tryAgainSoon > 0">
|
||||||
<i class="fa fa-circle"></i>
|
Too many attempts have been made to login. Please try again in {{ tryAgainSoon }} second<span ng-if="tryAgainSoon != 1">s</span>.
|
||||||
<span class="inner-text">OR</span>
|
</div>
|
||||||
|
|
||||||
|
<span ng-show="tryAgainSoon == 0">
|
||||||
|
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign In</button>
|
||||||
|
|
||||||
|
<span class="social-alternate" quay-require="['GITHUB_LOGIN']">
|
||||||
|
<i class="fa fa-circle"></i>
|
||||||
|
<span class="inner-text">OR</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<a id="github-signin-link" class="btn btn-primary btn-lg btn-block" href="javascript:void(0)" ng-click="showGithub()"
|
||||||
|
quay-require="['GITHUB_LOGIN']">
|
||||||
|
<i class="fa fa-github fa-lg"></i> Sign In with GitHub
|
||||||
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<a id="github-signin-link" class="btn btn-primary btn-lg btn-block" href="javascript:void(0)" ng-click="showGithub()"
|
|
||||||
quay-require="['GITHUB_LOGIN']">
|
|
||||||
<i class="fa fa-github fa-lg"></i> Sign In with GitHub
|
|
||||||
</a>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="alert alert-danger" ng-show="invalidCredentials">Invalid username or password.</div>
|
<div class="alert alert-danger" ng-show="invalidCredentials">Invalid username or password.</div>
|
||||||
|
|
|
@ -2245,7 +2245,10 @@ quayApp.directive('signinForm', function () {
|
||||||
'signInStarted': '&signInStarted',
|
'signInStarted': '&signInStarted',
|
||||||
'signedIn': '&signedIn'
|
'signedIn': '&signedIn'
|
||||||
},
|
},
|
||||||
controller: function($scope, $location, $timeout, ApiService, KeyService, UserService, CookieService, Features, Config) {
|
controller: function($scope, $location, $timeout, $interval, ApiService, KeyService, UserService, CookieService, Features, Config) {
|
||||||
|
$scope.tryAgainSoon = 0;
|
||||||
|
$scope.tryAgainInterval = null;
|
||||||
|
|
||||||
$scope.showGithub = function() {
|
$scope.showGithub = function() {
|
||||||
if (!Features.GITHUB_LOGIN) { return; }
|
if (!Features.GITHUB_LOGIN) { return; }
|
||||||
|
|
||||||
|
@ -2275,7 +2278,15 @@ quayApp.directive('signinForm', function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.$on('$destroy', function() {
|
||||||
|
if ($scope.tryAgainInterval) {
|
||||||
|
$interval.cancel($scope.tryAgainInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$scope.signin = function() {
|
$scope.signin = function() {
|
||||||
|
if ($scope.tryAgainSoon > 0) { return; }
|
||||||
|
|
||||||
$scope.markStarted();
|
$scope.markStarted();
|
||||||
|
|
||||||
ApiService.signinUser($scope.user).then(function() {
|
ApiService.signinUser($scope.user).then(function() {
|
||||||
|
@ -2298,8 +2309,26 @@ quayApp.directive('signinForm', function () {
|
||||||
$location.path($scope.redirectUrl ? $scope.redirectUrl : '/');
|
$location.path($scope.redirectUrl ? $scope.redirectUrl : '/');
|
||||||
}, 500);
|
}, 500);
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
$scope.needsEmailVerification = result.data.needsEmailVerification;
|
if (result.status == 429 /* try again later */) {
|
||||||
$scope.invalidCredentials = result.data.invalidCredentials;
|
$scope.tryAgainSoon = result.headers('Retry-After');
|
||||||
|
|
||||||
|
// Cancel any existing interval.
|
||||||
|
if ($scope.tryAgainInterval) {
|
||||||
|
$interval.cancel($scope.tryAgainInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup a new interval.
|
||||||
|
$scope.tryAgainInterval = $interval(function() {
|
||||||
|
$scope.tryAgainSoon--;
|
||||||
|
if ($scope.tryAgainSoon <= 0) {
|
||||||
|
$scope.tryAgainInterval = null;
|
||||||
|
$scope.tryAgainSoon = 0;
|
||||||
|
}
|
||||||
|
}, 1000, $scope.tryAgainSoon);
|
||||||
|
} else {
|
||||||
|
$scope.needsEmailVerification = result.data.needsEmailVerification;
|
||||||
|
$scope.invalidCredentials = result.data.invalidCredentials;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue