mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
admin panel should force registrations (#323)
This commit is contained in:
@@ -67,26 +67,32 @@ public class UserService {
|
|||||||
public User register(String name, String password, String email,
|
public User register(String name, String password, String email,
|
||||||
Collection<Role> roles, boolean forceRegistration) {
|
Collection<Role> roles, boolean forceRegistration) {
|
||||||
|
|
||||||
Preconditions.checkState(forceRegistration
|
|
||||||
|| applicationSettingsService.get().isAllowRegistrations(),
|
|
||||||
"Registrations are closed on this CommaFeed instance");
|
|
||||||
Preconditions.checkNotNull(name);
|
Preconditions.checkNotNull(name);
|
||||||
Preconditions.checkNotNull(email);
|
|
||||||
Preconditions.checkNotNull(password);
|
|
||||||
|
|
||||||
Preconditions.checkArgument(StringUtils.length(name) >= 3,
|
|
||||||
"Name too short (3 characters minimum)");
|
|
||||||
Preconditions.checkArgument(StringUtils.length(name) <= 32,
|
Preconditions.checkArgument(StringUtils.length(name) <= 32,
|
||||||
"Name too long (32 characters maximum)");
|
"Name too long (32 characters maximum)");
|
||||||
Preconditions.checkArgument(
|
Preconditions.checkNotNull(password);
|
||||||
forceRegistration || StringUtils.length(password) >= 6,
|
|
||||||
"Password too short (6 characters maximum)");
|
if (!forceRegistration) {
|
||||||
Preconditions.checkArgument(StringUtils.contains(email, "@"),
|
Preconditions.checkState(applicationSettingsService.get()
|
||||||
"Invalid email address");
|
.isAllowRegistrations(),
|
||||||
|
"Registrations are closed on this CommaFeed instance");
|
||||||
|
|
||||||
|
Preconditions.checkNotNull(email);
|
||||||
|
Preconditions.checkArgument(StringUtils.length(name) >= 3,
|
||||||
|
"Name too short (3 characters minimum)");
|
||||||
|
Preconditions.checkArgument(
|
||||||
|
forceRegistration || StringUtils.length(password) >= 6,
|
||||||
|
"Password too short (6 characters maximum)");
|
||||||
|
Preconditions.checkArgument(StringUtils.contains(email, "@"),
|
||||||
|
"Invalid email address");
|
||||||
|
}
|
||||||
|
|
||||||
Preconditions.checkArgument(userDAO.findByName(name) == null,
|
Preconditions.checkArgument(userDAO.findByName(name) == null,
|
||||||
"Name already taken");
|
"Name already taken");
|
||||||
Preconditions.checkArgument(userDAO.findByEmail(email) == null,
|
if (StringUtils.isNotBlank(email)) {
|
||||||
"Email already taken");
|
Preconditions.checkArgument(userDAO.findByEmail(email) == null,
|
||||||
|
"Email already taken");
|
||||||
|
}
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
byte[] salt = encryptionService.generateSalt();
|
byte[] salt = encryptionService.generateSalt();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class AdminREST extends AbstractResourceREST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
User user = userService.register(userModel.getName(),
|
User user = userService.register(userModel.getName(),
|
||||||
userModel.getPassword(), userModel.getEmail(), roles);
|
userModel.getPassword(), userModel.getEmail(), roles, true);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return Response.status(Status.CONFLICT)
|
return Response.status(Status.CONFLICT)
|
||||||
.entity("User already exists.").build();
|
.entity("User already exists.").build();
|
||||||
|
|||||||
Reference in New Issue
Block a user