-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add grunt-connect-proxy npm dependency - Update Gruntfile to use this dependency. - API must be served at localhost:7070 during development so as to be able to use livereload of angular changes and use a static version (war) of the API. - Solve Cross Origin request problem with browsers - Add Students service extending Restangular - Add Courses service extending Restangular - Add example of Students and Courses services usage on HomeCtrl - Add spec utils service - Add api responses service for testing purposes only (working as cassettes for api calls) - Add all test cases - Add simple authentication management - Add Authentication service - Add $cookies service to handle user session - Update login endpoint (back) to match the API path - Add token header to services using restangular - Add new spec cases for added components - Add AuthenticatedRestangular factory - Rename BodyController -> BodyCtrl - Notes - Authentication should be improved, but was implemented as to be able to deploy and test the app. - Login is served at the /login path and should be completed in order to use the rest of the app's requests.
- Loading branch information
1 parent
18ef123
commit dca63d2
Showing
29 changed files
with
949 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,3 +125,4 @@ dist/ | |
.tmp/ | ||
|
||
coverage/ | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'restangular', 'services/Authentication'], function(paw) { | ||
paw.controller('LoginCtrl', ['$location', '$log', 'Authentication', | ||
function($location, $log, Authentication) { | ||
var _this = this; | ||
|
||
this.login = function(user) { | ||
// user would never be undefined as the form has to be valid before calling this method | ||
// and that means that the user has to have some value defined | ||
Authentication.login(user).then(function(authToken) { | ||
Authentication.setToken(authToken); | ||
$location.path('/'); | ||
}, function(response) { | ||
// here we should handle any issue and show a nice error message | ||
$log.info('Response status: ' + response.status); | ||
}); | ||
}; | ||
}]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'restangular', 'services/Authentication'], function(paw) { | ||
paw.factory('AuthenticatedRestangular', ['Restangular', 'Authentication', | ||
function(Restangular, Authentication) { | ||
return Restangular.withConfig(function(RestangularConfigurer) { | ||
// cannot use RestangularConfigurer.setDefaultHeaders() as it is called | ||
// only once and before the token is set | ||
// This requests the token each time a request is made | ||
// and in this instance it should already be set | ||
RestangularConfigurer.addFullRequestInterceptor( | ||
function(element, operation, route, url, headers, params, httpConfig) { | ||
return { | ||
element: element, | ||
params: params, | ||
headers: _.extend(headers, Authentication.getHeader()), | ||
httpConfig: httpConfig | ||
}; | ||
} | ||
); | ||
}); | ||
}]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'restangular'], function(paw) { | ||
paw.service('Authentication', ['Restangular', '$cookies', | ||
function(Restangular, $cookies) { | ||
var _this = this; | ||
var tokenKey = 'ur'; | ||
|
||
var rest = Restangular.withConfig(function(RestangularConfigurer) { | ||
RestangularConfigurer.addResponseInterceptor( | ||
function(data, operation, what, url, response, deferred) { | ||
return response.headers()['x-auth-token']; | ||
} | ||
); | ||
}); | ||
|
||
this.setToken = function(token) { | ||
$cookies.put(tokenKey, token); | ||
}; | ||
|
||
this.getToken = function(token) { | ||
return $cookies.get(tokenKey); | ||
}; | ||
|
||
this.getHeader = function() { | ||
return {'x-auth-token': _this.getToken()}; | ||
}; | ||
|
||
this.login = function(user) { | ||
return rest.all('login').customPOST(user); | ||
}; | ||
}]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'services/AuthenticatedRestangular'], function(paw) { | ||
paw.service('Courses', ['AuthenticatedRestangular', | ||
function(AuthenticatedRestangular) { | ||
// this is needed as an array is expected from Restangular own methods | ||
// not needed if we are going to use Restangular's custom* methods | ||
var rest = AuthenticatedRestangular.withConfig(function(RestangularConfigurer) { | ||
RestangularConfigurer.addResponseInterceptor( | ||
function(data, operation, what, url, response, deferred) { | ||
return operation === 'getList' ? data.courses : data; | ||
} | ||
); | ||
RestangularConfigurer.setRestangularFields({ | ||
id: 'courseId' | ||
}); | ||
}); | ||
|
||
// add own methods as follows | ||
rest.getList = function() { | ||
return rest.all('courses').getList(); | ||
}; | ||
|
||
return rest; | ||
}]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'services/AuthenticatedRestangular'], function(paw) { | ||
paw.service('Students', ['AuthenticatedRestangular', | ||
function(AuthenticatedRestangular) { | ||
// this is needed as an array is expected from Restangular own methods | ||
// not needed if we are going to use Restangular's custom* methods | ||
var rest = AuthenticatedRestangular.withConfig(function(RestangularConfigurer) { | ||
RestangularConfigurer.addResponseInterceptor( | ||
function(data, operation, what, url, response, deferred) { | ||
return operation === 'getList' ? data.students : data; | ||
} | ||
); | ||
RestangularConfigurer.setRestangularFields({ | ||
id: 'docket' | ||
}); | ||
RestangularConfigurer.extendModel('students', function(student) { | ||
student.fullName = student.firstName + ' ' + student.lastName; | ||
return student; | ||
}); | ||
}); | ||
|
||
// add own methods as follows | ||
rest.getList = function() { | ||
return rest.all('students').getList(); | ||
}; | ||
|
||
return rest; | ||
}]); | ||
}); |
Oops, something went wrong.