forked from Archives/Athou_commafeed
registration module
This commit is contained in:
@@ -1455,14 +1455,12 @@ module.controller('MetricsCtrl', ['$scope', 'AdminMetricsService', function($sco
|
|||||||
$scope.metrics = AdminMetricsService.get();
|
$scope.metrics = AdminMetricsService.get();
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
module.controller('WelcomeCtrl', ['$scope', '$location', 'SessionService', 'ServerService', function($scope, $location, SessionService, ServerService) {
|
module.controller('LoginCtrl', ['$scope', '$location', 'SessionService', function($scope, $location, SessionService) {
|
||||||
$scope.ServerService = ServerService.get();
|
|
||||||
$scope.model = {};
|
$scope.model = {};
|
||||||
|
|
||||||
var login = function(model) {
|
var login = function(model) {
|
||||||
var success = function(data) {
|
var success = function(data) {
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
$scope.$emit('emitReload');
|
|
||||||
};
|
};
|
||||||
var error = function(data) {
|
var error = function(data) {
|
||||||
$scope.message = data.data;
|
$scope.message = data.data;
|
||||||
@@ -1483,3 +1481,19 @@ module.controller('WelcomeCtrl', ['$scope', '$location', 'SessionService', 'Serv
|
|||||||
login($scope.model);
|
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);
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|||||||
@@ -124,8 +124,7 @@ app.config(['$routeProvider', '$stateProvider', '$urlRouterProvider', '$httpProv
|
|||||||
|
|
||||||
$stateProvider.state('welcome', {
|
$stateProvider.state('welcome', {
|
||||||
url : '/welcome',
|
url : '/welcome',
|
||||||
templateUrl : 'templates/welcome.html',
|
templateUrl : 'templates/welcome.html'
|
||||||
controller : 'WelcomeCtrl'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$urlRouterProvider.when('/', '/feeds/view/category/all');
|
$urlRouterProvider.when('/', '/feeds/view/category/all');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6" ng-controller="LoginCtrl">
|
||||||
<div class="well" id="login-panel">
|
<div class="well" id="login-panel">
|
||||||
<h3>Login</h3>
|
<h3>Login</h3>
|
||||||
<span class="feedback">{{message}}</span>
|
<span class="feedback">{{message}}</span>
|
||||||
@@ -40,10 +40,29 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6" ng-if="ServerService.allowRegistrations">
|
<div class="col-md-6" ng-controller="RegisterCtrl">
|
||||||
<div class="well" id="register-panel">
|
<div ng-if="ServerService.allowRegistrations">
|
||||||
<h3>Register</h3>
|
<div class="well" id="register-panel">
|
||||||
<span></span>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -201,9 +201,7 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
|
|||||||
environment.lifecycle().manage(feedWorker);
|
environment.lifecycle().manage(feedWorker);
|
||||||
environment.lifecycle().manage(feedUpdater);
|
environment.lifecycle().manage(feedUpdater);
|
||||||
|
|
||||||
// TODO user login + registration page
|
|
||||||
// TODO translations
|
// TODO translations
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
import lombok.Data;
|
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.ApiModel;
|
||||||
import com.wordnik.swagger.annotations.ApiModelProperty;
|
import com.wordnik.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
@@ -13,12 +17,18 @@ import com.wordnik.swagger.annotations.ApiModelProperty;
|
|||||||
public class RegistrationRequest implements Serializable {
|
public class RegistrationRequest implements Serializable {
|
||||||
|
|
||||||
@ApiModelProperty(value = "username, between 3 and 32 characters", required = true)
|
@ApiModelProperty(value = "username, between 3 and 32 characters", required = true)
|
||||||
|
@Length(min = 3, max = 32)
|
||||||
|
@NotEmpty
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "password, minimum 6 characters", required = true)
|
@ApiModelProperty(value = "password, minimum 6 characters", required = true)
|
||||||
|
@Length(min = 6)
|
||||||
|
@NotEmpty
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@ApiModelProperty(value = "email address for password recovery", required = true)
|
@ApiModelProperty(value = "email address for password recovery", required = true)
|
||||||
|
@Email
|
||||||
|
@NotEmpty
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package com.commafeed.frontend.resource;
|
|||||||
|
|
||||||
import io.dropwizard.hibernate.UnitOfWork;
|
import io.dropwizard.hibernate.UnitOfWork;
|
||||||
import io.dropwizard.jersey.sessions.Session;
|
import io.dropwizard.jersey.sessions.Session;
|
||||||
|
import io.dropwizard.jersey.validation.ValidationErrorMessage;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
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.commafeed.frontend.model.request.RegistrationRequest;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.wordnik.swagger.annotations.Api;
|
import com.wordnik.swagger.annotations.Api;
|
||||||
import com.wordnik.swagger.annotations.ApiOperation;
|
import com.wordnik.swagger.annotations.ApiOperation;
|
||||||
import com.wordnik.swagger.annotations.ApiParam;
|
import com.wordnik.swagger.annotations.ApiParam;
|
||||||
@@ -200,12 +205,17 @@ public class UserREST {
|
|||||||
@POST
|
@POST
|
||||||
@UnitOfWork
|
@UnitOfWork
|
||||||
@ApiOperation(value = "Register a new account")
|
@ApiOperation(value = "Register a new account")
|
||||||
public Response register(@ApiParam(required = true) RegistrationRequest req) {
|
public Response register(@Valid @ApiParam(required = true) RegistrationRequest req) {
|
||||||
try {
|
try {
|
||||||
userService.register(req.getName(), req.getPassword(), req.getEmail(), Arrays.asList(Role.USER));
|
userService.register(req.getName(), req.getPassword(), req.getEmail(), Arrays.asList(Role.USER));
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
} catch (Exception e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
return Response.status(422).entity(new ValidationErrorMessage(Collections.<ConstraintViolation<?>> emptySet()) {
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getErrors() {
|
||||||
|
return ImmutableList.of(e.getMessage());
|
||||||
|
}
|
||||||
|
}).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user