Add login check witouth reloading page

This commit is contained in:
manzerbredes 2016-03-21 06:47:01 +01:00
parent 3216a69b75
commit 3c336f00d2
284 changed files with 141 additions and 31 deletions

View file

@ -3,7 +3,7 @@
* The main app module instance
* @type angular.module.angular-1_3_6_L1749.moduleInstance
*/
var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize', 'ngCookies']);
var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize', 'ngCookies','lr.upload']);
/**
* Configure routeProvider

View file

@ -29,7 +29,7 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','I
if(Identity.isAlreadyLogin()){
if(Compute.getData().machines == null{
if(Compute.getData().machines == null){
Loading.start();
Compute.pullData(callMeAfterPullData);
}

View file

@ -11,9 +11,6 @@ mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', funct
Loading.stop();
};
$scope.doUpload = function () {
Image.uploadImage($scope.myFile,function(){});
};
if(Identity.isAlreadyLogin()){

View file

@ -0,0 +1,60 @@
/**
* The image controller
*
* @param {$scope} $scope The $scope service from angular
*/
mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity,upload)
{
/*$scope.uploader = new FileUploader({
"token" : Identity.getToken(),
"task" : "image",
'action':'uploadImage',
'id':'6564'
});
$scope.uploader.url='../server/index.php'
$scope.uploader.alias='file_name'
$scope.uploader.formData={
"token" : Identity.getToken(),
"task" : "image",
'action':'uploadImage',
'id':'6564'
}
*/
$scope.doUpload = function () {
console.log($('#imageToUpload').prop('files')[0]);
Image.uploadImage($('#imageToUpload').prop('files')[0], function(){alert("done")})
/*$("#drop-area-div").dmUploader({
extraData: {
"token" : Identity.getToken(),
"task" : "image",
'action':'uploadImage',
'id':'6564'},
url:"../server/index.php"
});
*/
/*upload({
url: '../server/index.php',
method: 'POST',
data: {
"token" : Identity.getToken(),
"task" : "image",
'action':'uploadImage',
'id':'6564',
"file_name": $scope.myFile, // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending.
}
}).then(
function (response) {
console.log(response.data); // will output whatever you choose to return from the server on a successful upload
},
function (response) {
console.error(response); // Will return if status code is above 200 and lower than 300, same as $http
}
);*/
};
}]);

View file

@ -9,15 +9,15 @@
*/
mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity)
{
// Check for login and define default states
if(!Identity.isAlreadyLogin()){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
}
// Check for login and define default states
if(!Identity.isAlreadyLogin()){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
}
// Manager logout event
$scope.$on('logoutEvent', function(){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
});
// Manager logout event
$scope.$on('logoutEvent', function(){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
});

View file

@ -15,7 +15,7 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($
// Function to logout
$scope.logout=function(){
Identity.logout();
};
Identity.logout();
};
}]);

View file

@ -1,5 +1,5 @@
mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, $cookies, $rootScope){
/* Create profile structure to store informations
* about current session
@ -27,17 +27,20 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
&& typeof tokenPart_1InCookie !== 'undefined'
){
if(token!==null){
//if(token!==null){
// If yes, put it into variables
angular.extend(profile, profileInCookie);
token=tokenPart_0InCookie+tokenPart_1InCookie;
}
//}
// Return I'm Login
return true;
}
// Show the login overlay
$rootScope.$broadcast("logoutEvent");
// Return I'm not Login
return false;
}
@ -56,7 +59,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
profile.projectname=null;
// Reload Page
location.reload();
//location.reload();
$rootScope.$broadcast("logoutEvent");
}

View file

@ -45,17 +45,42 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
};
var uploadImage=function(fileToUpload, callback) {
var form_data = new FormData();
form_data.append('file', fileToUpload);
console.log(fileToUpload)
form_data.append("task" , "image")
form_data.append("token" , Identity.getToken())
form_data.append('action',"uploadImage")
form_data.append('id','6564')
form_data.append('file_name', fileToUpload.name);
$.ajax({
url: "../server/index.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
file_name:fileToUpload.name,
token : Identity.getToken(),
task : "image",
action:'uploadImage',
id:'6564',
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
alert("success")
}
});
var result=$http.post('../server/index.php',
$.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'filename':fileToUpload, 'id':'6564'}));
//var result=$http.post('../server/index.php',
// $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'}));
// Wait and handle the response
result.then(function (response){
/* result.then(function (response){
callback(parseUploadImageAnswer(response, false));
},function(response){
callback(parseUploadImageAnswer(response, true));
});
});*/