Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. var services = angular.module('exampleApp.services', ['ngResource']);
  2.  
  3.  
  4. services.factory('UserService', function ($resource) {
  5.  
  6. return $resource('rest/user/:action', {},
  7. {
  8. authenticate: {
  9. method: 'POST',
  10. params: {'action': 'authenticate'},
  11. headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  12. }
  13. }
  14. );
  15. });
  16.  
  17.  
  18. function LoginController($scope, $rootScope, $location, $cookieStore, UserService) {
  19.  
  20. $scope.rememberMe = false;
  21.  
  22. $scope.login = function () {
  23.  
  24. UserService.authenticate($.param({username: $scope.username, password: $scope.password}), function (authenticationResult) {
  25. var authToken = authenticationResult.token;
  26. $rootScope.authToken = authToken;
  27. if ($scope.rememberMe) {
  28. $cookieStore.put('authToken', authToken);
  29. }
  30. UserService.get(function (user) {
  31. $rootScope.user = user;
  32. $location.path("/");
  33. });
  34. });
  35. };
  36.  
  37. $scope.register = function () {
  38. $scope.user = new UserService();
  39. console.log($scope.user);
  40. $scope.user.$save(function () {
  41. $location.path('/');
  42. });
  43.  
  44. };
  45.  
  46. angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services'])
  47. .config(
  48. ['$routeProvider', '$locationProvider', '$httpProvider', function ($routeProvider, $locationProvider, $httpProvider) {
  49.  
  50. $routeProvider.when('/create', {
  51. templateUrl: 'partials/create.html',
  52. controller: CreateController
  53. });
  54.  
  55. $routeProvider.when('/login', {
  56. templateUrl: 'partials/login.html',
  57. controller: LoginController
  58. });
  59. //more stuff here
  60.  
  61. });
  62.  
  63. @Component
  64. @Path("/user")
  65. public class UserResource {
  66.  
  67. //some field here
  68.  
  69. @POST
  70. @Consumes(MediaType.APPLICATION_JSON)
  71. @Produces(MediaType.APPLICATION_JSON)
  72. public User register(User user) {
  73. return this.userDao.save(user);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement