2015-01-10 22:11:51 +00:00
|
|
|
var starter = angular.module('starter.services', []);
|
|
|
|
|
|
|
|
starter.factory('ApiService', ['$http', '$ionicPopup', '$ionicModal', function ($http, $ionicPopup, $ionicModal) {
|
|
|
|
return {
|
|
|
|
//login
|
|
|
|
login: function(username, password){
|
|
|
|
console.log('[JCE] [INFO]: atempting to login.');
|
|
|
|
//JCE Login shit:
|
|
|
|
var request = "https://mipo.jce.ac.il/index.php/site/login?_dc=1419773997764&formValues=%7B%22form_fields%22%3A%7B%22name%22%3A%22"+username+"%22%2C%22pwd%22%3A%22"+password+"%22%7D%7D&callback=JSON_CALLBACK";
|
|
|
|
|
|
|
|
return $http.get(request).then(function(resp) {
|
|
|
|
|
|
|
|
if(resp.data.guest == false){
|
2015-01-13 00:14:24 +00:00
|
|
|
window.localStorage['userInfo'] = JSON.stringify(resp.data);
|
2015-01-10 22:11:51 +00:00
|
|
|
console.log("[JCE] [INFO]: Success.");
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
var alertPopup = $ionicPopup.alert({
|
|
|
|
title: 'שם משתמש או סיסמא שגויים',
|
|
|
|
template: 'וודא שוב כי שם המשתמש והסיסמא הינם נכונים.'
|
|
|
|
});
|
2015-01-13 00:14:24 +00:00
|
|
|
console.log("[JCE] [INFO]: Wrong user/pass.");
|
2015-01-10 22:11:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
var alertPopup = $ionicPopup.alert({
|
|
|
|
title: 'שגיאת רשת',
|
|
|
|
template: 'בדוק את החיבור לנתונים'
|
|
|
|
});
|
|
|
|
console.error('[JCE] [FATAL]: Network Error!', err);
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
update: function(){
|
|
|
|
var username = window.localStorage['username'];
|
|
|
|
var password = window.localStorage['password'];
|
|
|
|
var notes = window.localStorage['notes'] || null;
|
|
|
|
var grades = window.localStorage['grades'] || null;
|
2015-02-01 21:13:58 +00:00
|
|
|
var agudaPosts = window.localStorage['agudaPosts'] || null;
|
2015-01-20 09:06:17 +00:00
|
|
|
|
2015-01-10 22:11:51 +00:00
|
|
|
var request = "https://mipo.jce.ac.il/index.php/site/login?_dc=1419773997764&formValues=%7B%22form_fields%22%3A%7B%22name%22%3A%22"+username+"%22%2C%22pwd%22%3A%22"+password+"%22%7D%7D";
|
|
|
|
|
|
|
|
return $http.get(request).then(function(resp) {
|
|
|
|
|
|
|
|
if(resp.data.guest == false){
|
|
|
|
//Logged in
|
|
|
|
//
|
|
|
|
//Get Notes:
|
|
|
|
$http.get("https://mipo.jce.ac.il/index.php/site/studentMessages").then(function(resp) {
|
|
|
|
console.log('Success', resp);
|
|
|
|
console.log("[JCE] [INFO] : in update - Got JCE News!");
|
|
|
|
if(notes === null){
|
|
|
|
window.localStorage['newNotes'] = "true";
|
|
|
|
window.localStorage['notes'] = JSON.stringify(resp.data);
|
|
|
|
}else if(notes === JSON.stringify(resp.data)){
|
|
|
|
console.log("[JCE] [INFO] : in update - no new Notes");
|
|
|
|
}else{
|
|
|
|
window.localStorage['newNotes'] = "true";
|
|
|
|
window.localStorage['notes'] = JSON.stringify(resp.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
console.error('[JCE] [INFO] : in update - can\'t get Notes', err);
|
|
|
|
});
|
|
|
|
|
|
|
|
//Get Grades
|
2015-02-01 21:13:58 +00:00
|
|
|
$http.get("https://mipo.jce.ac.il/index.php/site/studentGrades").then(function(resp) {
|
|
|
|
console.log('Success', resp);
|
|
|
|
console.log("[JCE] [INFO] : in update - Got Grades!");
|
|
|
|
if(grades === null){
|
|
|
|
window.localStorage['newGrades'] = "true";
|
|
|
|
window.localStorage['grades'] = JSON.stringify(resp.data);
|
|
|
|
}else if(grades === JSON.stringify(resp.data)){
|
|
|
|
console.log("[JCE] [INFO] : in update - no new Grades");
|
|
|
|
}else{
|
|
|
|
window.localStorage['newGrades'] = "true";
|
|
|
|
window.localStorage['grades'] = JSON.stringify(resp.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
console.error('[JCE] [INFO] : in update - can\'t get Grades', err);
|
|
|
|
});
|
|
|
|
|
|
|
|
//Get Aguda Posts
|
|
|
|
$http.get("https://ajax.googleapis.com/ajax/services/feed/load?v=2.0&num=10&q=https://www.facebook.com/feeds/page.php?id=597726260353610%26format=rss20").then(function(resp) {
|
|
|
|
console.log('Success', resp);
|
|
|
|
console.log("[JCE] [INFO] : in update - Got Aguda from Facebook!");
|
|
|
|
if(grades === null){
|
|
|
|
window.localStorage['newAguda'] = "true";
|
2015-02-01 21:36:42 +00:00
|
|
|
window.localStorage['agudaPosts'] = JSON.stringify(resp.data);
|
2015-02-01 21:13:58 +00:00
|
|
|
}else if(grades === JSON.stringify(resp.data)){
|
|
|
|
console.log("[JCE] [INFO] : in update - no new newAguda");
|
|
|
|
}else{
|
|
|
|
window.localStorage['newAguda'] = "true";
|
|
|
|
window.localStorage['agudaPosts'] = JSON.stringify(resp.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
console.error('[JCE] [INFO] : in update - can\'t get Aguda Posts from Facebook', err);
|
|
|
|
});
|
2015-01-20 09:06:17 +00:00
|
|
|
|
|
|
|
//Get Calendar
|
|
|
|
//https://mipo.jce.ac.il/index.php/site/timetable
|
|
|
|
$http.get("https://mipo.jce.ac.il/index.php/site/timetable").then(function(resp) {
|
|
|
|
console.log('Success', resp);
|
|
|
|
console.log("[JCE] [INFO] : in update - Got Calendar!");
|
|
|
|
window.localStorage['calendar'] = JSON.stringify(resp.data);
|
|
|
|
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
console.error('[JCE] [INFO] : in update - can\'t get Calendar', err);
|
2015-01-10 22:11:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}else{
|
|
|
|
window.localStorage['loggedIn'] = false;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
window.localStorage['loggedIn'] = false;
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}]);
|