From 2c7fc4ad8300cbf8839c38df5aa0cbef78295960 Mon Sep 17 00:00:00 2001 From: Apratim Shukla Date: Thu, 11 Jun 2020 20:30:23 +0530 Subject: [PATCH] Production Build Fixed Moodle,Resync and Wrong Password check. Added About and much more. --- VITask Desktop/dashboard.html | 118 +++++++++++++++++++--------------- VITask Desktop/main.js | 81 +++++++++++------------ 2 files changed, 108 insertions(+), 91 deletions(-) diff --git a/VITask Desktop/dashboard.html b/VITask Desktop/dashboard.html index 096406f..cf0276d 100644 --- a/VITask Desktop/dashboard.html +++ b/VITask Desktop/dashboard.html @@ -1284,16 +1284,12 @@

${course}-${type}

let assignment_count = 1; for(i in assignment){ - let coursename = Object.values(assignment[i])[0]; - let deadline = Object.values(assignment[i])[2]; - - let splitter = coursename.split("("); - splitter[1] = splitter[1].substring(0, splitter[1].length - 1); - let sendcourse = splitter.join(" "); - sendcourse = sendcourse.split(" "); - let sendtime = deadline.split(" "); + let coursename = assignment[i]["course"]; + let deadline = assignment[i]["time"]; + let courseinfo = assignment[i]["name"]; + let description = assignment[i]["description"]; - content += ` ${coursename} + content += ` ${coursename} info ${deadline} @@ -1807,8 +1803,6 @@

Integrate Moodle

function login(regno,password,moodle_username=null,moodle_password=null,mode=null){ let url = 'http://134.209.150.24/api/gettoken'; - let timetable_ini_url = 'http://134.209.150.24/api/vtop/timetable' - let acadhistory_ini_url = 'http://134.209.150.24/api/vtop/history' let attendance_ini_url = 'http://134.209.150.24/api/vtop/attendance' let marks_ini_url = 'http://134.209.150.24/api/vtop/marks' let moodle_ini_url = 'http://134.209.150.24/api/moodle/login'; @@ -1822,39 +1816,48 @@

Integrate Moodle

if(mode=='moodle_authenticate') { - request(url, function (err, response, body) { - if(err){ - console.log('error:', error); - } else { - let result = JSON.parse(body); - result.profile = "user-profile"; - result.regno = regno; - result.password = password; - - data.insert(result, function(err, doc) { - console.log('Inserted', doc.Name); - }); - - data.findOne({ profile: 'user-profile' }, function(err, doc) { - + request({ + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-VITASK-API': '98e1e33a8e1964f073d2cc7a5c6bea755e862fe0e9041822e476d3b5b089a6a94f8343faf7b475c54cb1f490b762b8563144b64a914e06d421f8eed9d040ddd2' + }, + uri: url, + json: true, + body: {"username" : regno,"password" : password}, + method: 'POST' + }, function (err, res, body) { + if(err){ + console.log('error:', err); + } else { + let result = body; + /*console.log(result);*/ + if(result.Error){ + $("#loading").fadeOut(); + $("#content").fadeIn(); + alert("Wrong Password."); + } + else{ + result.profile = "user-profile"; + result.regno = regno; + result.password = password; + data.insert(result, function(err, doc) { + console.log('Inserted', doc.Name); + }); - timetable(doc.APItoken, function() { - acadhistory(doc.APItoken, function(){ - attendance(doc.APItoken, function(){ + data.findOne({ profile: 'user-profile' }, function(err, doc) { + attendance(doc.APItoken, function(){ marks(doc.APItoken, function(){ - moodlefetch(moodle_username,moodle_password,doc.AppNo, function(){ + moodlefetch(moodle_username,moodle_password,doc.APItoken, function(){ ipcRenderer.send('resync:new','resynced'); done(doc.APItoken); }); }); }); }); - }); - - }); - } - }); + } + } + }); } else if(mode=='no_moodle_authenticate') @@ -1903,25 +1906,40 @@

Integrate Moodle

} - function moodlefetch(moodle_username,moodle_password,appno, callback){ - console.log(moodle_username+" "+moodle_password+" "+appno); - let moodle_url = moodle_ini_url+appno+"&username="+moodle_username+"&password="+moodle_password; - request(moodle_url, function (err, response, body) { + function moodlefetch(moodle_username,moodle_password,token, callback){ + console.log(moodle_username+" "+moodle_password+" "+token); + + request({ + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-VITASK-API': '98e1e33a8e1964f073d2cc7a5c6bea755e862fe0e9041822e476d3b5b089a6a94f8343faf7b475c54cb1f490b762b8563144b64a914e06d421f8eed9d040ddd2' + }, + uri: moodle_ini_url, + json: true, + body: {"username": moodle_username, "password": moodle_password, "token" : token}, + method: 'POST' + }, function (err, response, body) { if(err){ - console.log('error:', error); + console.log('error:', err); } else { - let result = JSON.parse(body); - result.moodle = "user-moodle"; - result.regno = moodle_username; - result.password = moodle_password; + let result = body; + if(result.error){ + $("#loading").fadeOut(); + location.reload(true); + alert("Wrong Moodle Password."); + } + else{ + result.moodle = "user-moodle"; + result.regno = moodle_username; + result.password = moodle_password; - data.insert(result, function(err, doc) { - console.log('Inserted', doc.Assignments); - callback(); - }); + data.insert(result, function(err, doc) { + console.log('Inserted', doc.Assignments); + callback(); + }); + } } }); - } @@ -2019,8 +2037,6 @@

Integrate Moodle

- - diff --git a/VITask Desktop/main.js b/VITask Desktop/main.js index 4a62335..334e8dc 100644 --- a/VITask Desktop/main.js +++ b/VITask Desktop/main.js @@ -6,6 +6,7 @@ const ua = require('universal-analytics'); const analytics = ua('UA-157430748-1'); const {app, BrowserWindow, Menu, ipcMain} = electron; +const { dialog } = require('electron'); let mainWindow; @@ -46,8 +47,8 @@ function createMainWindow() icon: path.join(__dirname, 'icons/png/64x64.png') })); //Quit app when closed - mainWindow.on('closed',function(){ - mainWindow = null; + mainWindow.on('window-all-closed', () => { + app.quit(); }); //Build Menu from template const mainMenu = Menu.buildFromTemplate(loginMenuTemplate); @@ -70,8 +71,8 @@ function createDashboard(){ slashes: true, icon: path.join(__dirname, 'icons/png/64x64.png') })); - dashWindow.on('closed',function(){ - dashWindow = null; + dashWindow.on('window-all-closed', () => { + app.quit(); }); //Build Menu from template const mainMenu = Menu.buildFromTemplate(mainMenuTemplate); @@ -136,6 +137,24 @@ const mainMenuTemplate = [ { label:'File', submenu:[ + { + label: 'About', + accelerator: process.platform == 'darwin' ? 'Command+1' : 'Ctrl+1', + click(){ + const options = { + type: 'question', + buttons: ['Cancel'], + defaultId: 2, + title: 'About VITask ', + message: 'VITask Desktop V1.0.1', + detail: 'VITask Desktop is built by the VITask Team. All rights reserved. To know more visit https://vitask.me', + }; + dialog.showMessageBox(options) + } + }, + { + role: 'reload' + }, { label: 'Quit', accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q', @@ -152,6 +171,24 @@ const loginMenuTemplate = [ { label:'File', submenu:[ + { + label: 'About', + accelerator: process.platform == 'darwin' ? 'Command+1' : 'Ctrl+1', + click(){ + const options = { + type: 'question', + buttons: ['Cancel'], + defaultId: 2, + title: 'About VITask ', + message: 'VITask Desktop V1.0.1', + detail: 'VITask Desktop is built by the VITask Team. All rights reserved. To know more visit https://vitask.me', + }; + dialog.showMessageBox(options) + } + }, + { + role: 'reload' + }, { label: 'Quit', accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q', @@ -217,42 +254,6 @@ if(process.platform=="darwin"){ } -//add developer tools item if not in production -if(process.env.NODE_ENV!=='production'){ - mainMenuTemplate.push({ - label: 'Developer Tools', - submenu: [ - { - label: 'Toggle DevTools', - accelerator: process.platform == 'darwin' ? 'Command+I' : 'Ctrl+I', - click(item, focusedWindow){ - focusedWindow.toggleDevTools(); - } - }, - { - role: 'reload' - } - ] - }) - - loginMenuTemplate.push({ - label: 'Developer Tools', - submenu: [ - { - label: 'Toggle DevTools', - accelerator: process.platform == 'darwin' ? 'Command+I' : 'Ctrl+I', - click(item, focusedWindow){ - focusedWindow.toggleDevTools(); - } - }, - { - role: 'reload' - } - ] - }) -} - - function handleSquirrelEvent(application) { if (process.argv.length === 1) {