mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
registration api (#303)
This commit is contained in:
@@ -6,14 +6,22 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.wordnik.swagger.annotations.ApiProperty;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class RegistrationRequest implements Serializable {
|
||||
|
||||
@ApiProperty(value = "username, between 3 and 32 characters", required = true)
|
||||
private String name;
|
||||
|
||||
@ApiProperty(value = "password, minimum 6 characters", required = true)
|
||||
private String password;
|
||||
|
||||
@ApiProperty(value = "email address for password recovery", required = true)
|
||||
private String email;
|
||||
|
||||
private boolean googleImport = true;
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -54,7 +54,8 @@ public class RegisterPanel extends Panel {
|
||||
if (applicationSettingsService.get().isAllowRegistrations()) {
|
||||
RegistrationRequest req = getModelObject();
|
||||
userService.register(req.getName(), req.getPassword(),
|
||||
Arrays.asList(Role.USER));
|
||||
req.getEmail(), Arrays.asList(Role.USER));
|
||||
|
||||
IAuthenticationStrategy strategy = getApplication()
|
||||
.getSecuritySettings().getAuthenticationStrategy();
|
||||
strategy.save(req.getName(), req.getPassword());
|
||||
@@ -92,7 +93,8 @@ public class RegisterPanel extends Panel {
|
||||
}));
|
||||
form.add(new PasswordTextField("password", MF.m(model, p.getPassword()))
|
||||
.setResetPassword(false).add(StringValidator.minimumLength(6)));
|
||||
form.add(new RequiredTextField<String>("email", MF.m(model, p.getEmail())) {
|
||||
form.add(new RequiredTextField<String>("email", MF.m(model,
|
||||
p.getEmail())) {
|
||||
@Override
|
||||
protected String getInputType() {
|
||||
return "email";
|
||||
|
||||
@@ -52,7 +52,7 @@ public class AdminREST extends AbstractResourceREST {
|
||||
}
|
||||
|
||||
User user = userService.register(userModel.getName(),
|
||||
userModel.getPassword(), roles);
|
||||
userModel.getPassword(), userModel.getEmail(), roles);
|
||||
if (user == null) {
|
||||
return Response.status(Status.CONFLICT)
|
||||
.entity("User already exists.").build();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
@@ -19,6 +21,7 @@ import com.commafeed.backend.model.UserSettings.ViewMode;
|
||||
import com.commafeed.frontend.model.Settings;
|
||||
import com.commafeed.frontend.model.UserModel;
|
||||
import com.commafeed.frontend.model.request.ProfileModificationRequest;
|
||||
import com.commafeed.frontend.model.request.RegistrationRequest;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
@@ -138,6 +141,21 @@ public class UserREST extends AbstractResourceREST {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@Path("/register")
|
||||
@POST
|
||||
@ApiOperation(value = "Register a new account")
|
||||
public Response register(@ApiParam(required = true) RegistrationRequest req) {
|
||||
try {
|
||||
userService.register(req.getName(), req.getPassword(),
|
||||
req.getEmail(), Arrays.asList(Role.USER));
|
||||
return Response.ok().build();
|
||||
} catch (Exception e) {
|
||||
return Response.status(Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(e.getMessage()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Path("/profile/deleteAccount")
|
||||
@POST
|
||||
@ApiOperation(value = "Delete the user account")
|
||||
|
||||
Reference in New Issue
Block a user