From: Erik Brakkee Date: Sun, 29 Sep 2013 20:52:42 +0000 (+0200) Subject: basic user management working. X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=4fccc48bd9b0fba3b29ee64595011ba715087982;p=photos basic user management working. Still need to implement add user to group. --- diff --git a/src/main/java/org/wamblee/photos/wicket/AdminPage.html b/src/main/java/org/wamblee/photos/wicket/AdminPage.html index 4a1ce89..5567558 100644 --- a/src/main/java/org/wamblee/photos/wicket/AdminPage.html +++ b/src/main/java/org/wamblee/photos/wicket/AdminPage.html @@ -15,6 +15,7 @@

Groups

+

Delete groups

@@ -25,6 +26,9 @@
Groupdelete
+ +

Create group

+
@@ -34,6 +38,69 @@
+

Users

+ +

Delete users, change passwords, delete users from groups

+ + + + + + + + + + + + +
UserGroupsActions
usernamegroupname (del)   + + delete + +
+ + + + + +
+
+
+ +

Create user

+ +
+ + + + + + + + + + + + + + +
Username
Password
+
+ + +

Add user to group

+ diff --git a/src/main/java/org/wamblee/photos/wicket/AdminPage.java b/src/main/java/org/wamblee/photos/wicket/AdminPage.java index 6ef38c6..0449028 100644 --- a/src/main/java/org/wamblee/photos/wicket/AdminPage.java +++ b/src/main/java/org/wamblee/photos/wicket/AdminPage.java @@ -23,9 +23,12 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.PasswordTextField; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.repeater.RepeatingView; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.model.Model; import org.wamblee.security.authentication.UserAdministration; import org.wamblee.security.authentication.UserMgtException; @@ -103,6 +106,132 @@ public class AdminPage extends BasePage { add(groupCreate); _groupName = new TextField("groupName", new Model("")); groupCreate.add(_groupName); + + RepeatingView user = new RepeatingView("user") { + @Override + protected void onPopulate() { + removeAll(); + List users = _userAdmin.getUsers(); + for (final String user : users) { + WebMarkupContainer nameContainer = new WebMarkupContainer(newChildId()); + nameContainer.add(new Label("name", user)); + add(nameContainer); + RepeatingView groups = new RepeatingView("groups") { + @Override + protected void onPopulate() { + removeAll(); + List groups = _userAdmin.getGroups(user); + for (final String group : groups) { + WebMarkupContainer groupContainer = new WebMarkupContainer(newChildId()); + groupContainer.add(new Label("group", group)); + groupContainer.add(new Link("remove") { + @Override + public void onClick() { + try { + _userAdmin.removeUserFromGroup(user, group); + } + catch (UserMgtException e) { + error("Error removing group: " + e.getMessage()); + } + } + }); + add(groupContainer); + } + } + }; + nameContainer.add(groups); + nameContainer.add(new Link("delete") { + @Override + public void onClick() { + try { + _userAdmin.removeUser(user); + info("Deleted user '" + user + "'"); + } + catch (UserMgtException e) { + error("Could not delete user '" + user + "'"); + } + } + }); + + final PasswordTextField password = new PasswordTextField("password", new Model("")); + Form changePassword = new Form("changePasswordForm") { + @Override + protected void onSubmit() { + String value = password.getValue(); + if (value == null || value.length() == 0) { + return; + } + _userAdmin.setPassword(user, value); + info("password for user '" + user + "' changed"); + } + }; + changePassword.add(password); + nameContainer.add(changePassword); + } + } + }; + add(user); + + { + final TextField newUser = new TextField("user", new Model("")); + final PasswordTextField passwordNewUser = new PasswordTextField("password", new Model("")); + IModel> groups = new LoadableDetachableModel>() { + @Override + protected List load() { + return _userAdmin.getGroups(); + } + }; + /* + final DropDownChoice groupChoice = + new DropDownChoice("group", new Model(""), groups, new IChoiceRenderer() { + + @Override + public Object getDisplayValue(Object object) { + return object.toString(); + } + + @Override + public String getIdValue(Object object, int index) { + if (index < 0) { + return ""; + } + return object.toString(); + } + }); + */ + Form createUserForm = new Form("createUserForm") { + @Override + protected void onSubmit() { + //System.out.println("Create user " + newUser.getValue() + " " + passwordNewUser.getValue() + " " + + // "'" + groupChoice.getValue() + "'"); + String user = newUser.getValue(); + String pw = passwordNewUser.getValue(); + + //String group = groupChoice.getValue(); + // if (!_userAdmin.getGroups().contains(group)) { + // info("No group selected"); + // return; + // } + if (user.length() == 0) { + info("No username specified"); + return; + } + try { + _userAdmin.createUser(user, pw); + // _userAdmin.addUserToGroup(user, group); + info("User '" + user + "' created"); + newUser.setModel(new Model("")); + } + catch (UserMgtException e) { + error("Problem creating user '" + user + "': " + e.getMessage()); + } + } + }; + add(createUserForm); + createUserForm.add(newUser); + createUserForm.add(passwordNewUser); + // createUserForm.add(groupChoice); + } } @Override