Skip to content

Commit

Permalink
Merge pull request #786 from dhruvmisra/fix/userExistsALert
Browse files Browse the repository at this point in the history
[Issue #580 fix] Added username check on the first screen
  • Loading branch information
llaske authored May 2, 2020
2 parents fa452ad + ddfb499 commit c9e3f8f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
44 changes: 43 additions & 1 deletion js/firstscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,14 @@ enyo.kind({
if (name.length == 0) {
return;
}
this.step++;

if (util.getClientType() == constant.appType && (this.createnew || !this.$.server.getValue())) { // No password for the app when create new or server is null
this.step += 2;
this.displayStep();
} else if(!this.createnew) { // Login
this.step++;
} else { // Signup
this.checkUsername(name);
}
this.displayStep();
} else if (this.step == 3) {
Expand Down Expand Up @@ -423,6 +428,43 @@ enyo.kind({
}
},

checkUsername: function(name) {
var that = this;
that.$.spinner.setShowing(true);
myserver.postUser(
{
name: name,
role: "student",
beforeSignup: true
},
function(inSender, inResponse) {
if(!inResponse.exists) {
// Username unique
that.step++;
that.displayStep();
}
that.$.spinner.setShowing(false);
},
function(response, error) {
if(error == 2) {
// Server does not support fix -> old workflow
that.step++;
that.displayStep();
} else {
// Server supports fix -> new workflow
if(error == 22) {
// Username already exists
that.$.warningmessage.setContent(l10n.get("UserAlreadyExist"));
} else {
that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
}
that.$.warningmessage.setShowing(true);
}
that.$.spinner.setShowing(false);
}
);
},

createUser: function() {
var that = this;
myserver.postUser(
Expand Down
10 changes: 6 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ define(["settings"], function(preferences) {
}
});
ajax.response(function(inSender, inResponse) {
var newuser = {"name": user.name, "password": user.password};
server.loginUser(newuser, function(loginSender, loginResponse) {
preferences.setToken({'x_key': inResponse._id, 'access_token': loginResponse.token});
});
if(!user.beforeSignup) {
var newuser = {"name": user.name, "password": user.password};
server.loginUser(newuser, function(loginSender, loginResponse) {
preferences.setToken({'x_key': inResponse._id, 'access_token': loginResponse.token});
});
}
if (response) response(inSender, inResponse);
});
ajax.error(function(inResponse) {
Expand Down

0 comments on commit c9e3f8f

Please sign in to comment.