summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-05-12 18:18:20 -0400
committerJames Moger <james.moger@gitblit.com>2011-05-12 18:18:20 -0400
commita098da747052eb8d9f612f78dece8ac027a72caa (patch)
tree04694504c79cc955cf81a719799d12bee3ac8810 /src
parentf8288af5c6233172a5ae29ed11c46b31b4316931 (diff)
downloadgitblit-a098da747052eb8d9f612f78dece8ac027a72caa.tar.gz
gitblit-a098da747052eb8d9f612f78dece8ac027a72caa.zip
Improvements to create/edit user.
Diffstat (limited to 'src')
-rw-r--r--src/com/gitblit/JettyLoginService.java5
-rw-r--r--src/com/gitblit/wicket/pages/EditRepositoryPage.java2
-rw-r--r--src/com/gitblit/wicket/pages/EditUserPage.java31
3 files changed, 35 insertions, 3 deletions
diff --git a/src/com/gitblit/JettyLoginService.java b/src/com/gitblit/JettyLoginService.java
index fb510ee6..c191f0f0 100644
--- a/src/com/gitblit/JettyLoginService.java
+++ b/src/com/gitblit/JettyLoginService.java
@@ -69,8 +69,11 @@ public class JettyLoginService extends MappedLoginService implements ILoginServi
@Override
public UserModel getUserModel(String username) {
- UserModel model = new UserModel(username);
UserIdentity identity = _users.get(username);
+ if (identity == null) {
+ return null;
+ }
+ UserModel model = new UserModel(username);
Subject subject = identity.getSubject();
for (Principal principal : subject.getPrincipals()) {
if (principal instanceof RolePrincipal) {
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
index 8eed0059..88202901 100644
--- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -116,7 +116,7 @@ public class EditRepositoryPage extends BasePage {
error(e.getMessage());
return;
}
- setRedirect(true);
+ setRedirect(false);
setResponsePage(RepositoriesPage.class);
}
};
diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java
index d1faa782..7522f3ed 100644
--- a/src/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/com/gitblit/wicket/pages/EditUserPage.java
@@ -1,5 +1,6 @@
package com.gitblit.wicket.pages;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -71,8 +72,25 @@ public class EditUserPage extends BasePage {
private static final long serialVersionUID = 1L;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.wicket.markup.html.form.Form#onSubmit()
+ */
@Override
protected void onSubmit() {
+ String username = userModel.getUsername();
+ if (StringUtils.isEmpty(username)) {
+ error("Please enter a username!");
+ return;
+ }
+ if (isCreate) {
+ UserModel model = GitBlit.self().getUserModel(username);
+ if (model != null) {
+ error(MessageFormat.format("Username {0} is unavailable.", username));
+ return;
+ }
+ }
if (!userModel.getPassword().equals(confirmPassword.getObject())) {
error("Passwords do not match!");
return;
@@ -80,6 +98,16 @@ public class EditUserPage extends BasePage {
String password = userModel.getPassword();
if (!password.toUpperCase().startsWith(Crypt.__TYPE) && !password.toUpperCase().startsWith(MD5.__TYPE)) {
// This is a plain text password.
+ // Check length.
+ int minLength = GitBlit.self().settings().getInteger(Keys.realm.minPasswordLength, 5);
+ if (minLength < 4) {
+ minLength = 4;
+ }
+ if (password.trim().length() < minLength) {
+ error(MessageFormat.format("Password is too short. Minimum length is {0} characters.", minLength));
+ return;
+ }
+
// Optionally encrypt/obfuscate the password.
String type = GitBlit.self().settings().getString(Keys.realm.passwordStorage, "md5");
if (type.equalsIgnoreCase("md5")) {
@@ -103,9 +131,10 @@ public class EditUserPage extends BasePage {
error(e.getMessage());
return;
}
- setRedirect(true);
+ setRedirect(false);
if (isCreate) {
// create another user
+ info(MessageFormat.format("New user {0} successfully created.", userModel.getUsername()));
setResponsePage(EditUserPage.class);
} else {
// back to home