Skip to content

Commit f46c52f

Browse files
committed
Merge login 2.0
2 parents 228cbe0 + d5d16ae commit f46c52f

20 files changed

+251
-60
lines changed

Diff for: Zenergy/Zenergy/App_Start/BundleConfig.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ public static void RegisterBundles(BundleCollection bundles)
2222
bundles.Add(new ScriptBundle("~/bundles/angular-resource").Include(
2323
"~/Scripts/Lib/angular-resource.min.js"));
2424

25+
bundles.Add(new ScriptBundle("~/bundles/angular-route").Include(
26+
"~/Scripts/Lib/angular-route.min.js"));
27+
2528
bundles.Add(new ScriptBundle("~/bundles/zenergyApp")
2629
.Include("~/Scripts/zenergyApp.js")
2730
.IncludeDirectory("~/Scripts/Controllers", "*.js")
28-
.IncludeDirectory("~/Scripts/Factories", "*.js"));
31+
.IncludeDirectory("~/Scripts/Factories", "*.js")
32+
.IncludeDirectory("~/Scripts/Tools", "*.js"));
2933

3034
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
3135
"~/Scripts/Lib/bootstrap.js",

Diff for: Zenergy/Zenergy/App_Start/Startup.Auth.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public void ConfigureAuth(IAppBuilder app)
6363
appId: "429380533932654",
6464
appSecret: "ce6476f6a182519fee61ee17db94556d");
6565

66-
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
67-
//{
68-
// ClientId = "",
69-
// ClientSecret = ""
70-
//});
66+
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
67+
{
68+
ClientId = "444754422502-l5urcdutcrgoedvdtrrbbvml2boq6eg2.apps.googleusercontent.com",
69+
ClientSecret = "mzj_gvPmB-pkCca_6U1VLkBE"
70+
});
7171
}
7272
}
7373
}

Diff for: Zenergy/Zenergy/Controllers/RegisterController.cs

-16
This file was deleted.

Diff for: Zenergy/Zenergy/Pages/home.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="jumbotron">
2+
<h1>ASP.NET</h1>
3+
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
4+
<p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
5+
<p ng-cloak ng-show="isConnected">Connected AS : {{name}}</p>
6+
{{users}}
7+
</div>

Diff for: Zenergy/Zenergy/Pages/login.html

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div id="fb-root"></div>
2+
<div class="container ">
3+
<div class="row">
4+
<div class="col-md-3 col-lg-offset-2">
5+
<h1>Sign in</h1>
6+
<form ng-submit="connexion()">
7+
<div class="form-group" ng-class="{ 'has-error': hasError}">
8+
<input type="email" class="form-control" ng-model="user.mail" placeholder="Email" >
9+
</div>
10+
<div class="form-group" ng-class="{ 'has-error': hasError}">
11+
<input type="password" class="form-control" ng-model="user.password" placeholder="Password">
12+
</div>
13+
<p ng-cloak class="text-danger" ng-if="hasError">Invalid email or password</p>
14+
<input type="submit" id="submit" value="Sign in" class="btn btn-primary" />
15+
</form>
16+
</div>
17+
<div ng-controller="facebookApiTools" ng-cloak class="col-md-4 col-lg-offset-1">
18+
<h3>Or use a social network</h3>
19+
20+
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
21+
</fb:login-button>
22+
<div id="status">
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>

Diff for: Zenergy/Zenergy/Pages/profile.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="jumbotron">
2+
{{users}}
3+
</div>

Diff for: Zenergy/Zenergy/Views/Register/index.cshtml renamed to Zenergy/Zenergy/Pages/register.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
2-
@{
3-
ViewBag.Title = "index";
4-
}
5-
6-
<h2>Registration</h2>
1+
<h2>Registration</h2>
72
<div class="container " ng-controller="registerPageController">
83
<div class="row">
94
<div name="formRegistration" class="col-md-3 col-lg-offset-4">
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
zenergyApp.controller("homePageController", ["$scope", "tokenService", function ($scope, tokenService) {
1+
zenergyApp.controller("homePageController", ["$scope", "tokenService","$http", function ($scope, tokenService, $http) {
22
$scope.name = tokenService.getUserName();
33
}]);

Diff for: Zenergy/Zenergy/Scripts/Controllers/loginPageController.js

+49-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
zenergyApp.controller("loginPageController", ["$scope", "$http", "$httpParamSerializerJQLike", "tokenService","$window", function ($scope,$http, $httpParamSerializerJQLike, tokenService, $window) {
1+
zenergyApp.controller("loginPageController", ["$scope", "$http", "$httpParamSerializerJQLike", "tokenService","$window", "$location", function ($scope,$http, $httpParamSerializerJQLike, tokenService, $window, $location) {
22

33
$scope.user = { mail: '', password: '' };
44
$scope.hasError = false;
5+
56
$scope.connexion = function () {
67
var response = $http({
78
url: 'api/login',
@@ -14,13 +15,58 @@
1415
}).then(function successCallback(response) {
1516
$scope.hasError = false;
1617
tokenService.saveToken(response.data.access_token, response.data.userName);
17-
window.location.replace("/Home");
18+
$location.path('/');
1819
}, function errorCallback(response) {
1920
$scope.hasError = true;
2021
tokenService.deleteToken();
2122
$scope.user.mail = '';
2223
$scope.user.password = '';
2324
});
24-
2525
};
26+
27+
/*
28+
var auth_response_change_callback = function (response) {
29+
if (response.status === 'connected') {
30+
FB.api('/me', function (response) {
31+
console.log(response);
32+
});
33+
}
34+
//window.location.replace("/Home");
35+
}
36+
37+
$window.fbAsyncInit = function () {
38+
// Executed when the SDK is loaded
39+
40+
FB.init({
41+
42+
appId: '429380533932654',
43+
channelUrl: 'app/channel.html',
44+
status: true,
45+
cookie: true,
46+
xfbml: true
47+
});
48+
49+
FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback);
50+
};
51+
52+
(function (d) {
53+
// load the Facebook javascript SDK
54+
55+
var js,
56+
id = 'facebook-jssdk',
57+
ref = d.getElementsByTagName('script')[0];
58+
59+
if (d.getElementById(id)) {
60+
return;
61+
}
62+
63+
js = d.createElement('script');
64+
js.id = id;
65+
js.async = true;
66+
js.src = "//connect.facebook.net/en_US/all.js";
67+
68+
ref.parentNode.insertBefore(js, ref);
69+
70+
}(document));
71+
*/
2672
}]);
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
zenergyApp.controller("mainController", ["$scope", "tokenService", "$window", function ($scope, tokenService, $window) {
2-
$scope.isConnected = tokenService.tokenExists();
2+
3+
$scope.isAuthanticated = function()
4+
{
5+
return tokenService.tokenExists();
6+
}
7+
38
$scope.logoff = function () {
49
tokenService.deleteToken();
5-
$window.location.reload();
610
};
11+
712
}]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
zenergyApp.controller("profilePageController", ["$scope", "$window", "$http",'$location', function ($scope, $window, $http, $location)
2+
{
3+
if (!$scope.isAuthanticated())
4+
$location.path("/Login");
5+
else
6+
{
7+
var response = $http({
8+
url: 'api/users',
9+
method: 'GET',
10+
}).then(function successCallback(response) {
11+
$scope.users = response.data;
12+
}, function errorCallback(response) {
13+
});
14+
}
15+
}]);

Diff for: Zenergy/Zenergy/Scripts/Controllers/registerPageController.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
zenergyApp.controller("registerPageController", ["$scope", "$http", "$window", function ($scope, $http, $window) {
1+
zenergyApp.controller("registerPageController", ["$scope", "$http", "$window", "$location", function ($scope, $http, $window, $location) {
22

33
$scope.user = {mail: '', password: '', passwordBis: '', lastName:'', firstName:'', adr1:'', adr2:'', pc:'', town:'', phone:''};
44
$scope.hasError = false;
@@ -28,7 +28,7 @@
2828
}
2929
}).then(function successCallback(response) {
3030
$scope.hasError = false;
31-
window.location.replace("/Login");
31+
$location.path("/");
3232
}, function errorCallback(response) {
3333
$scope.hasError = true;
3434
$scope.user.mail = '';

Diff for: Zenergy/Zenergy/Scripts/Factories/authInterceptorService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
var _request = function (config) {
66

7+
//TODO : vérifier les id sur api/users/{:id}
78
config.headers = config.headers || {};
89

910
if (tokenService.tokenExists()) {
@@ -15,7 +16,6 @@
1516

1617
var _responseError = function (rejection) {
1718
if (rejection.status === 401) {
18-
console.log("Not connected");
1919
}
2020
return $q.reject(rejection);
2121
}

Diff for: Zenergy/Zenergy/Scripts/Lib/_references.js

242 Bytes
Binary file not shown.

Diff for: Zenergy/Zenergy/Scripts/Tools/facebookApiTools.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
zenergyApp.controller("facebookApiTools", ["$scope", "$http", "$httpParamSerializerJQLike", "tokenService","$window","$location", function ($scope,$http, $httpParamSerializerJQLike, tokenService, $window,$location) {
2+
3+
4+
// This is called with the results from from FB.getLoginStatus().
5+
function statusChangeCallback(response) {
6+
if (response.status === 'connected') {
7+
facebookLogin(response.authResponse.accessToken);
8+
console.log(response);
9+
} else if (response.status === 'not_authorized') {
10+
document.getElementById('status').innerHTML = 'Please log ' +
11+
'into this app.';
12+
} else {
13+
document.getElementById('status').innerHTML = 'Please log ' +
14+
'into Facebook.';
15+
}
16+
}
17+
18+
$window.checkLoginState = function() {
19+
FB.getLoginStatus(function (response) {
20+
statusChangeCallback(response);
21+
});
22+
}
23+
24+
window.fbAsyncInit = function () {
25+
FB.init({
26+
appId: '429380533932654',
27+
cookie: true, // enable cookies to allow the server to access
28+
// the session
29+
xfbml: true, // parse social plugins on this page
30+
version: 'v2.2' // use version 2.2
31+
});
32+
33+
34+
};
35+
36+
(function (d, s, id) {
37+
var js, fjs = d.getElementsByTagName(s)[0];
38+
if (d.getElementById(id)) return;
39+
js = d.createElement(s); js.id = id;
40+
js.src = "//connect.facebook.net/en_US/sdk.js";
41+
fjs.parentNode.insertBefore(js, fjs);
42+
}(document, 'script', 'facebook-jssdk'));
43+
44+
function facebookLogin(token) {
45+
console.log('Welcome! Fetching your information.... ');
46+
FB.api('/me', 'get', { access_token: token, fields: 'id,email,first_name,last_name' }, function (response) {
47+
var user = response;
48+
console.log(user);
49+
$http({
50+
url: 'api/login',
51+
method: 'POST',
52+
data: $httpParamSerializerJQLike({ grant_type: 'password', username: user.email, password: user.id }),
53+
//data: $httpParamSerializerJQLike({ grant_type: 'password', username: $scope.user.mail, password: CryptoJS.MD5($scope.user.password).toString() }),
54+
headers: {
55+
'Content-Type': 'application/x-www-form-urlencoded'
56+
}
57+
}).then(function successCallback(response) {
58+
tokenService.saveToken(response.data.access_token, user.email);
59+
$location.path('/');
60+
}, function errorCallback(response) {
61+
//TODO: inscrire le user
62+
console.log(response);
63+
});
64+
});
65+
}
66+
67+
}]);

Diff for: Zenergy/Zenergy/Scripts/zenergyApp.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
var zenergyApp = angular.module('zenergyApp', ['ngResource']);
1+
var zenergyApp = angular.module('zenergyApp', ['ngResource', 'ngRoute']);
2+
3+
zenergyApp.config(function ($routeProvider) {
4+
$routeProvider
5+
6+
// route for the home page
7+
.when('/', {
8+
templateUrl: 'Pages/home.html',
9+
controller: 'homePageController'
10+
})
11+
12+
.when('/Login', {
13+
templateUrl: 'Pages/login.html',
14+
controller: 'loginPageController'
15+
})
16+
17+
.when('/Profile', {
18+
templateUrl: 'Pages/profile.html',
19+
controller: 'profilePageController'
20+
})
21+
22+
.when('/Register', {
23+
templateUrl: 'Pages/register.html',
24+
controller: 'registerPageController'
25+
})
26+
});
27+
28+
229

Diff for: Zenergy/Zenergy/Views/Home/Index.cshtml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
@{
22
ViewBag.Title = "Zenergy";
33
}
4-
<div class="jumbotron" ng-controller="homePageController">
5-
<h1>ASP.NET</h1>
6-
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
7-
<p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
8-
<p ng-cloak ng-show="isConnected">Connected AS : {{name}}</p>
9-
</div>
4+
<div id="main">
5+
6+
<div ng-view>
7+
8+
</div>
9+
10+
</div>

0 commit comments

Comments
 (0)