Skip to content

Commit 20342f7

Browse files
author
Dave Syer
committed
Convert github sample
1 parent 4693c56 commit 20342f7

File tree

2 files changed

+120
-118
lines changed

2 files changed

+120
-118
lines changed

github/pom.xml

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,84 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>com.example</groupId>
7-
<artifactId>social-github</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
<packaging>jar</packaging>
6+
<groupId>com.example</groupId>
7+
<artifactId>social-github</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
1010

11-
<name>social-github</name>
12-
<description>Demo project for Spring Boot</description>
11+
<name>social-github</name>
12+
<description>Demo project for Spring Boot</description>
1313

14-
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.5.2.RELEASE</version>
18-
<relativePath /> <!-- lookup parent from repository -->
19-
</parent>
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.2.RELEASE</version>
18+
<relativePath /> <!-- lookup parent from repository -->
19+
</parent>
2020

21-
<properties>
22-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<java.version>1.8</java.version>
24-
</properties>
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
2525

26-
<dependencies>
27-
<dependency>
28-
<groupId>org.springframework.boot</groupId>
29-
<artifactId>spring-boot-starter-actuator</artifactId>
30-
</dependency>
31-
<dependency>
32-
<groupId>org.springframework.boot</groupId>
33-
<artifactId>spring-boot-starter-security</artifactId>
34-
</dependency>
35-
<dependency>
36-
<groupId>org.springframework.boot</groupId>
37-
<artifactId>spring-boot-starter-web</artifactId>
38-
</dependency>
39-
<dependency>
40-
<groupId>org.springframework.security.oauth</groupId>
41-
<artifactId>spring-security-oauth2</artifactId>
42-
</dependency>
43-
<dependency>
44-
<groupId>org.webjars</groupId>
45-
<artifactId>jquery</artifactId>
46-
<version>2.1.1</version>
47-
</dependency>
48-
<dependency>
49-
<groupId>org.webjars</groupId>
50-
<artifactId>bootstrap</artifactId>
51-
<version>3.2.0</version>
52-
</dependency>
53-
<dependency>
54-
<groupId>org.webjars</groupId>
55-
<artifactId>webjars-locator</artifactId>
56-
</dependency>
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-actuator</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-security</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.security.oauth</groupId>
41+
<artifactId>spring-security-oauth2</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.webjars</groupId>
45+
<artifactId>js-cookie</artifactId>
46+
<version>2.1.0</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.webjars</groupId>
50+
<artifactId>jquery</artifactId>
51+
<version>2.1.1</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.webjars</groupId>
55+
<artifactId>bootstrap</artifactId>
56+
<version>3.2.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.webjars</groupId>
60+
<artifactId>webjars-locator</artifactId>
61+
</dependency>
5762

58-
<dependency>
59-
<groupId>org.springframework.boot</groupId>
60-
<artifactId>spring-boot-starter-test</artifactId>
61-
<scope>test</scope>
62-
</dependency>
63-
<dependency>
64-
<groupId>org.springframework.boot</groupId>
65-
<artifactId>spring-boot-configuration-processor</artifactId>
66-
<optional>true</optional>
67-
</dependency>
68-
</dependencies>
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-test</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-configuration-processor</artifactId>
71+
<optional>true</optional>
72+
</dependency>
73+
</dependencies>
6974

70-
<build>
71-
<plugins>
72-
<plugin>
73-
<groupId>org.springframework.boot</groupId>
74-
<artifactId>spring-boot-maven-plugin</artifactId>
75-
</plugin>
76-
</plugins>
77-
</build>
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-maven-plugin</artifactId>
80+
</plugin>
81+
</plugins>
82+
</build>
7883

7984
</project>

github/src/main/resources/static/index.html

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,55 @@
88
<meta name="viewport" content="width=device-width" />
99
<base href="/" />
1010
<link rel="stylesheet" type="text/css"
11-
href="/webjars/bootstrap/css/bootstrap.min.css" />
11+
href="/webjars/bootstrap/css/bootstrap.min.css" />
1212
<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
1313
<script type="text/javascript"
14-
src="/webjars/bootstrap/js/bootstrap.min.js"></script>
14+
src="/webjars/bootstrap/js/bootstrap.min.js"></script>
1515
</head>
16-
<body ng-app="app" ng-controller="home as home">
17-
<h1>Login</h1>
18-
<div class="container" ng-show="!home.authenticated">
19-
<div>
20-
With Facebook: <a href="/login/facebook">click here</a>
21-
</div>
22-
<div>
23-
With Github: <a href="/login/github">click here</a>
24-
</div>
25-
</div>
26-
<div class="container" ng-show="home.authenticated">
27-
Logged in as: <span ng-bind="home.user"></span>
28-
<div>
29-
<button ng-click="home.logout()" class="btn btn-primary">Logout</button>
30-
</div>
31-
</div>
32-
<script type="text/javascript" src="/webjars/angularjs/angular.min.js"></script>
33-
<script type="text/javascript">
34-
angular
35-
.module("app", [])
36-
.config(
37-
function($httpProvider) {
38-
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
39-
}).controller("home", function($http, $location) {
40-
var self = this;
41-
$http.get("/user").success(function(data) {
42-
if (data.name) {
43-
self.user = data.name;
44-
self.authenticated = true;
45-
} else {
46-
self.user = "N/A";
47-
self.authenticated = false;
48-
}
49-
}).error(function() {
50-
self.user = "N/A";
51-
self.authenticated = false;
52-
});
53-
self.logout = function() {
54-
$http.post('logout', {}).success(function() {
55-
self.authenticated = false;
56-
$location.path("/");
57-
}).error(function(data) {
58-
console.log("Logout failed")
59-
self.authenticated = false;
60-
});
61-
};
62-
});
63-
</script>
16+
<body>
17+
<h1>Login</h1>
18+
<div class="container unauthenticated">
19+
<div>
20+
With Facebook: <a href="/login/facebook">click here</a>
21+
</div>
22+
<div>
23+
With Github: <a href="/login/github">click here</a>
24+
</div>
25+
</div>
26+
<div class="container authenticated" style="display: none">
27+
Logged in as: <span id="user"></span>
28+
<div>
29+
<button onClick="logout()" class="btn btn-primary">Logout</button>
30+
</div>
31+
</div>
32+
<script type="text/javascript" src="/webjars/js-cookie/js.cookie.js"></script>
33+
<script type="text/javascript">
34+
$.ajaxSetup({
35+
beforeSend : function(xhr, settings) {
36+
if (settings.type == 'POST' || settings.type == 'PUT'
37+
|| settings.type == 'DELETE') {
38+
if (!(/^http:.*/.test(settings.url) || /^https:.*/
39+
.test(settings.url))) {
40+
// Only send the token to relative URLs i.e. locally.
41+
xhr.setRequestHeader("X-XSRF-TOKEN", Cookies
42+
.get('XSRF-TOKEN'));
43+
}
44+
}
45+
}
46+
});
47+
$.get("/user", function(data) {
48+
$("#user").html(data.userAuthentication.details.name);
49+
$(".unauthenticated").hide();
50+
$(".authenticated").show();
51+
});
52+
var logout = function() {
53+
$.post("/logout", function() {
54+
$("#user").html('');
55+
$(".unauthenticated").show();
56+
$(".authenticated").hide();
57+
})
58+
return true;
59+
}
60+
</script>
6461
</body>
6562
</html>

0 commit comments

Comments
 (0)