Merge pull request #2066 from coreos-inc/select-username

Add support for temp usernames and an interstitial to confirm username
This commit is contained in:
josephschorr 2016-11-03 16:22:16 -04:00 committed by GitHub
commit 233b2be5c2
18 changed files with 388 additions and 24 deletions

View file

@ -191,6 +191,9 @@ quayApp.config(['$routeProvider', '$locationProvider', 'pages', function($routeP
// Privacy
.route('/privacy', 'privacy')
// Change username
.route('/updateuser', 'update-user')
// Landing Page
.route('/', 'landing')

View file

@ -11,13 +11,14 @@ angular.module('quay').directive('namespaceInput', function () {
scope: {
'binding': '=binding',
'isBackIncompat': '=isBackIncompat',
'hasExternalError': '=?hasExternalError',
'namespaceTitle': '@namespaceTitle',
},
controller: function($scope, $element) {
$scope.USERNAME_PATTERN = USERNAME_PATTERN;
$scope.usernamePattern = new RegExp(USERNAME_PATTERN);
$scope.$watch('binding', function(binding) {
if (!binding) {
$scope.isBackIncompat = false;

View file

@ -0,0 +1,80 @@
(function() {
/**
* Update user page.
*/
angular.module('quayPages').config(['pages', function(pages) {
pages.create('update-user', 'update-user.html', UpdateUserCtrl, {
'title': 'Confirm Username'
});
}]);
function UpdateUserCtrl($scope, UserService, $location, ApiService) {
$scope.state = 'loading';
UserService.updateUserIn($scope, function(user) {
if (!user.prompts || !user.prompts.length) {
$location.path('/');
return;
}
$scope.state = 'editing';
$scope.username = user.username;
});
var confirmUsername = function(username) {
if (username == $scope.user.username) {
$scope.state = 'confirmed';
return;
}
$scope.state = 'confirming';
var params = {
'username': username
};
ApiService.getUserInformation(null, params).then(function() {
$scope.state = 'existing';
}, function(resp) {
if (resp.status == 404) {
$scope.state = 'confirmed';
} else {
$scope.state = 'error';
}
});
};
$scope.updateUsername = function(username) {
$scope.state = 'updating';
var data = {
'username': username
};
ApiService.changeUserDetails(data).then(function() {
window.location = '/';
}, ApiService.errorDisplay('Could not update username'));
};
$scope.hasPrompt = function(user, prompt_name) {
if (!user.prompts) {
return false;
}
for (var i = 0; i < user.prompts.length; ++i) {
if (user.prompts[i] == prompt_name) {
return true;
}
}
return false;
};
$scope.$watch('username', function(username) {
if (!username) {
$scope.state = 'editing';
return;
}
confirmUsername(username);
});
}
})();

View file

@ -91,8 +91,14 @@ function(ApiService, CookieService, $rootScope, Config, $location) {
}
}
// If the loaded user has a prompt, redirect them to the update page.
if (loadedUser.prompts && loadedUser.prompts.length) {
$location.path('/updateuser');
return;
}
if (opt_callback) {
opt_callback();
opt_callback(loadedUser);
}
};