Skip to content

Commit

Permalink
Improve usability of account upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Dec 10, 2023
1 parent bb9a768 commit 068507b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
27 changes: 25 additions & 2 deletions src/main/html/webapp/components/core/user/profile/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ export default Control.extend({
}, function(user) {
$(element).html(template({
user: user,
emailRequired: options.appState.attr('emailRequired')
anonymousAccount: (!options.appState.attr('emailRequired')),
emailProvided: (user.attr('mail') != "" && user.attr('mail') != undefined),
userEmailDescription: options.appState.attr('userEmailDescription'),
userWithoutEmailDescription: options.appState.attr('userWithoutEmailDescription')
}));
options.user = user;
$(element).fadeIn();
});
},

"#anonymous click" : function(){
if (!this.emailRequired){
var anonymousControl = $(this.element).find("[name='anonymous']");
var anonymous = !anonymousControl.is(':checked');
var mail = $(this.element).find("[name='mail']");
if (anonymous){
mail.attr('disabled','disabled');
} else {
mail.removeAttr('disabled');
}
mail.val("");
}
},

'submit': function(element, event) {
event.preventDefault();
var user = new User();
Expand All @@ -39,9 +56,15 @@ export default Control.extend({
var fullnameError = user.checkName(fullname.val());
this.updateControl(fullname, fullnameError);

var anonymous = false;
if (!this.emailRequired){
var anonymousControl = $(this.element).find("[name='anonymous']");
anonymous = !anonymousControl.is(':checked');
}

// mail
var mail = $(element).find("[name='mail']");
if (!this.emailRequired && mail.val() != ""){
if (!anonymous){
var mailError = user.checkMail(mail.val());
this.updateControl(mail, mailError);
} else {
Expand Down
26 changes: 24 additions & 2 deletions src/main/html/webapp/components/core/user/profile/profile.stache
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,34 @@ Please fill out the form below to change your account settings or your password.
<div class="invalid-feedback"></div>
</div>

{{#is(anonymousAccount, false)}}

<div class="form-group">
<label for="mail" class="control-label">E-Mail:</label>
<input id="mail" name="mail" type="text" value="{{user.mail}}" class="form-control col-sm-3">
<div class="invalid-feedback"></div>
</div>

{{else}}
<hr>
<div class="form-group">
<input type="checkbox" id="anonymous" name="anonymous" value="0" {{#emailProvided}}checked{{/emailProvided}}> <label for="anonymous" class="control-label">E-Mail Address</label>
<div class="form-group" style="margin-left: 30px;">
<p>
{{userEmailDescription}}
</p>
<label for="mail" class="control-label">E-Mail:</label>
<input id="mail" name="mail" type="text" class="form-control col-sm-3" autocomplete="off" {{#is(emailProvided, false)}}disabled{{/is}} value="{{user.mail}}">
<div class="invalid-feedback"></div>
<p><br>
{{userWithoutEmailDescription}}
</p>
</div>
</div>
<hr>

{{/is}}

<h4>Change password</h4>

<div class="form-group">
Expand Down Expand Up @@ -58,7 +80,7 @@ Please fill out the form below to change your account settings or your password.
<small class="{{#is(../user.apiTokenValid, false)}}text-danger{{#is}}">{{../user.apiTokenMessage}}</small>
{{else}}
<button class="btn btn-primary" id="create_token">Create API Token</button>
Expires in
Expires in
<select id="token_expiration">
<option value="30">30 days</option>
<option value="60">60 days</option>
Expand All @@ -77,4 +99,4 @@ Please fill out the form below to change your account settings or your password.
<div class="controls">
<button class="btn btn-danger" id="delete_account">Delete Account</button>
</div>
</div>
</div>
2 changes: 0 additions & 2 deletions src/main/html/webapp/components/core/user/signup/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export default Control.extend({
if (!this.emailRequired){
var anonymousControl = $(this.element).find("[name='anonymous']:checked");
var anonymous = (anonymousControl.val() == "1");
console.log(anonymous);
var mail = $(this.element).find("[name='mail']");
console.log(mail);
if (anonymous){
mail.attr('disabled','disabled');
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cloudgene/mapred/api/v2/users/RegisterUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RegisterUser extends BaseResource {

public static final String DEFAULT_ROLE = "User";

public static final String DEFAULT_UNTRUSTED_ROLE = "User_Untrusted";
public static final String DEFAULT_ANONYMOUS_ROLE = "Anonymous_User";

@Post
public Representation post(Representation entity) {
Expand Down Expand Up @@ -58,7 +58,7 @@ public Representation post(Representation entity) {
}
}

String[] roles = new String[] { mailProvided ? DEFAULT_ROLE : DEFAULT_UNTRUSTED_ROLE};
String[] roles = new String[] { mailProvided ? DEFAULT_ROLE : DEFAULT_ANONYMOUS_ROLE};

// check password
error = User.checkPassword(newPassword, confirmNewPassword);
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/cloudgene/mapred/api/v2/users/UserProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.restlet.resource.Get;
import org.restlet.resource.Post;

import cloudgene.mapred.core.ApiTokenVerifier;
import cloudgene.mapred.core.User;
import cloudgene.mapred.database.UserDao;
import cloudgene.mapred.representations.JSONAnswer;
Expand Down Expand Up @@ -98,15 +97,18 @@ public Representation post(Representation entity) {
newUser.getId()));
}

String roleMessage = " ";
if (!getSettings().isEmailRequired()) {
if ((newUser.getMail() == null || newUser.getMail().isEmpty()) && user.hasRole(RegisterUser.DEFAULT_ROLE)) {
newUser.replaceRole(RegisterUser.DEFAULT_ROLE, RegisterUser.DEFAULT_UNTRUSTED_ROLE);
log.info(String.format("User: changed role to %s for user %s (ID %s)", RegisterUser.DEFAULT_UNTRUSTED_ROLE, newUser.getUsername(),
newUser.replaceRole(RegisterUser.DEFAULT_ROLE, RegisterUser.DEFAULT_ANONYMOUS_ROLE);
log.info(String.format("User: changed role to %s for user %s (ID %s)", RegisterUser.DEFAULT_ANONYMOUS_ROLE, newUser.getUsername(),
newUser.getId()));
} else if ((newUser.getMail() != null && !newUser.getMail().isEmpty()) && user.hasRole(RegisterUser.DEFAULT_UNTRUSTED_ROLE)) {
newUser.replaceRole(RegisterUser.DEFAULT_UNTRUSTED_ROLE, RegisterUser.DEFAULT_ROLE);
roleMessage += "<br><br>Your account has been <b>downgraded</b>.<br>To apply these changes, please log out and log back in.";
} else if ((newUser.getMail() != null && !newUser.getMail().isEmpty()) && user.hasRole(RegisterUser.DEFAULT_ANONYMOUS_ROLE)) {
newUser.replaceRole(RegisterUser.DEFAULT_ANONYMOUS_ROLE, RegisterUser.DEFAULT_ROLE);
log.info(String.format("User: changed role to %s for user %s (ID %s)", RegisterUser.DEFAULT_ROLE, newUser.getUsername(),
newUser.getId()));
roleMessage += "<br><br>Your account has been <b>upgraded</b>.<br>To apply these changes, please log out and log back in.";
}
}

Expand All @@ -126,7 +128,7 @@ public Representation post(Representation entity) {

dao.update(newUser);

return new JSONAnswer("User profile sucessfully updated.", true);
return new JSONAnswer("User profile successfully updated." + roleMessage , true);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void testWithEmptyMailAndNoMailRequired() throws JSONException, IOExcepti
UserDao dao = new UserDao(TestServer.getInstance().getDatabase());
User user = dao.findByUsername("abcdefgh");
assertEquals(1, user.getRoles().length);
assertEquals(RegisterUser.DEFAULT_UNTRUSTED_ROLE, user.getRoles()[0]);
assertEquals(RegisterUser.DEFAULT_ANONYMOUS_ROLE, user.getRoles()[0]);
}

public void testWithMailAndNoMailRequired() throws JSONException, IOException {
Expand Down

0 comments on commit 068507b

Please sign in to comment.