diff --git a/app/index.html b/app/index.html index 46fbe73..e67a40b 100644 --- a/app/index.html +++ b/app/index.html @@ -61,6 +61,7 @@ + @@ -69,7 +70,11 @@ + + + + diff --git a/app/mock_data/login.json b/app/mock_data/login.json new file mode 100644 index 0000000..816ddfc --- /dev/null +++ b/app/mock_data/login.json @@ -0,0 +1,3 @@ +{ + "token" : "21232f297a57a5a743894a0e4a801fc3" +} diff --git a/app/scripts/app.js b/app/scripts/app.js index 4940e77..f37f95e 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -6,7 +6,8 @@ angular 'ngResource', 'ngSanitize', 'ngRoute', - 'apiMock' + 'apiMock', + 'ngStorage' ]) .config(function ($routeProvider, apiMockProvider) { $routeProvider @@ -14,6 +15,14 @@ angular templateUrl: 'views/main.html', controller: 'MainCtrl' }) + .when('/login', { + templateUrl: 'views/login.html', + controller: 'LoginCtrl' + }) + .when('/dashboard', { + templateUrl: 'views/dashboard.html', + controller: 'DashboardCtrl' + }) .otherwise({ redirectTo: '/' }); diff --git a/app/scripts/controllers/dashboard.js b/app/scripts/controllers/dashboard.js new file mode 100644 index 0000000..6a3513c --- /dev/null +++ b/app/scripts/controllers/dashboard.js @@ -0,0 +1,6 @@ +'use strict'; + +angular.module('myApp') + .controller('DashboardCtrl', function ($scope) { + + }); diff --git a/app/scripts/controllers/login.js b/app/scripts/controllers/login.js new file mode 100644 index 0000000..037707f --- /dev/null +++ b/app/scripts/controllers/login.js @@ -0,0 +1,39 @@ +'use strict'; + +angular.module('myApp') + .controller('LoginCtrl', ['$scope', '$cookies', '$location', 'Auth', 'User', function($scope, $cookies, $location, Auth, User) { + + Auth.status(function() { + if (User.getUserDetails().status == true) { + $location.url('/dashboard'); + } + else { + + } + }, + function() { + User.clear(); + }); + + $scope.user = {}; + $scope.login_error = null; + + $scope.login = function() { + + Auth.login($scope.user) + .success(function(data) { + if (!data.error) { + User.setUserDetails(data); + + $location.url('/dashboard'); + } + else { + $scope.login_error = data.description; + } + }) + .error(function(data, status, headers, config) { + $scope.login_error = 'Login failed.'; + }); + } + + }]); diff --git a/app/scripts/controllers/main.js b/app/scripts/controllers/main.js index 3bb10d8..5a86150 100644 --- a/app/scripts/controllers/main.js +++ b/app/scripts/controllers/main.js @@ -1,5 +1,5 @@ 'use strict'; angular.module('myApp') - .controller('MainCtrl', function ($scope, Boxes) { + .controller('MainCtrl', function ($scope) { }); diff --git a/app/scripts/services/ethosiahttpinterceptor.js b/app/scripts/services/ethosiahttpinterceptor.js deleted file mode 100644 index c17ca00..0000000 --- a/app/scripts/services/ethosiahttpinterceptor.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -angular.module('myApp') - .factory('restfulHttpInterceptor', function ($q, BACKEND_URL) { - // Public API here - return { - /** - * This interceptor construct the path to get the data translated, - * check the config and according this generated the new path in relation - * the language selected by the user. - * - * @param config - * In the $http config add two new variables: - * - * - serverPredefined: true|false if the value is true take the constant - * WEB_URL defined in the config.js to set the server URI. Otherwise - * keep the original config.url. * - * - apiMock: true|false indicate if use the interceptor angular-apimock. - * to maintain compatibility. - * - * @returns {*} - */ - 'request': function(config) { - // Validate if use the server url defined in the constant. - if (config.serverPredefined) { - config._url = BACKEND_URL; - - // Have the condition to work with the module angular-apimock - // https://github.com/seriema/angular-apimock - config.url = (angular.isDefined(config.apiMock) && config.apiMock) ? config.url : config._url + config.url; - } - - return config || $q.when(config); - } - }; - }); diff --git a/app/scripts/services/user/auth.js b/app/scripts/services/user/auth.js new file mode 100644 index 0000000..731df40 --- /dev/null +++ b/app/scripts/services/user/auth.js @@ -0,0 +1,33 @@ +'use strict'; + +angular.module('myApp'). + service('Auth', ['$http', '$q', 'User', function($http, $q, User) { + + this.status = function(success, error) { + $http.get('http://127.0.0.1/restful-login.php?status=1').success(function(res) { + if (res.status !== "undefined" && res.token) { + User.setDetails(res); + success(); + } + }).error(error); + } + + this.login = function(user) { + return $http.post('http://127.0.0.1/restful-login.php', user, + { + headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}, + transformRequest: function(data){ + return $.param(data); + } + } + ); + } + + this.logout = function(success, error) { + $http.post('http://127.0.0.1/restful-login.php?logout=1').success(function(res) { + User.clear(); + success(); + }).error(error); + } + + }]); diff --git a/app/scripts/services/user/user.js b/app/scripts/services/user/user.js new file mode 100644 index 0000000..9f9aacd --- /dev/null +++ b/app/scripts/services/user/user.js @@ -0,0 +1,19 @@ +'use strict'; + +angular.module('myApp'). + service('User', function($localStorage) { + this.storage = $localStorage; + + this.setUserDetails = function(userDetails) { + this.storage.userDetails = userDetails; + } + + this.getUserDetails = function() { + return this.storage.userDetails; + } + + this.clear = function() { + delete this.storage.userDetails; + } + + }) diff --git a/app/views/dashboard.html b/app/views/dashboard.html new file mode 100644 index 0000000..062def9 --- /dev/null +++ b/app/views/dashboard.html @@ -0,0 +1,38 @@ +
+ +

Restful client example

+
+ +
+

Welcome to dashboard.

+

+ I'm Yeoman
+ Always a pleasure scaffolding your apps. +

+

Splendid!

+
+ +
+

HTML5 Boilerplate

+

+ HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites. +

+ +

Angular

+

+ AngularJS is a toolset for building the framework most suited to your application development. +

+ +

Karma

+

Spectacular Test Runner for JavaScript.

+
+ + diff --git a/app/views/login.html b/app/views/login.html new file mode 100644 index 0000000..1ad1334 --- /dev/null +++ b/app/views/login.html @@ -0,0 +1,29 @@ +
+ +

Restful client example

+
+ + +
+

Login

+
{{ login_error }}
+

+ + +

+

+ + +

+

Login

+
+ + + diff --git a/app/views/main.html b/app/views/main.html index 60e65c3..2c8c203 100644 --- a/app/views/main.html +++ b/app/views/main.html @@ -1 +1,38 @@ -Main view +
+ +

Restful client example

+
+ + +
+

'Allo, 'Allo!

+

+ I'm Yeoman
+ Always a pleasure scaffolding your apps. +

+

Splendid!

+
+ +
+

HTML5 Boilerplate

+

+ HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites. +

+ +

Angular

+

+ AngularJS is a toolset for building the framework most suited to your application development. +

+ +

Karma

+

Spectacular Test Runner for JavaScript.

+
+ + diff --git a/bower.json b/bower.json index 694e82c..d63882c 100644 --- a/bower.json +++ b/bower.json @@ -11,7 +11,8 @@ "angular-cookies": "1.2.16", "angular-sanitize": "1.2.16", "angular-route": "1.2.16", - "angular-apimock": "*" + "angular-apimock": "*", + "ngstorage": "~0.3.0" }, "devDependencies": { "angular-mocks": "1.2.16",