diff --git a/client/build/logo.png b/client/build/logo.png deleted file mode 100644 index f3d2503..0000000 Binary files a/client/build/logo.png and /dev/null differ diff --git a/client/src/assets/semantic-helper.css b/client/src/assets/semantic-helper.css index c79cc46..0d26571 100644 --- a/client/src/assets/semantic-helper.css +++ b/client/src/assets/semantic-helper.css @@ -86,6 +86,8 @@ body { text-align: center; } + + .ui.form input:not([type]), .ui.form input:not([type]):focus, .ui.form textarea:not([type]), @@ -94,6 +96,21 @@ body { background-color: var(--small_element_bg_color); border-color: var(--dark_border_color); } +.ui.form input[type="password"], +.ui.form input[type="text"], +.ui.input > input { + color: var(--text_color); + background-color: var(--small_element_bg_color); + border-color: var(--dark_border_color); +} +.ui.form input[type="password"]:focus, .ui.form input[type="password"]:active, +.ui.form input[type="text"]:focus, .ui.form input[type="text"]:active, +.ui.input > input:focus, .ui.input > input:active { + color: var(--text_color); + background-color: var(--small_element_bg_color); + border-color: var(--main-accent); + border-right-color: var(--main-accent) !important; +} .ui.basic.label, .ui.header, .ui.header div.sub.header { color: var(--text_color); background-color: transparent; @@ -358,10 +375,15 @@ i.green.icon.icon.icon.icon { border-collapse: collapse; } + tr { + display: flex; + } + th, td { border: 1px solid #ddd; border-bottom: 1px solid #ddd; font-weight: normal; + flex: 1; } /* table:hover th, table:hover td { border: 1px solid black; @@ -371,6 +393,22 @@ i.green.icon.icon.icon.icon { padding: 3px; text-align: left; } + .table-tic-table { + } + .table-tic-table > div { + height: 21px; + margin: 0; + padding: 0; + } + .tabletic { + display: inline-block; + border: 1px solid black; + border-radius: 2px; + width: 20px; + height: 20px; + margin: 0 1px 1px 0; + cursor: pointer; + } .t-table { width: 100%; @@ -430,7 +468,7 @@ i.green.icon.icon.icon.icon { font-family: 'Icons'; content: "\f058"; - color: #21BA45; + color: var(--main-accent); opacity: 1; } } diff --git a/client/src/components/GlobalNotificationComponent.vue b/client/src/components/GlobalNotificationComponent.vue index 462b568..3257f43 100644 --- a/client/src/components/GlobalNotificationComponent.vue +++ b/client/src/components/GlobalNotificationComponent.vue @@ -2,30 +2,31 @@ .popup-body { position: fixed; - bottom: 15px; + top: 15px; left: 15px; min-height: 50px; min-width: 200px; - max-width: calc(100% - 20px); + max-width: calc(100% - 30px); z-index: 1002; - border-top: 2px solid #21ba45; box-shadow: 0px 0px 5px 2px rgba(140,140,140,1); - border-top-right-radius: 4px; - border-top-left-radius: 4px; + border-radius: 4px; + + color: white; + background-color: var(--main-accent); } .popup-row { padding: 1em 5px; cursor: pointer; - white-space: nowrap; } .popup-row > span { - width: calc(100% - 50px); + /*width: calc(100% - 50px);*/ display: inline-block; - text-align: center; + text-align: left; box-sizing: border-box; padding: 0 10px 0; font-size: 1.25em; + border-radius: 4px; } .popup-row + .popup-row { border-top: 1px solid #FFF; @@ -36,12 +37,10 @@ } @keyframes slide-in-bottom { 0% { - transform: translateY(1000px); - opacity: 0; + transform: translateY(-1000px); } 100% { transform: translateY(0); - opacity: 1; } } @@ -63,14 +62,46 @@ } } + .meter { + height: 2px; + display: inline-block; + width: 100%; + position: fixed; + top: 0; + left: 0; + right: 0; + overflow: hidden; + border-top-right-radius: 4px; + border-top-left-radius: 4px; + } + + .meter span { + display: block; + height: 100%; + } + + .progress { + background-color: white; + animation: progressBar 3s linear; + animation-fill-mode: both; + } + + @keyframes progressBar { + 0% { width: 0; } + 100% { width: 100%; } + } + @@ -94,9 +125,9 @@ }, mounted(){ - // this.$bus.$emit('notification', 'Password Protection Removed') - // this.$bus.$emit('notification', 'Password Protection Removed') - // this.$bus.$emit('notification', 'Password Protection Removed') + // this.$bus.$emit('notification', 'Password Protection Removed Login did not succeed') + // this.$bus.$emit('notification', 'Password Protection Removed your life is exposed to the internet') + // this.$bus.$emit('notification', 'Password Protection Removed everyone can see everything') }, methods: { @@ -105,7 +136,7 @@ clearTimeout(this.totalTimeout) this.totalTimeout = setTimeout(() => { this.dismiss() - }, 4000) + }, 3000) }, dismiss(){ this.notifications = [] diff --git a/client/src/components/GlobalSiteMenu.vue b/client/src/components/GlobalSiteMenu.vue index 50915da..d591911 100644 --- a/client/src/components/GlobalSiteMenu.vue +++ b/client/src/components/GlobalSiteMenu.vue @@ -133,9 +133,23 @@
- + + + + + + + @@ -167,10 +181,8 @@ diff --git a/client/src/mixins/SquireButtonFunctions.js b/client/src/mixins/SquireButtonFunctions.js index 7726972..3caa9bb 100644 --- a/client/src/mixins/SquireButtonFunctions.js +++ b/client/src/mixins/SquireButtonFunctions.js @@ -345,62 +345,26 @@ const SquireButtonFunctions = { this.editor.focus() this.editor.moveCursorToEnd() }, - insertTable(wide, tall){ - console.log('Insert a table') + insertTable(tall, wide){ + console.log(`Table: ${wide} x ${tall}`) - let tableSyntax = ` -
- - - - - - - - - - - - - -







-
- ` - - tableSyntax = ` - - - -


-
- -


-
-
- - -


-
- -


-
-
-
-


- ` - tableSyntax = '' - tableSyntax += '' + //Insert a table + let tableSyntax = '
' + tableSyntax += '' for (let i = 0; i < tall; i++) { - + tableSyntax += '' for (let j = 0; j < wide; j++) { - + tableSyntax += '' } + tableSyntax += '' } - tableSyntax += '


' + tableSyntax += '



' this.editor.insertHTML(tableSyntax) this.editor.focus() this.editor.moveCursorToEnd() + + this.$router.go(-1) }, }, } diff --git a/client/src/pages/HelpPage.vue b/client/src/pages/HelpPage.vue index 94f14e9..ed309db 100644 --- a/client/src/pages/HelpPage.vue +++ b/client/src/pages/HelpPage.vue @@ -1,31 +1,29 @@ diff --git a/client/src/pages/SettingsPage.vue b/client/src/pages/SettingsPage.vue index 77050c1..df29dfb 100644 --- a/client/src/pages/SettingsPage.vue +++ b/client/src/pages/SettingsPage.vue @@ -8,6 +8,23 @@ Settings +
+

Change Password

+

Create a new scratch pad. Old scratch pad will turn into a normal note.

+
+ + New Scratch Pad +
+
+ + Cancel +
+
+ + Confirm +
+
+
@@ -65,20 +82,20 @@
- +
- +
- -
+ +
Change it!
@@ -98,7 +115,7 @@
-
+
Log Out all other browsers
@@ -123,6 +140,7 @@ password: '', qrCode: '', verificationToken: '', + showNewNoteConfirm: false, themeColors: [ '#21BA45', //Green @@ -137,10 +155,26 @@ '#fbbd08', //Yellow '#767676', //Grey '#303030', //Black-almost - ] + ], + + change1: '', + change2: '', + change3: '', } }, methods: { + newQuickNote(){ + + this.showNewNoteConfirm = true + + axios.post('/api/quick-note/new') + .then( ({data}) => { + this.showNewNoteConfirm = false + this.$store.dispatch('fetchAndUpdateUserTotals') + this.$bus.$emit('notification', 'New Scratch Pad Created') + }) + + }, logout() { this.$store.commit('destroyLoginToken') this.$router.push('/') @@ -176,6 +210,47 @@ //It failed } }) + }, + passwordChange(){ + + if(this.change1 == '' || this.change2 == '' || this.change3 == ''){ + this.$bus.$emit('notification', 'All Password Fields Required') + return + } + + if(this.change1 == this.change2){ + this.$bus.$emit('notification', 'Old password matches new password') + return + } + + if(this.change2 != this.change3){ + this.$bus.$emit('notification', 'New Passwords do not match') + return + } + + const postData = { + 'currentPass':this.change1, + 'newPass':this.change3 + } + + axios.post('/api/user/changepassword', postData) + .then(({data}) => { + if(data){ + this.$bus.$emit('notification', 'Success: Password Changed') + this.change1 = '' + this.change2 = '' + this.change3 = '' + } else { + this.$bus.$emit('notification', 'Failed to change password') + this.change1 = '' + } + }) + }, + revokeAllSessions(){ + axios.post('/api/user/revokesessions') + .then(({data}) => { + this.$bus.$emit('notification', 'All other active sessions revoked.') + }) } } } diff --git a/client/src/pages/SharePage.vue b/client/src/pages/SharePage.vue index de1be7c..e4b82dd 100644 --- a/client/src/pages/SharePage.vue +++ b/client/src/pages/SharePage.vue @@ -4,38 +4,55 @@
-
+
-

{{title}}

+
-
+

{{title}}

+ +
+ +
-

- -
- Solid Scribe is an easy, free, secure Note App -
- Encrypted notes, only readable by you. Unless you share them. + +
+ +
+
+ +
+
+ +

+
+ Solid Scribe is an easy, free, secure Note App +
+ Encrypted notes, only readable by you. Unless you share them. +
+
+

+ +
+
+ + Sign Up + +
+
+ + + Learn More + +
+
-

-
-
- - Sign Up - -
-
- - - Learn More - -
+
@@ -99,7 +116,7 @@ \ No newline at end of file diff --git a/server/helpers/Auth.js b/server/helpers/Auth.js index cd75023..7367c48 100644 --- a/server/helpers/Auth.js +++ b/server/helpers/Auth.js @@ -7,6 +7,7 @@ let Auth = {} const tokenSecretKey = process.env.JSON_KEY +//Creates session token Auth.createToken = (userId, masterKey, pastId = null, pastCreatedDate = null) => { return new Promise((resolve, reject) => { @@ -42,6 +43,7 @@ Auth.createToken = (userId, masterKey, pastId = null, pastCreatedDate = null) => }) } +//Decodes session token Auth.decodeToken = (token, request = null) => { return new Promise((resolve, reject) => { diff --git a/server/index.js b/server/index.js index d49b632..be38d0b 100644 --- a/server/index.js +++ b/server/index.js @@ -263,7 +263,7 @@ let AuthTest = require('@helpers/Auth') Auth.testTwoFactor() Auth.test() -UserTest.keyPairTest('genMan16', '1', printResults) +UserTest.keyPairTest('genMan23', '1', printResults) .then( ({testUserId, masterKey}) => NoteTest.test(testUserId, masterKey, printResults)) .then( message => { if(printResults) console.log(message) diff --git a/server/models/QuickNote.js b/server/models/QuickNote.js index 27e7d73..aedbf4a 100644 --- a/server/models/QuickNote.js +++ b/server/models/QuickNote.js @@ -10,19 +10,28 @@ QuickNote.get = (userId, masterKey) => { db.promise() .query(` - SELECT note.id FROM note WHERE quick_note = 1 AND user_id = ? LIMIT 1 - `, [userId]) + SELECT note.id FROM note WHERE quick_note = 1 AND user_id = ? LIMIT 1`, [userId]) .then((rows, fields) => { //Quick Note is set, return note text if(rows[0][0] != undefined){ + let noteId = rows[0][0].id - Note.get(userId, noteId, masterKey) - .then( noteObject => { - return resolve(noteObject) - }) + return resolve({'noteId':noteId}) + } else { - return resolve(null) + //Or create a new note and get the id + let finalId = null + return Note.create(userId, 'Scratch Pad', '', masterKey) + .then(insertedId => { + finalId = insertedId + db.promise().query('UPDATE note SET quick_note = 1 WHERE id = ? AND user_id = ?',[insertedId, userId]) + .then((rows, fields) => { + + return resolve({'noteId':finalId}) + }) + }) + } diff --git a/server/models/User.js b/server/models/User.js index 0039773..9f13c92 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -9,7 +9,7 @@ const speakeasy = require('speakeasy') let User = module.exports = {} -const version = '3.1.3' +const version = '3.1.5' //Login a user, if that user does not exist create them //Issues login token @@ -238,7 +238,7 @@ User.getCounts = (userId) => { Object.assign(countTotals, rows[0][0]) //combine results - return db.promise().query('SELECT two_fa_enabled FROM user WHERE id = ?', [userId]) + return db.promise().query('SELECT id AS quickNote FROM note WHERE quick_note = 1 AND user_id = ?', [userId]) }).then( (rows, fields) => { @@ -432,6 +432,66 @@ User.getByUserName = (username) => { }) } +User.changePassword = (userId, oldPass, newPass) => { + return new Promise((resolve, reject) => { + User.getMasterKey(userId, oldPass) + .then(masterKey => { + User.getPrivateKey(userId, masterKey) + .then(privateKey => { + //If success, user has correct password + + // Generate new master pass, encrypt with new password + // const masterPassword = cs.createSmallSalt() + const salt = cs.createSmallSalt() + const encryptedMasterPassword = cs.encrypt(newPass, salt, masterKey) + const encryptedPrivateKey = cs.encrypt(masterKey, salt, privateKey) + + db.promise() + .query( + 'UPDATE user_key SET salt = ?, `key` = ?, private_key_encrypted = ? WHERE user_id = ? LIMIT 1', + [salt, encryptedMasterPassword, encryptedPrivateKey, userId] + ).then((r,f) => { + //Create login using password + let shasum = crypto.createHash('sha512') //Prepare Hash + const saltString = shasum.digest('hex') + const passwordSalt = Buffer.from(saltString, 'binary') //Generate Salt hash + const iterations = 25000 + + crypto.pbkdf2(newPass, passwordSalt, iterations, 512, 'sha512', function(err, delivered_key) { + + const deliveredPass = delivered_key.toString('hex') + + db.promise().query('UPDATE user SET password = ?, salt = ? WHERE id = ? LIMIT 1', [deliveredPass, passwordSalt, userId]) + .then((r,f) => { + return resolve(true) + }) + + }) + }) + + }) + + }) + .catch(error => { + resolve(false) + }) + }) +} + +User.revokeActiveSessions = (userId, sessionId) => { + return new Promise((resolve, reject) => { + + const userHash = cs.hash(String(userId)).toString('base64') + + db.promise().query('DELETE FROM user_active_session WHERE user_hash = ? AND session_id != ?', [userHash, sessionId]) + .then((r,f) => { + + resolve(true) + }) + + }) +} + User.deleteUser = (userId, password) => { //Verify user is correct by decryptig master key with password @@ -471,6 +531,7 @@ User.keyPairTest = (testUserName = 'genMan', password = '1', printResults) => { const randomUsername = Math.random().toString(36).substring(2, 15); const randomPassword = '1' + const secondPassword = '2' User.register(testUserName, password) .then( ({ token, userId }) => { @@ -478,7 +539,7 @@ User.keyPairTest = (testUserName = 'genMan', password = '1', printResults) => { if(printResults) console.log('Test: Register User '+testUserName+' - Pass') - return User.getMasterKey(testUserId, password) + return User.getMasterKey(testUserId, password) }) .then(newMasterKey => { masterKey = newMasterKey @@ -510,6 +571,26 @@ User.keyPairTest = (testUserName = 'genMan', password = '1', printResults) => { if(printResults) console.log('Test: Login New User - Pass') + return User.changePassword(testUserId, randomPassword, secondPassword) + + }) + .then(passwordChangeResults => { + + if(printResults) console.log('Test: Password Change - ', passwordChangeResults?'Pass':'Fail') + + return User.login(testUserName, secondPassword) + + }) + .then(reLogin => { + + if(printResults) console.log('Test: Login With new Password - Pass') + + return User.getMasterKey(testUserId, secondPassword) + }) + .then(newMasterKey => { + + masterKey = newMasterKey + resolve({testUserId, masterKey}) }) }) diff --git a/server/routes/quicknoteController.js b/server/routes/quicknoteController.js index bbf5008..59f230d 100644 --- a/server/routes/quicknoteController.js +++ b/server/routes/quicknoteController.js @@ -6,9 +6,8 @@ let QuickNote = require('@models/QuickNote'); let userId = null let masterKey = null -// middleware that is specific to this router router.use(function setUserId (req, res, next) { - if(userId = req.headers.userId){ + if(req.headers.userId){ userId = req.headers.userId masterKey = req.headers.masterKey } diff --git a/server/routes/userController.js b/server/routes/userController.js index fbe2a3b..aa8082a 100644 --- a/server/routes/userController.js +++ b/server/routes/userController.js @@ -41,6 +41,25 @@ router.post('/register', function (req, res) { }) }) +// change password +router.post('/changepassword', function (req, res) { + + User.changePassword(req.headers.userId, req.body.currentPass, req.body.newPass) + .then( returnData => { + res.send(returnData) + }) +}) + +//Revoke all active session keys for user +router.post('/revokesessions', function(req, res) { + + User.revokeActiveSessions(req.headers.userId, req.headers.sessionId) + .then( returnData => { + res.send(returnData) + }) + +}) + // fetch counts of users notes router.post('/totals', function (req, res) { User.getCounts(req.headers.userId)