diff --git a/endpoints/api.py b/endpoints/api.py index c0876f2a9..368576f8f 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -13,7 +13,7 @@ from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermission, AdministerRepositoryPermission) from endpoints import registry - +import re logger = logging.getLogger(__name__) @@ -55,6 +55,14 @@ def get_logged_in_user(): @app.route('/api/user/', methods=['POST']) def create_user_api(): user_data = request.get_json() + existing_user = model.get_user(user_data['username']) + if existing_user: + error_resp = jsonify({ + 'message': 'The username already exists' + }) + error_resp.status_code = 400 + return error_resp + try: new_user = model.create_user(user_data['username'], user_data['password'], user_data['email']) @@ -62,8 +70,13 @@ def create_user_api(): send_confirmation_email(new_user.username, new_user.email, code.code) return make_response('Created', 201) except model.DataModelException as ex: + message = ex.message + m = re.search('column ([a-zA-Z]+) is not unique', message) + if m and m.group(1): + message = m.group(1) + ' already exists' + error_resp = jsonify({ - 'message': ex.message, + 'message': message, }) error_resp.status_code = 400 return error_resp diff --git a/static/js/controllers.js b/static/js/controllers.js index 23bc13f64..3772662e9 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -100,18 +100,29 @@ function RepoListCtrl($scope, Restangular) { function LandingCtrl($scope, $timeout, Restangular, UserService) { $('.form-signup').popover(); + $('.spin').spin(); $scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) { $scope.user = currentUser; + if (currentUser && !currentUser.anonymous) { + document.location = '/#/repository'; + } }, true); $scope.awaitingConfirmation = false; + $scope.registering = false; + $scope.register = function() { + $('.form-signup').popover('hide'); + $scope.registering = true; + var newUserPost = Restangular.one('user/'); newUserPost.customPOST($scope.newUser).then(function() { $scope.awaitingConfirmation = true; + $scope.registering = false; }, function(result) { console.log("Displaying error message."); + $scope.registering = false; $scope.registerError = result.data.message; $timeout(function() { $('.form-signup').popover('show'); diff --git a/static/partials/landing.html b/static/partials/landing.html index fd0fab96b..af41f8917 100644 --- a/static/partials/landing.html +++ b/static/partials/landing.html @@ -9,13 +9,16 @@
- +
+ +
Thank you for registering! We have sent you an activation email. You must verify your email address before you can continue.
diff --git a/templates/index.html b/templates/index.html index 819d3e4f2..4e2ca8e6a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,7 +43,7 @@ - Quay + Quay