summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMarko Pušnik <marko.pusnik@guru.si>2015-10-05 19:59:05 +0200
committerMarko Pušnik <marko.pusnik@guru.si>2015-10-05 19:59:05 +0200
commit2f415bc811f7378091bd2285e9e822cb39eed3e6 (patch)
treeeff58afa8468334c4ae21b16b4d2367af3047816 /js
parent4a53a4594018fc6e538c87f7321ffefadc5edbd3 (diff)
sign up, reset password and profile pages + related comm messages
Diffstat (limited to 'js')
-rw-r--r--js/codeq/comms.js21
-rw-r--r--js/codeq/login.js9
-rw-r--r--js/codeq/navigation.js10
-rw-r--r--js/codeq/profile.js56
4 files changed, 92 insertions, 4 deletions
diff --git a/js/codeq/comms.js b/js/codeq/comms.js
index 3671e95..54a912f 100644
--- a/js/codeq/comms.js
+++ b/js/codeq/comms.js
@@ -297,10 +297,29 @@
});
};
if (socket) return performLogin();
- // this is the only method where we do connect() first, if we're not already connected
+ // this is the 1st method where we do connect() first, if we're not already connected
return this.connect().then(performLogin);
},
+ 'logout': function () {
+ return this.send({'action': 'logout'});
+ },
+
+ 'signup': function (username, password) {
+ var myself = this,
+ performSignUp = function () {
+ return myself.send({'action': 'signup', 'username': username, 'password': password});
+ };
+
+ if (socket) return performSignUp();
+ // this is the 2nd method where we do connect() first, if we're not already connected
+ return this.connect().then(performSignUp);
+ },
+
+ 'changePassword': function (newpassword) {
+ return this.send({'action': 'change_password', 'password': newpassword});
+ },
+
'updateSettings': function (new_settings){
return this.send({'action': 'settings', 'sid': sid, 'settings': new_settings});
},
diff --git a/js/codeq/login.js b/js/codeq/login.js
index 391592b..d5bcd90 100644
--- a/js/codeq/login.js
+++ b/js/codeq/login.js
@@ -15,6 +15,9 @@
$('#disabled').css('cursor', '');
if (data.code !== 0) throw new Error('Login failed, code: ' + data.code + ', message: ' + data.message);
+ //merge profile
+ $('#profileUsername').html($('#username').val());
+
//merge these settings into the already existing default settings
var sett = data.settings;
$.merge(true, codeq.settings, sett);
@@ -47,14 +50,14 @@
}
});
$('#modalLogIn').modal();
-
- $("#screen_login").css('display', '');
+ //$("#screen_login").css('display', '');
$('#disabled').css('display', 'none');
},
'exit' : function(){
$("#submit").off('click', loginFun);
formInputs.off('keyup');
- $("#screen_login").css('display', 'none');
+ $('#modalLogIn').modal('hide');
+ //$("#screen_login").css('display', 'none');
$('#signed-in-title').html('Signed in as '+$('#username').val());
$("#password").val('');
}
diff --git a/js/codeq/navigation.js b/js/codeq/navigation.js
index 4eff834..a1b8f3d 100644
--- a/js/codeq/navigation.js
+++ b/js/codeq/navigation.js
@@ -102,6 +102,16 @@
e.preventDefault();
});
$('#navigation-logout').on('click', function(e){
+ codeq.comms.logout()
+ .then(function (data) {
+ console.log(data);
+ //codeq.globalStateMachine.transition('login');
+ })
+ .fail(function (reason) {
+ console.log(reason);
+ })
+ .done();
+
codeq.globalStateMachine.transition('login');
e.preventDefault();//prevent this since we'll trigger a page reload otherwise
});
diff --git a/js/codeq/profile.js b/js/codeq/profile.js
index 5dcda05..be0bb1e 100644
--- a/js/codeq/profile.js
+++ b/js/codeq/profile.js
@@ -3,6 +3,62 @@
*/
(function(){
+
+ codeq.profile = {
+
+ 'signup': function () {
+ var jqUsername = $("#modalSignUpUsername"),
+ jqPassword = $("#modalSignUpPassword"),
+ jqVerify = $("#modalSignUpVerify");
+
+ if (jqUsername.val() == "" || jqPassword.val() == "" || jqVerify.val() == "") {
+ alert('Some fields are empty.');
+ }
+ else if (jqPassword.val() != jqVerify.val()) {
+ alert('Passwords do not match.');
+ }
+ else {
+ codeq.comms.signup(jqUsername.val(), jqPassword.val())
+ .then(function (data) {
+ //back to login
+ $('#modalSignUp').modal('hide');
+ alert('Welcome '+ jqUsername.val() +'. Thanks for signing up.');
+ $('#modalLogIn').modal('show');
+ //assume user wants to sign-in with signed username
+ $("#username").val(jqUsername.val());
+ //clear
+ jqUsername.val('');
+ jqPassword.val('');
+ jqVerify.val('');
+ })
+ .done();
+ }
+
+ },
+
+ 'changePassword': function () {
+ var jqNew = $("#modalChangePasswordNew"),
+ jqVerify = $("#modalChangePasswordVerify");
+
+ if (jqNew.val() == "" || jqVerify.val() == "") {
+ alert('Some fields are empty.');
+ }
+ else if (jqNew.val() != jqVerify.val()) {
+ alert('Passwords do not match.');
+ }
+ else {
+ codeq.comms.changePassword(jqNew.val())
+ .then(function (data) {
+ $('#modalChangePassword').modal('hide');
+ jqNew.val('');
+ jqVerify.val('');
+ alert('Password changed.');
+ })
+ .done();
+ }
+ }
+ };
+
codeq.globalStateMachine.register('profile',{
'enter': function(){