summaryrefslogtreecommitdiff
path: root/js/codeq/signup.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq/signup.js')
-rw-r--r--js/codeq/signup.js46
1 files changed, 32 insertions, 14 deletions
diff --git a/js/codeq/signup.js b/js/codeq/signup.js
index d41f1d5..7f28e9f 100644
--- a/js/codeq/signup.js
+++ b/js/codeq/signup.js
@@ -31,12 +31,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqExitSignUpBtn = $('#signup-cancel'),
jqLangSelect = jqScreen.find('.lang-select'),
jqNavBarRight = $('.nav.navbar-nav.navbar-right'),
- jqNavigationHomeBtn = $('#navigation-home');
+ jqNavigationHomeBtn = $('#navigation-home'),
+ jqMessages = jqFormSignUp.find('.error,.success'),
+ redirectTimeout = null;
codeq.globalStateMachine.register('signup',{
'jqScreen': jqScreen,
- 'enter': function(){
+ 'enter': function() {
+ jqMessages.hide();
jqNavigationHomeBtn.off('click');//remove the click listener of this element here
jqNavBarRight.css('display','none');//hide settings etc.
$('#signed-in-title').html('');
@@ -47,22 +50,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
});
//prepare listener for successfull signup
- jqFormSignUp.on('submit',function(event) {
+ jqFormSignUp.on('submit', function(e) {
+ jqMessages.hide();
if (jqPassword.val() != jqVerify.val()) {
- alert('Passwords do not match.');
+ jqFormSignUp.find('.error.mismatch').show();
}
else {
codeq.comms.signup(jqUsername.val(), jqName.val(), jqEmail.val(), jqPassword.val())
.then(function (data) {
- if (data.code !== 0) throw new Error('Signup failed, code: ' + data.code + ', message: ' + data.message);
-
- var newUsername = jqUsername.val();//saving before transition (which will reset the value of the field)
- //back to login
- codeq.globalStateMachine.transition('login');
- alert('Welcome '+ newUsername +'. Thanks for signing up.');
- //assume user wants to sign-in with signed username
- $("#username").val(newUsername);
-
+ var jqSuccess = jqFormSignUp.find('.success'),
+ username = jqUsername.val();
+ switch (data.code) {
+ case 0: // everything OK
+ $("#username").val(username);
+ jqSuccess.find('.username').text(username);
+ jqSuccess.show();
+ // back to login after short pause
+ redirectTimeout = setTimeout(function() {
+ codeq.globalStateMachine.transition('login');
+ }, 2000);
+ break;
+ case 10: // username exists
+ jqFormSignUp.find('.error.username-exists').show();
+ break;
+ default:
+ throw new Error(data.message);
+ }
})
.fail(function (reason) {
codeq.log.error('Signup failed: ' + reason, reason);
@@ -70,7 +83,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
})
.done();
}
- event.preventDefault(); // Prevent the form from submitting via the browser.
+ e.preventDefault(); // Prevent the form from submitting via the browser.
});
// setup language selection links
@@ -80,6 +93,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
});
},
'exit' : function(){
+ if (redirectTimeout !== null) {
+ clearTimeout(redirectTimeout);
+ redirectTimeout = null;
+ }
+ jqMessages.hide();
jqScreen.css('display', 'none');
//re-enable the click listener
jqNavigationHomeBtn.on('click', function(e){