Skip to content

Commit

Permalink
Remove dead code (unused variables and functions) and improve toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
foivospro committed Sep 15, 2024
1 parent 35ed009 commit 4423885
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 74 deletions.
Binary file modified blockly_unix_database.db
Binary file not shown.
51 changes: 16 additions & 35 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<script src="https://unpkg.com/@blockly/workspace-backpack@latest"></script>
<script src="https://unpkg.com/@blockly/plugin-cross-tab-copy-paste@latest"></script>
<script src="js/el.js"></script>
<script src="msg/en.js"></script>

<!-- <script src="https://unpkg.com/@blockly/block-plus-minus"></script> -->

<!-- BLOCKS DEFINITION -->
Expand Down Expand Up @@ -51,7 +53,6 @@
<script src="blocks/lsBlock.js"></script>
<script src="blocks/cdBlock.js"></script>
<script src="blocks/mkdirBlock.js"></script>
<script src="blocks/gzipBlock.js"></script>
<script src="blocks/grepBlock.js"></script>
<script src="blocks/sedBlock.js"></script>
<script src="blocks/awkBlock.js"></script>
Expand Down Expand Up @@ -135,9 +136,6 @@
<button id="homePage" class="icon-button" title="HomePage">
<i class="fas fa-home"></i>
</button>
<form id="homePageForm" action="/" method="POST" style="display: none">
<input type="hidden" name="_method" value="POST" />
</form>

<form
id="logoutForm"
Expand All @@ -157,15 +155,6 @@
>
<i class="fas fa-sign-out-alt"></i>
</button>

<form
id="loginForm"
action="/login"
method="POST"
style="display: none"
>
<input type="hidden" name="_method" value="POST" />
</form>
<button
id="loginButton"
class="icon-button"
Expand All @@ -174,14 +163,6 @@
>
<i class="fas fa-sign-in-alt"></i>
</button>
<form
id="registerForm"
action="/register"
method="POST"
style="display: none"
>
<input type="hidden" name="_method" value="POST" />
</form>
<button
id="registerButton"
class="icon-button"
Expand Down Expand Up @@ -346,7 +327,7 @@
contents: [
{
kind: 'category',
name: 'Text Processing',
name: [MSG.TEXT_PROCESSING],
colour: '#4CAF50',
contents: [
{ kind: 'block', type: 'head' },
Expand All @@ -365,7 +346,7 @@
},
{
kind: 'category',
name: 'File inputs',
name: [MSG.FILE_INPUTS],
colour: '#5C81A6',
contents: [
{ kind: 'block', type: 'filename' },
Expand All @@ -378,7 +359,7 @@
},
{
kind: 'category',
name: 'File and Directory Operations',
name: [MSG.FILE_DIR_OPERATIONS],
colour: '#FE9B13',
contents: [
{ kind: 'block', type: 'ls' },
Expand All @@ -397,7 +378,7 @@
},
{
kind: 'category',
name: 'I/O Redirection',
name: [MSG.IO_REDIRECTION],
colour: '#1976D2',
contents: [
{ kind: 'block', type: 'save' },
Expand All @@ -410,7 +391,7 @@
},
{
kind: 'category',
name: 'Regular Expressions',
name: [MSG.REGULAR_EXPRESSIONS],
colour: '#FF5733',
contents: [
{ kind: 'block', type: 'regOutput' },
Expand All @@ -433,7 +414,7 @@
},
{
kind: 'category',
name: 'System Monitoring',
name: [MSG.SYSTEM_MONITORING],
colour: '#9C27B0',
contents: [
{ kind: 'block', type: 'ps' },
Expand All @@ -449,7 +430,7 @@
},
{
kind: 'category',
name: 'Network Operations',
name: [MSG.NETWORK_OPERATIONS],
colour: '#FFC107',
contents: [
{ kind: 'block', type: 'ssh' },
Expand All @@ -463,7 +444,7 @@
},
{
kind: 'category',
name: 'Data Processing',
name: [MSG.DATA_PROCESSING],
colour: '#3B7C09',
contents: [
{ kind: 'block', type: 'beginEnd' },
Expand All @@ -476,7 +457,7 @@
{ kind: 'block', type: 'xargs' },
{
kind: 'category',
name: 'Text output',
name: [MSG.TEXT_OUTPUT],
colour: '160',
contents: [
{ kind: 'block', type: 'text' },
Expand All @@ -499,7 +480,7 @@
},
{
kind: 'category',
name: 'Logic',
name: [MSG.LOGIC],
colour: '210',
contents: [
{ kind: 'block', type: 'controls_if' },
Expand All @@ -510,7 +491,7 @@
},
{
kind: 'category',
name: 'Loops',
name: [MSG.LOOPS],
colour: '120',
contents: [
{ kind: 'block', type: 'controls_whileUntil' },
Expand All @@ -519,7 +500,7 @@
},
{
kind: 'category',
name: 'Math',
name: [MSG.MATH],
colour: '230',
contents: [
{ kind: 'block', type: 'math_number' },
Expand Down Expand Up @@ -554,7 +535,7 @@
},
{
kind: 'category',
name: 'Variables',
name: [MSG.VARIABLES],
colour: '330',
custom: 'VARIABLE'
},
Expand All @@ -564,7 +545,7 @@
},
{
kind: 'category',
name: 'Other Commands',
name: [MSG.OTHER_COMMANDS],
colour: '#009688',
contents: [
{ kind: 'block', type: 'kill' },
Expand Down
10 changes: 4 additions & 6 deletions passport-config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const LocalStrategy = require('passport-local').Strategy;
const bcrypt = require('bcrypt');
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./blockly_unix_database.db');

// Initialize function to set up LocalStrategy and Google OAuth
// Initialize function to set up LocalStrategy
function initialize(passport, getUserByUsername, getUserById) {
// Local Strategy for login
const authenticateUser = async (username, password, done) => {
Expand Down Expand Up @@ -39,14 +35,16 @@ function initialize(passport, getUserByUsername, getUserById) {

// Serialize user into the session
passport.serializeUser((user, done) => {
done(null, user.id); // Χρησιμοποίησε το `id` από τη βάση δεδομένων
done(null, user.id); // Use the `id` from the database
});

// Deserialize user from the session
passport.deserializeUser((id, done) => {
getUserById(id, (err, user) => {
if (err) return done(err);
return done(null, user);
});
});
}

module.exports = initialize;
2 changes: 1 addition & 1 deletion public/blocks/pingBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var pingBlock = {
{
type: 'field_input',
name: 'address',
text: '8.8.8.8'
text: 'hostname'
}
],

Expand Down
6 changes: 3 additions & 3 deletions public/blocks/psBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ var psBlock = {
{
type: 'field_input',
name: 'show_process_user',
text: ''
text: 'user'
}
],
message3: '%{BKY_PS_SHOW_PID}',
args3: [
{
type: 'field_input',
name: 'show_process_pid',
text: ''
text: 'pid'
}
],
message4: '%{BKY_PS_FORMAT}',
args4: [
{
type: 'field_input',
name: 'format',
text: ''
text: 'format'
}
],
message5: '%{BKY_PS_SHOW_THREAD}',
Expand Down
9 changes: 8 additions & 1 deletion public/msg/el.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
var MSG_EL = {
window.MSG = {
TEXT_PROCESSING: 'Επεξεργασία Κειμένου',
FILE_INPUTS: 'Είσοδοι Αρχείων',
FILE_DIR_OPERATIONS: 'Λειτουργίες Αρχείων και Καταλόγων',
IO_REDIRECTION: 'Ανακατεύθυνση Εισόδου/Εξόδου',
REGULAR_EXPRESSIONS: 'Κανονικές Εκφράσεις',
DATA_PROCESSING: 'Επεξεργασία Δεδομένων',
VARIABLES: 'Μεταβλητές',
SYSTEM_MONITORING: 'Παρακολούθηση Συστήματος',
NETWORK_OPERATIONS: 'Λειτουργίες Δικτύου',
TEXT_OUTPUT: 'Έξοδος Κειμένου',
LOGIC: 'Λογική',
LOOPS: 'Βρόχοι',
MATH: 'Μαθηματικά',
OTHER_COMMANDS: 'Άλλες Εντολές',
title: 'Κώδικας',
blocks: 'Μπλοκ',
linkTooltip: 'Αποθήκευση και σύνδεση με τα μπλοκ.',
Expand Down
10 changes: 8 additions & 2 deletions public/msg/en.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
var MSG_EN = {
window.MSG = {
TEXT_PROCESSING: 'Text Processing',
FILE_INPUTS: 'File Inputs',
FILE_DIR_OPERATIONS: 'File and Directory Operations',
IO_REDIRECTION: 'I/O Redirection',
REGULAR_EXPRESSIONS: 'Regular Expressions',
DATA_PROCESSING: 'Data Processing',
VARIABLES: 'Variables',

SYSTEM_MONITORING: 'System Monitoring',
NETWORK_OPERATIONS: 'Network Operations',
TEXT_OUTPUT: 'Text Output',
LOGIC: 'Logic',
LOOPS: 'Loops',
MATH: 'Math',
OTHER_COMMANDS: 'Other Commands',
title: 'Code',
blocks: 'Blocks',
linkTooltip: 'Save and link to blocks.',
Expand Down
26 changes: 0 additions & 26 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ if (process.env.NODE_ENV !== 'production') {
const express = require('express');
const app = express();
const path = require('path');

//Replace when integrate with database
const users = [];
const bcrypt = require('bcrypt'); // Importing bcrypt library
const passport = require('passport');
const initializePassport = require('./passport-config');
const flash = require('express-flash');
const session = require('express-session');
const methodOverride = require('method-override');
const jwt = require('jsonwebtoken');
const cookieParser = require('cookie-parser');
const sqlite3 = require('sqlite3').verbose();
Expand Down Expand Up @@ -60,7 +56,6 @@ app.use(
);
app.use(passport.initialize());
app.use(passport.session());
app.use(methodOverride('_method'));
app.use(cookieParser());
app.set('view engine', 'ejs');

Expand All @@ -69,14 +64,6 @@ app.use((req, res, next) => {
next();
});

app.use((req, res, next) => {
if (req.session) {
req.session._garbage = Date();
req.session.touch();
}
next();
});

// Middleware to add auth token
function addAuthToken(req, res, next) {
if (req.isAuthenticated()) {
Expand Down Expand Up @@ -229,16 +216,6 @@ app.get('/register', checkNotAuthenticated, (req, res) => {
res.render('register', { errorMessages: req.flash('error') || [] });
});

app.delete('/logout', (req, res, next) => {
res.clearCookie('remember_me');
req.logOut((err) => {
if (err) {
return next(err);
}
res.redirect('/');
});
});

app.get('/logout', function (req, res, next) {
if (req.session) {
req.session.destroy(function (err) {
Expand Down Expand Up @@ -407,9 +384,6 @@ function checkNotAuthenticated(req, res, next) {

const GoogleStrategy = require('passport-google-oauth20').Strategy;

app.use(passport.initialize());
app.use(passport.session());

passport.use(
new GoogleStrategy(
{
Expand Down

0 comments on commit 4423885

Please sign in to comment.