summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2016-02-10 17:47:01 +0100
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2016-02-10 17:47:01 +0100
commit65bcc720596b395298fa281b5b68737d04ffdb8a (patch)
treed0d9d890d3562bf806665845e2c1989bc25e1492 /client
parent1cd1ae92f414573942262f65dc1644e8ff9bb8f6 (diff)
Make Identity module more AngularJs Like !
Diffstat (limited to 'client')
-rw-r--r--client/index.html7
-rw-r--r--client/js/controllers/login.js16
-rw-r--r--client/js/controllers/status.js6
-rw-r--r--client/js/requests/identity.js52
-rw-r--r--client/js/services/Identity.js49
-rw-r--r--client/js/services/sharedProfile.js13
-rw-r--r--client/partials/nav.html2
7 files changed, 63 insertions, 82 deletions
diff --git a/client/index.html b/client/index.html
index 013b1b4..10eceb3 100644
--- a/client/index.html
+++ b/client/index.html
@@ -72,10 +72,7 @@
<script src="./js/app.js"></script>
<!-- Include services -->
- <script src="./js/services/sharedProfile.js"></script>
-
- <!-- Include resquest dependencies -->
- <script src="./js/requests/identity.js"></script>
+ <script src="./js/services/Identity.js"></script>
<!-- Include controller -->
<script src="./js/controllers/login.js"></script>
@@ -87,4 +84,4 @@
-</html> \ No newline at end of file
+</html>
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js
index 751bd09..e9308b8 100644
--- a/client/js/controllers/login.js
+++ b/client/js/controllers/login.js
@@ -7,7 +7,7 @@
* @param {sharedProfile} sharedProfile The sharedProfile service
*/
-mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile)
+mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
{
// Define default states
$('#loginModal').modal({backdrop: 'static', keyboard: false});
@@ -24,23 +24,23 @@ mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', funct
var password=$("#loginFormPassword").val();
var projectname=$("#loginFormProjectname").val();
- var result=identity.request.login($http,username, password, projectname);
+ var result=Identity.login(username, password, projectname);
result.then(function (response){
// Parser result
- var requestResultObject=identity.requestParser.parseLoginAnswer(response);
+ var requestResultObject=Identity.parseLoginAnswer(response);
// Check for error
if(requestResultObject.status!==0){
- //alert(result.data)
+
$('#failedToLoginAlert').show();
}
else {
- $('#loginModal').modal('hide');
- sharedProfile.username=username;
- sharedProfile.projectname=projectname;
-
+ $('#loginModal').modal('hide');
+ Identity.profile.username=username;
+ Identity.profile.projectname=projectname;
+
}
// Reset button state
diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js
index ce6882e..7425244 100644
--- a/client/js/controllers/status.js
+++ b/client/js/controllers/status.js
@@ -6,9 +6,9 @@
* @param {$scope} $scope The $scope service from angular
* @param {sharedProfile} sharedProfile The sharedProfile build by ourself
*/
-mainApp.controller('statusCtrl', ['$scope','sharedProfile', function ($scope, sharedProfile)
+mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity)
{
- $scope.profile=sharedProfile;
+ $scope.profile=Identity.profile;
-}]); \ No newline at end of file
+}]);
diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js
deleted file mode 100644
index be3f4f8..0000000
--- a/client/js/requests/identity.js
+++ /dev/null
@@ -1,52 +0,0 @@
-
-/**
- * Client Identity Module
- * @namespace identity
- */
-var identity = {};
-
-/**
- * Contain all request who can be send with http request
- * @namespace request
- */
-identity.request = {};
-
-/**
- * Contain parser for result of request made by {@link identity.request}
- * @namespace request
- */
-identity.requestParser = {};
-
-
-/**
- *
- * @param {object} $http Angular $http service
- * @param {string} username The user name
- * @param {string} password The user password
- * @param {string} projectname The user project name
- * @returns {promise} The result of the request
- */
-identity.request.login=function($http,username, password,projectname){
- return $http.post('../server/index.php',
- $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
-};
-
-
-/**
- *
- * @param {string} response The response to parse
- * @returns {requestParserResult} Formated data
- */
-identity.requestParser.parseLoginAnswer=function(response){
- var requestParserResult={};
-
- requestParserResult.status=0;
- requestParserResult.data=response.data;
-
-
- // TODO
-
-
- return requestParserResult;
-};
-
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
new file mode 100644
index 0000000..2164592
--- /dev/null
+++ b/client/js/services/Identity.js
@@ -0,0 +1,49 @@
+
+mainApp.factory('Identity',[ '$http', function($http){
+ var profile={};
+ profile.username="None";
+ profile.projectname="None";
+
+
+ /**
+ *
+ * @param {object} $http Angular $http service
+ * @param {string} username The user name
+ * @param {string} password The user password
+ * @param {string} projectname The user project name
+ * @returns {promise} The result of the request
+ */
+ var login=function(username, password,projectname){
+ return $http.post('../server/index.php',
+ $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
+ };
+
+
+ /**
+ *
+ * @param {string} response The response to parse
+ * @returns {requestParserResult} Formated data
+ */
+ var parseLoginAnswer=function(response){
+ var requestParserResult={};
+
+ requestParserResult.status=0;
+ requestParserResult.data=response.data;
+
+
+ // TODO
+
+
+ return requestParserResult;
+ };
+
+
+
+ return {
+ login: login,
+ parseLoginAnswer: parseLoginAnswer,
+ profile: profile
+ };
+
+
+}]);
diff --git a/client/js/services/sharedProfile.js b/client/js/services/sharedProfile.js
deleted file mode 100644
index 6e78cf6..0000000
--- a/client/js/services/sharedProfile.js
+++ /dev/null
@@ -1,13 +0,0 @@
-
-/**
- * The sharedProfile service
- * It's used to shared the profile between controller
- */
-mainApp.factory('sharedProfile',[function(){
- var profile={};
-
- profile.username="None";
- profile.projectname="None";
-
- return profile;
-}]); \ No newline at end of file
diff --git a/client/partials/nav.html b/client/partials/nav.html
index 786c53b..7c34174 100644
--- a/client/partials/nav.html
+++ b/client/partials/nav.html
@@ -39,4 +39,4 @@
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
-</nav> \ No newline at end of file
+</nav>