- 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,
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

View file

@ -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');

View file

@ -9,13 +9,16 @@
<div class="signup-container">
<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="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="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>
</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 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>

View file

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