Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed from ng-resource to Restangular #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
angular-rest-springsecurity
===========================
angular-rest-springsecurity with Restangular
============================================

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=shoxrocks&url=http://sorst.net/github/angular-rest-springsecurity&title=AngularJS REST Spring Security Example&language=&tags=github&category=software)

[![Donate](http://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=W9NAXW8YAZ4D6&item_name=Angular REST SpringSecurity Example Donation&currency_code=EUR)
This is a fork from https://github.com/philipsorst/angular-rest-springsecurity. I needed this exact functionality but with Restangular
For this fork to work you need to download Restangular and underscore.

An example AngularJS Application that uses a Spring Security protected Jersey REST backend based on Hibernate/JPA.

Expand All @@ -25,7 +24,8 @@ Any feedback is welcome, and I will incorporate useful pull requests.
Technologies
------------

* [AngularJS](http://angularjs.org/)
* [AngularJS](http://angularjs.org/)
* [Restangular](https://github.com/mgonto/restangular)
* [Bootstrap](http://getbootstrap.com/)
* [Jersey](https://jersey.java.net/)
* [Spring Security](http://projects.spring.io/spring-security/)
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<script src="js/bootstrap-3.1.1.min.js"></script>
<script src="js/angular-1.2.3.js"></script>
<script src="js/angular-resource-1.2.3.js"></script>
<script src="js/underscore-min.js"></script>
<script src="js/restangular.js"></script>
<script src="js/angular-route-1.2.3.js"></script>
<script src="js/angular-cookies-1.2.3.js"></script>
<script src="js/config.js"></script>
Expand Down
63 changes: 31 additions & 32 deletions src/main/webapp/js/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services'])
angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services','restangular'])
.config(
[ '$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) {
[ '$routeProvider', '$locationProvider', '$httpProvider','RestangularProvider', function($routeProvider, $locationProvider, $httpProvider, RestangularProvider) {

$routeProvider.when('/create', {
templateUrl: 'partials/create.html',
Expand Down Expand Up @@ -63,8 +63,10 @@ angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services'])
return config || $q.when(config);
}
};
}
);
});


RestangularProvider.setBaseUrl('rest')

} ]

Expand Down Expand Up @@ -101,9 +103,9 @@ angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services'])
var authToken = $cookieStore.get('authToken');
if (authToken !== undefined) {
$rootScope.authToken = authToken;
UserService.get(function(user) {
UserService.get("").then(function(user) {
$rootScope.user = user;
$location.path(originalPath);
$location.path("/");
});
}

Expand All @@ -113,22 +115,25 @@ angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services'])

function IndexController($scope, NewsService) {

$scope.newsEntries = NewsService.query();

NewsService.getList().then(function(entries){
$scope.newsEntries = entries;
});
$scope.deleteEntry = function(newsEntry) {
newsEntry.$remove(function() {
$scope.newsEntries = NewsService.query();
newsEntry.remove().then(function() {
$scope.newsEntries = NewsService.getList().$object
});
};
};


function EditController($scope, $routeParams, $location, NewsService) {

$scope.newsEntry = NewsService.get({id: $routeParams.id});

NewsService.get($routeParams.id).then(function(enrty){
$scope.newsEntry = enrty;
});

$scope.save = function() {
$scope.newsEntry.$save(function() {
$scope.newsEntry.post().then(function() {
$location.path('/');
});
};
Expand All @@ -137,10 +142,9 @@ function EditController($scope, $routeParams, $location, NewsService) {

function CreateController($scope, $location, NewsService) {

$scope.newsEntry = new NewsService();


$scope.save = function() {
$scope.newsEntry.$save(function() {
NewsService.post($scope.newsEntry).then(function() {
$location.path('/');
});
};
Expand All @@ -150,39 +154,34 @@ function CreateController($scope, $location, NewsService) {
function LoginController($scope, $rootScope, $location, $cookieStore, UserService) {

$scope.rememberMe = false;

$scope.login = function() {
UserService.authenticate($.param({username: $scope.username, password: $scope.password}), function(authenticationResult) {

UserService.customPOST($.param({username: $scope.username, password: $scope.password}),"authenticate",{},{'Content-Type': 'application/x-www-form-urlencoded'}).then(function(authenticationResult) {
var authToken = authenticationResult.token;
$rootScope.authToken = authToken;

if ($scope.rememberMe) {
$cookieStore.put('authToken', authToken);
}
UserService.get(function(user) {
UserService.get("").then(function(user) {
$rootScope.user = user;
$location.path("/");
});

});
};
};


var services = angular.module('exampleApp.services', ['ngResource']);
var services = angular.module('exampleApp.services', []);

services.factory('UserService', function($resource) {
services.factory('UserService', function(Restangular) {

return $resource('rest/user/:action', {},
{
authenticate: {
method: 'POST',
params: {'action' : 'authenticate'},
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
},
}
);
return Restangular.all('user');
});

services.factory('NewsService', function($resource) {
services.factory('NewsService', function(Restangular) {

return $resource('rest/news/:id', {id: '@id'});
return Restangular.all('news');
});
Loading