Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 27eae71

Browse files
committed
CAS example
1 parent de30ee9 commit 27eae71

File tree

12 files changed

+78
-7
lines changed

12 files changed

+78
-7
lines changed

app/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ angular.module('myApp', [
55
'ngRoute',
66
'myApp.view1',
77
'myApp.view2',
8+
'myApp.logout',
89
'myApp.version'
910
]).
1011
config(['$routeProvider', function($routeProvider) {

app/backend/init.inc.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?
2+
3+
require_once 'CAS.php';
4+
5+
$CAS_HOST = 'cru.renater.fr';
6+
$CAS_CONTEXT = '/cas';
7+
8+
phpCAS::client(CAS_VERSION_2_0, $CAS_HOST, 443, $CAS_CONTEXT);
9+
phpCAS::setNoCasServerValidation();

app/backend/logout.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
session_start() ;
4+
5+
// partial logout
6+
session_destroy();

app/backend/user.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
require_once 'init.inc.php';
4+
5+
if (phpCAS::isAuthenticated()) {
6+
echo json_encode(array('id' => phpCAS::getUser()));
7+
} else {
8+
header('HTTP/1.0 401 Unauthorized');
9+
echo 'HTTP/1.0 401 Unauthorized';
10+
}

app/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ul class="menu">
1919
<li><a href="#/view1">view1</a></li>
2020
<li><a href="#/view2">view2</a></li>
21+
<li><a href="#/logout">logout</a></li>
2122
</ul>
2223

2324
<!--[if lt IE 7]>
@@ -36,6 +37,7 @@
3637
<script src="app.js"></script>
3738
<script src="view1/view1.js"></script>
3839
<script src="view2/view2.js"></script>
40+
<script src="logout/logout.js"></script>
3941
<script src="components/version/version.js"></script>
4042
<script src="components/version/version-directive.js"></script>
4143
<script src="components/version/interpolate-filter.js"></script>

app/index.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
require_once 'backend/init.inc.php';
4+
5+
phpCAS::handleLogoutRequests();
6+
phpCAS::forceAuthentication();
7+
8+
9+
include('index.html');

app/logout/logout.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>Partial logout {{status}}</p>
2+

app/logout/logout.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
angular.module('myApp.logout', ['ngRoute'])
4+
5+
.config(['$routeProvider', function($routeProvider) {
6+
$routeProvider.when('/logout', {
7+
templateUrl: 'logout/logout.html',
8+
controller: 'LogoutCtrl'
9+
});
10+
}])
11+
12+
.controller('LogoutCtrl', function($http, $scope) {
13+
$scope.status = 'in progress';
14+
$http.get('backend/logout.php').success(function () {
15+
$scope.status = 'success';
16+
}).error(function (data) {
17+
$scope.status = 'failure: ' + data;
18+
});
19+
});

app/view1/view1.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<p>This is the partial for view 1.</p>
1+
<div ng-if="user">
2+
<p>User id: {{user.id}}</p>
3+
</div>
4+
5+
<div ng-if="!user">
6+
Session timeout! Please <a href="index.php">re-start application</a>
7+
</div>

app/view1/view1.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ angular.module('myApp.view1', ['ngRoute'])
99
});
1010
}])
1111

12-
.controller('View1Ctrl', [function() {
12+
.controller('View1Ctrl', function($http, $scope, $window) {
13+
$http.get('backend/user.php').success(function (user) {
14+
$scope.user = user;
15+
});
1316

14-
}]);
17+
$scope.restart = function() {
18+
$window.location.reload();
19+
}
20+
});

app/view1/view1_test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ describe('myApp.view1 module', function() {
66

77
describe('view1 controller', function(){
88

9-
it('should ....', inject(function($controller) {
9+
it('should ....', inject(function($rootScope, $controller) {
1010
//spec body
11-
var view1Ctrl = $controller('View1Ctrl');
11+
var scope = $rootScope.$new();
12+
var view1Ctrl = $controller('View1Ctrl', {$scope: scope});
1213
expect(view1Ctrl).toBeDefined();
1314
}));
1415

1516
});
16-
});
17+
});

e2e-tests/scenarios.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('my app', function() {
2020

2121
it('should render view1 when user navigates to /view1', function() {
2222
expect(element.all(by.css('[ng-view] p')).first().getText()).
23-
toMatch(/partial for view 1/);
23+
toMatch(/User id:/);
2424
});
2525

2626
});

0 commit comments

Comments
 (0)