registration module

This commit is contained in:
Athou
2014-08-09 19:04:37 +02:00
parent 0c25412f03
commit 0329c7d876
6 changed files with 65 additions and 15 deletions

View File

@@ -1455,14 +1455,12 @@ module.controller('MetricsCtrl', ['$scope', 'AdminMetricsService', function($sco
$scope.metrics = AdminMetricsService.get();
}]);
module.controller('WelcomeCtrl', ['$scope', '$location', 'SessionService', 'ServerService', function($scope, $location, SessionService, ServerService) {
$scope.ServerService = ServerService.get();
module.controller('LoginCtrl', ['$scope', '$location', 'SessionService', function($scope, $location, SessionService) {
$scope.model = {};
var login = function(model) {
var success = function(data) {
$location.path('/');
$scope.$emit('emitReload');
};
var error = function(data) {
$scope.message = data.data;
@@ -1483,3 +1481,19 @@ module.controller('WelcomeCtrl', ['$scope', '$location', 'SessionService', 'Serv
login($scope.model);
};
}]);
module.controller('RegisterCtrl', ['$scope', '$location', 'SessionService', 'ServerService', function($scope, $location, SessionService, ServerService) {
$scope.ServerService = ServerService.get();
$scope.model = {};
$scope.register = function() {
var success = function(data) {
$location.path('/');
$scope.$emit('emitReload');
};
var error = function(data) {
$scope.messages = data.data.errors;
};
SessionService.register($scope.model, success, error);
}
}]);

View File

@@ -124,8 +124,7 @@ app.config(['$routeProvider', '$stateProvider', '$urlRouterProvider', '$httpProv
$stateProvider.state('welcome', {
url : '/welcome',
templateUrl : 'templates/welcome.html',
controller : 'WelcomeCtrl'
templateUrl : 'templates/welcome.html'
});
$urlRouterProvider.when('/', '/feeds/view/category/all');

View File

@@ -20,7 +20,7 @@
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="col-md-6" ng-controller="LoginCtrl">
<div class="well" id="login-panel">
<h3>Login</h3>
<span class="feedback">{{message}}</span>
@@ -40,10 +40,29 @@
</form>
</div>
</div>
<div class="col-md-6" ng-if="ServerService.allowRegistrations">
<div class="well" id="register-panel">
<h3>Register</h3>
<span></span>
<div class="col-md-6" ng-controller="RegisterCtrl">
<div ng-if="ServerService.allowRegistrations">
<div class="well" id="register-panel">
<h3>Register</h3>
<div ng-repeat="message in messages">{{message}}</div>
<form autocomplete="off" ng-submit="register()">
<div class="form-group">
<label>User Name</label>
<input type="text" class="form-control" ng-model="model.name"></input>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" ng-model="model.password"></input>
</div>
<div class="form-group">
<label>Email address (used for password recovery only)</label>
<input type="email" class="form-control" ng-model="model.email"></input>
</div>
<div>
<input type="submit" class="btn btn-primary" value="Register" />
</div>
</form>
</div>
</div>
</div>
</div>

View File

@@ -201,9 +201,7 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
environment.lifecycle().manage(feedWorker);
environment.lifecycle().manage(feedUpdater);
// TODO user login + registration page
// TODO translations
}
public static void main(String[] args) throws Exception {

View File

@@ -4,6 +4,10 @@ import java.io.Serializable;
import lombok.Data;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
@@ -13,12 +17,18 @@ import com.wordnik.swagger.annotations.ApiModelProperty;
public class RegistrationRequest implements Serializable {
@ApiModelProperty(value = "username, between 3 and 32 characters", required = true)
@Length(min = 3, max = 32)
@NotEmpty
private String name;
@ApiModelProperty(value = "password, minimum 6 characters", required = true)
@Length(min = 6)
@NotEmpty
private String password;
@ApiModelProperty(value = "email address for password recovery", required = true)
@Email
@NotEmpty
private String email;
}

View File

@@ -2,10 +2,14 @@ package com.commafeed.frontend.resource;
import io.dropwizard.hibernate.UnitOfWork;
import io.dropwizard.jersey.sessions.Session;
import io.dropwizard.jersey.validation.ValidationErrorMessage;
import java.util.Arrays;
import java.util.Collections;
import javax.servlet.http.HttpSession;
import javax.validation.ConstraintViolation;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -40,6 +44,7 @@ import com.commafeed.frontend.model.request.ProfileModificationRequest;
import com.commafeed.frontend.model.request.RegistrationRequest;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
@@ -200,12 +205,17 @@ public class UserREST {
@POST
@UnitOfWork
@ApiOperation(value = "Register a new account")
public Response register(@ApiParam(required = true) RegistrationRequest req) {
public Response register(@Valid @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();
} catch (final IllegalArgumentException e) {
return Response.status(422).entity(new ValidationErrorMessage(Collections.<ConstraintViolation<?>> emptySet()) {
@Override
public ImmutableList<String> getErrors() {
return ImmutableList.of(e.getMessage());
}
}).build();
}
}