From a8a966866c4d9a1557e1887e66eb56cc36552ee4 Mon Sep 17 00:00:00 2001 From: Max G Date: Tue, 14 Jul 2020 05:31:02 +0000 Subject: [PATCH] * Added theme colors to form fields * Added some basic table styles for inserting some shitty tables * Made popup notification styles look better and work better on mobile * Quick note now opens a note and not some weird page * Menu collapses when page is small, behaves like mobile menu * Added terms and conditions to help and login forms * Added password change functionality * Better styles for shared page * Added some tests for changing password --- client/build/logo.png | Bin 6849 -> 0 bytes client/src/assets/semantic-helper.css | 40 +++++++- .../GlobalNotificationComponent.vue | 65 +++++++++---- client/src/components/GlobalSiteMenu.vue | 58 ++++++++++-- client/src/components/NoteInputPanel.vue | 13 ++- client/src/components/ShareNoteComponent.vue | 1 + client/src/mixins/SquireButtonFunctions.js | 58 +++--------- client/src/pages/HelpPage.vue | 44 +++++---- client/src/pages/SettingsPage.vue | 87 ++++++++++++++++-- client/src/pages/SharePage.vue | 63 ++++++++----- server/helpers/Auth.js | 2 + server/index.js | 2 +- server/models/QuickNote.js | 23 +++-- server/models/User.js | 87 +++++++++++++++++- server/routes/quicknoteController.js | 3 +- server/routes/userController.js | 19 ++++ 16 files changed, 423 insertions(+), 142 deletions(-) delete mode 100644 client/build/logo.png diff --git a/client/build/logo.png b/client/build/logo.png deleted file mode 100644 index f3d2503fc2a44b5053b0837ebea6e87a2d339a43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6849 zcmaKRcUV(fvo}bjDT-7nLI_nlK}sT_69H+`qzVWDA|yaU?}j417wLi^B1KB1SLsC& zL0ag7$U(XW5YR7p&Ux?sP$d4lvMt8C^+TcQu4F zQqv!UF!I+kw)c0jhd6+g6oCr9P?7)?!qX1ui*iL{p}sKCAGuJ{{W)0z1pLF|=>h}& zt(2Lr0Z`2ig8<5i%Zk}cO5Fm=LByqGWaS`oqChZdEFmc`0hSb#gg|Aap^{+WKOYcj zHjINK)KDG%&s?Mt4CL(T=?;~U@bU2x_mLKN!#GJuK_CzbNw5SMEJorG!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cytc|S)4^*t8Va3HR zg=~sN^tp9re@w=GTx$;zOWMjcg-7X3Wk^N$n;&Kf1RgVG2}2L-(0o)54C509C&77i zrjSi{X*WV=%C17((N^6R4Ya*4#6s_L99RtQ>m(%#nQ#wrRC8Y%yxkH;d!MdY+Tw@r zjpSnK`;C-U{ATcgaxoEpP0Gf+tx);buOMlK=01D|J+ROu37qc*rD(w`#O=3*O*w9?biwNoq3WN1`&Wp8TvKj3C z3HR9ssH7a&Vr<6waJrU zdLg!ieYz%U^bmpn%;(V%%ugMk92&?_XX1K@mwnVSE6!&%P%Wdi7_h`CpScvspMx?N zQUR>oadnG17#hNc$pkTp+9lW+MBKHRZ~74XWUryd)4yd zj98$%XmIL4(9OnoeO5Fnyn&fpQ9b0h4e6EHHw*l68j;>(ya`g^S&y2{O8U>1*>4zR zq*WSI_2o$CHQ?x0!wl9bpx|Cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?IH*qI5{G@Rn&}^Z{+TW}mQeb9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk#r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VCbJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{*ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- 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)