Skip to content
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
5 changes: 5 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/ngstorage/ngStorage.js"></script>
<!-- endbower -->

<script src="bower_components/angular-apimock/dist/angular-apimock.min.js"></script>
Expand All @@ -69,7 +70,11 @@

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/services/user/user.js"></script>
<script src="scripts/services/user/auth.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/login.js"></script>
<script src="scripts/controllers/dashboard.js"></script>
<script src="scripts/services/backend-url.js"></script>
<!-- endbuild -->
</body>
Expand Down
3 changes: 3 additions & 0 deletions app/mock_data/login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"token" : "21232f297a57a5a743894a0e4a801fc3"
}
11 changes: 10 additions & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ angular
'ngResource',
'ngSanitize',
'ngRoute',
'apiMock'
'apiMock',
'ngStorage'
])
.config(function ($routeProvider, apiMockProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/login', {
templateUrl: 'views/login.html',
controller: 'LoginCtrl'
})
.when('/dashboard', {
templateUrl: 'views/dashboard.html',
controller: 'DashboardCtrl'
})
.otherwise({
redirectTo: '/'
});
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

angular.module('myApp')
.controller('DashboardCtrl', function ($scope) {

});
39 changes: 39 additions & 0 deletions app/scripts/controllers/login.js
Original file line number Diff line number Diff line change
@@ -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.';
});
}

}]);
2 changes: 1 addition & 1 deletion app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

angular.module('myApp')
.controller('MainCtrl', function ($scope, Boxes) {
.controller('MainCtrl', function ($scope) {
});
36 changes: 0 additions & 36 deletions app/scripts/services/ethosiahttpinterceptor.js

This file was deleted.

33 changes: 33 additions & 0 deletions app/scripts/services/user/auth.js
Original file line number Diff line number Diff line change
@@ -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);
}

}]);
19 changes: 19 additions & 0 deletions app/scripts/services/user/user.js
Original file line number Diff line number Diff line change
@@ -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;
}

})
38 changes: 38 additions & 0 deletions app/views/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="/">Home</a></li>
<li><a ng-href="#/{{'dashboard'}}">Dashboard</a></li>
<li><a ng-href="#/{{'login'}}">Login</a></li>
<li><a ng-href="#/{{'logout'}}">Login</a></li>
<li><a ng-href="#">Registration</a></li>
</ul>
<h3 class="text-muted">Restful client example</h3>
</div>

<div class="jumbotron">
<h1>Welcome to dashboard.</h1>
<p class="lead">
<img src="images/yeoman.png" alt="I'm Yeoman"><br>
Always a pleasure scaffolding your apps.
</p>
<p><a class="btn btn-lg btn-success" ng-href="#">Splendid!<span class="glyphicon glyphicon-ok"></span></a></p>
</div>

<div class="row marketing">
<h4>HTML5 Boilerplate</h4>
<p>
HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites.
</p>

<h4>Angular</h4>
<p>
AngularJS is a toolset for building the framework most suited to your application development.
</p>

<h4>Karma</h4>
<p>Spectacular Test Runner for JavaScript.</p>
</div>

<div class="footer">
<p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
</div>
29 changes: 29 additions & 0 deletions app/views/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="/">Home</a></li>
<li><a ng-href="#">Dashboard</a></li>
<li><a ng-href="#/{{'login'}}">Login</a></li>
<li><a ng-href="#">Registration</a></li>
</ul>
<h3 class="text-muted">Restful client example</h3>
</div>


<div class="jumbotron">
<h1>Login</h1>
<div class="alert alert-danger" ng-show="login_error">{{ login_error }}</div>
<p class="lead">
<label for="username">Username:</label>
<input type="text" id="username" ng-model="user.username" />
</p>
<p class="lead">
<label for="password">Password:</label>
<input type="text" id="password" ng-model="user.password" />
</p>
<p><a class="btn btn-lg btn-success" ng-click="login(user)" href="">Login</a></p>
</div>

<div class="footer">

</div>

39 changes: 38 additions & 1 deletion app/views/main.html
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
Main view
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="/">Home</a></li>
<li><a ng-href="#">Dashboard</a></li>
<li><a ng-href="#/{{'login'}}">Login</a></li>
<li><a ng-href="#">Registration</a></li>
</ul>
<h3 class="text-muted">Restful client example</h3>
</div>


<div class="jumbotron">
<h1>'Allo, 'Allo!</h1>
<p class="lead">
<img src="images/yeoman.png" alt="I'm Yeoman"><br>
Always a pleasure scaffolding your apps.
</p>
<p><a class="btn btn-lg btn-success" ng-href="#">Splendid!<span class="glyphicon glyphicon-ok"></span></a></p>
</div>

<div class="row marketing">
<h4>HTML5 Boilerplate</h4>
<p>
HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites.
</p>

<h4>Angular</h4>
<p>
AngularJS is a toolset for building the framework most suited to your application development.
</p>

<h4>Karma</h4>
<p>Spectacular Test Runner for JavaScript.</p>
</div>

<div class="footer">
<p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
</div>
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down