summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2016-02-10 21:46:18 +0100
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2016-02-10 21:46:18 +0100
commit8c6b1cecd310acebd63c73628688aa0fcf8cb126 (patch)
tree36529b1366bf65381aad98c6591336b0b80a8950 /client
parente026ce21b48eddc9c4ca03b441d03baff217d3ad (diff)
parent3f83cae4178226084dcbf1e826271a04cc97086d (diff)
Merge branch 'loic' into develop
Diffstat (limited to 'client')
-rw-r--r--client/index.html1
-rw-r--r--client/js/controllers/login.js41
-rw-r--r--client/js/controllers/status.js2
-rw-r--r--client/js/services/Identity.js82
-rw-r--r--client/js/services/Image.js25
-rw-r--r--client/partials/login.html4
6 files changed, 94 insertions, 61 deletions
diff --git a/client/index.html b/client/index.html
index 10eceb3..ab5f00f 100644
--- a/client/index.html
+++ b/client/index.html
@@ -73,6 +73,7 @@
<!-- Include services -->
<script src="./js/services/Identity.js"></script>
+ <script src="./js/services/Image.js"></script>
<!-- Include controller -->
<script src="./js/controllers/login.js"></script>
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js
index 60eb52f..6358a6d 100644
--- a/client/js/controllers/login.js
+++ b/client/js/controllers/login.js
@@ -4,7 +4,7 @@
* @param {$scope} $scope The $scope angular service
* @param {$sce} $sce The $sce angular service
* @param {$http} $http The $http angular service
- * @param {sharedProfile} sharedProfile The sharedProfile service
+ * @param {Identity} The Identity service
*/
mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
@@ -16,42 +16,39 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s
$('#loginButton').click(function(){
+
+ // Begin login state for template
$('#loginButton').hide();
$('#loadingLoginButton').show();
$('#failedToLoginAlert').hide();
+ // Get data from templates
var username=$("#loginFormUsername").val();
var password=$("#loginFormPassword").val();
var projectname=$("#loginFormProjectname").val();
- var result=Identity.login(username, password, projectname);
-
-
- result.then(function (response){
- // Parser result
- var response=Identity.getResponse();
-
- // Check for error
+ // Function to call to handle result
+ var responseCallback=function(response){
+
if(response.status!==0){
-
+ // Set reason of fail
+ $scope.failReason=response.failReason;
+
+ // Display the error
$('#failedToLoginAlert').show();
}
else {
+ // Else the user is online !
$('#loginModal').modal('hide');
}
// Reset button state
$('#loginButton').show();
- $('#loadingLoginButton').hide();
- },function(response){
- $('#failedToLoginAlert').show();
-
- // Reset button state
- $('#loginButton').show();
- $('#loadingLoginButton').hide();
- });
-
-
-
- });
+ $('#loadingLoginButton').hide();
+ }
+
+ // Try to login
+ Identity.login(username, password, projectname, responseCallback);
+ });
+
}]);
diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js
index 7425244..2930e34 100644
--- a/client/js/controllers/status.js
+++ b/client/js/controllers/status.js
@@ -4,7 +4,7 @@
* The status controller
*
* @param {$scope} $scope The $scope service from angular
- * @param {sharedProfile} sharedProfile The sharedProfile build by ourself
+ * @param {Identity} The Identity service
*/
mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity)
{
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
index 509f800..4c8919c 100644
--- a/client/js/services/Identity.js
+++ b/client/js/services/Identity.js
@@ -1,14 +1,42 @@
mainApp.factory('Identity',[ '$http', function($http){
- /* Create profile structure */
+ /* Create profile structure to store informations
+ * about current session
+ */
var profile={};
- profile.username="Undefined";
- profile.projectname="Undefined";
- profile.token="";
+ profile.username=null;
+ profile.projectname=null;
+ profile.token=null;
+
+
+ /**
+ *
+ * @param {string} response The response to parse
+ * @param {boolean} to check if the request is send or not
+ * @returns {requestParserResult} Formated data
+ */
+ var parseLoginAnswer=function(response, failedToSendRequest){
+
+ var requestParserResult={};
+ requestParserResult.status=1;
+ requestParserResult.failReason=null;
+
+ if (typeof response.data.token !== 'undefined') {
+ requestParserResult.status=0;
+ profile.token=response.data.token;
+ }
+ else if(failedToSendRequest){
+ requestParserResult.failReason="Failed to send request";
+ }
+ else{
+ requestParserResult.failReason="Please check your username, password and project name !";
+ }
+
+ return requestParserResult;
+ };
+
- /* Will contain the result of the $http request */
- var $httpResponse;
/**
* Function to connect to OpenStack
@@ -17,46 +45,28 @@ mainApp.factory('Identity',[ '$http', function($http){
* @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
+ * @param {function} function to call when data is avalaible
*/
- var login=function(username, password,projectname){
+ var login=function(username, password,projectname, callback){
+
+ // Set profile information (early)
profile.username=username;
profile.projectname=projectname;
- $httpResponse=$http.post('../server/index.php',
+ var result=$http.post('../server/index.php',
$.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
- return $httpResponse;
- };
-
- /**
- *
- * @param {string} response The response to parse
- * @returns {requestParserResult} Formated data
- */
- var parseLoginAnswer=function(response){
- var requestParserResult={};
-
- requestParserResult.status=0;
- requestParserResult.data=response.data;
- profile.token="Un Token";
-
- // TODO
-
-
- return requestParserResult;
- };
-
-
- var getResponse=function(){
- return parseLoginAnswer($httpResponse);
- }
-
+ // Wait and handle the response
+ result.then(function (response){
+ callback(parseLoginAnswer(response), false);
+ },function(response){
+ callback(parseLoginAnswer(response), true)
+ });
+ };
// Return services objects
return {
login: login,
- getResponse: getResponse,
profile: profile
};
diff --git a/client/js/services/Image.js b/client/js/services/Image.js
new file mode 100644
index 0000000..4cb3590
--- /dev/null
+++ b/client/js/services/Image.js
@@ -0,0 +1,25 @@
+
+mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
+
+ var httpResponse;
+
+ var uploadImage=function(image){
+
+ };
+
+ var parseUploadImageRequest=function(){
+
+ };
+
+ var getResponse=function(){
+ return parseUploadImageRequest(httpResponse);
+ };
+
+ // Return services objects
+ return {
+ uploadImage: uploadImage,
+ getResponse: getResponse
+ };
+
+
+}]);
diff --git a/client/partials/login.html b/client/partials/login.html
index e0ce876..cd7d9ec 100644
--- a/client/partials/login.html
+++ b/client/partials/login.html
@@ -33,9 +33,9 @@
<div class="modal-footer">
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
<button class="btn btn-lg btn-warning btn-block" id="loadingLoginButton"><span class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></span> Loading...</button>
- <div class="alert alert-danger text-center" role="alert" id="failedToLoginAlert">Failed to login</div>
+ <div class="alert alert-danger text-center" role="alert" id="failedToLoginAlert"><b>Failed to login</b></b><br />{{ failReason }}</div>
<a href="#" class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="processForm()">Login</a>
</div>
</div>
</div>
-</div> \ No newline at end of file
+</div>