- Better error messages for sign up

- Show a throbber while working on sign up
- Have the front page redirect to the repositories view when logged in
This commit is contained in:
Joseph Schorr 2013-10-01 22:13:43 -04:00
parent 211fd6bcd7
commit 31914da4ca
4 changed files with 31 additions and 4 deletions

View file

@ -13,7 +13,7 @@ from auth.permissions import (ReadRepositoryPermission,
ModifyRepositoryPermission, ModifyRepositoryPermission,
AdministerRepositoryPermission) AdministerRepositoryPermission)
from endpoints import registry from endpoints import registry
import re
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -55,6 +55,14 @@ def get_logged_in_user():
@app.route('/api/user/', methods=['POST']) @app.route('/api/user/', methods=['POST'])
def create_user_api(): def create_user_api():
user_data = request.get_json() 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: try:
new_user = model.create_user(user_data['username'], user_data['password'], new_user = model.create_user(user_data['username'], user_data['password'],
user_data['email']) user_data['email'])
@ -62,8 +70,13 @@ def create_user_api():
send_confirmation_email(new_user.username, new_user.email, code.code) send_confirmation_email(new_user.username, new_user.email, code.code)
return make_response('Created', 201) return make_response('Created', 201)
except model.DataModelException as ex: 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({ error_resp = jsonify({
'message': ex.message, 'message': message,
}) })
error_resp.status_code = 400 error_resp.status_code = 400
return error_resp return error_resp

View file

@ -100,18 +100,29 @@ function RepoListCtrl($scope, Restangular) {
function LandingCtrl($scope, $timeout, Restangular, UserService) { function LandingCtrl($scope, $timeout, Restangular, UserService) {
$('.form-signup').popover(); $('.form-signup').popover();
$('.spin').spin();
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) { $scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
$scope.user = currentUser; $scope.user = currentUser;
if (currentUser && !currentUser.anonymous) {
document.location = '/#/repository';
}
}, true); }, true);
$scope.awaitingConfirmation = false; $scope.awaitingConfirmation = false;
$scope.registering = false;
$scope.register = function() { $scope.register = function() {
$('.form-signup').popover('hide');
$scope.registering = true;
var newUserPost = Restangular.one('user/'); var newUserPost = Restangular.one('user/');
newUserPost.customPOST($scope.newUser).then(function() { newUserPost.customPOST($scope.newUser).then(function() {
$scope.awaitingConfirmation = true; $scope.awaitingConfirmation = true;
$scope.registering = false;
}, function(result) { }, function(result) {
console.log("Displaying error message."); console.log("Displaying error message.");
$scope.registering = false;
$scope.registerError = result.data.message; $scope.registerError = result.data.message;
$timeout(function() { $timeout(function() {
$('.form-signup').popover('show'); $('.form-signup').popover('show');

View file

@ -9,13 +9,16 @@
<div class="signup-container"> <div class="signup-container">
<div ng-show="user.anonymous"> <div ng-show="user.anonymous">
<form class="form-signup" name="signupForm" ng-submit="register()" data-trigger="manual" data-content="{{ registerError }}" data-placement="left" ng-show="!awaitingConfirmation"> <form class="form-signup" name="signupForm" ng-submit="register()" data-trigger="manual" data-content="{{ registerError }}" data-placement="left" ng-show="!awaitingConfirmation && !registering">
<input type="text" class="form-control" placeholder="Create a username" name="username" ng-model="newUser.username" autofocus required> <input type="text" class="form-control" placeholder="Create a username" name="username" ng-model="newUser.username" autofocus required>
<input type="email" class="form-control" placeholder="Email address" ng-model="newUser.email" required> <input type="email" class="form-control" placeholder="Email address" ng-model="newUser.email" required>
<input type="password" class="form-control" placeholder="Create a password" ng-model="newUser.password" required> <input type="password" class="form-control" placeholder="Create a password" ng-model="newUser.password" required>
<input type="password" class="form-control" placeholder="Verify your password" ng-model="newUser.repeatePassword" match="newUser.password" required> <input type="password" class="form-control" placeholder="Verify your password" ng-model="newUser.repeatePassword" match="newUser.password" required>
<button class="btn btn-lg btn-primary btn-block" ng-disabled="signupForm.$invalid" type="submit">Get Started!</button> <button class="btn btn-lg btn-primary btn-block" ng-disabled="signupForm.$invalid" type="submit">Get Started!</button>
</form> </form>
<div ng-show="registering" style="text-align: center">
<span class="spin" color="#fff" style="display: inline-block"></span>
</div>
<div ng-show="awaitingConfirmation"> <div ng-show="awaitingConfirmation">
<div class="sub-message">Thank you for registering! We have sent you an activation email. You must <b>verify your email address</b> before you can continue.</div> <div class="sub-message">Thank you for registering! We have sent you an activation email. You must <b>verify your email address</b> before you can continue.</div>
</div> </div>

View file

@ -43,7 +43,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="#">Quay</a> <a class="navbar-brand" href="{{ user.anonymous ? '#' : '#/repository' }}">Quay</a>
</div> </div>
<!-- Collapsable stuff --> <!-- Collapsable stuff -->