[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

No more usernames; Register/login with email

KH (Sep 27, 2017, 6:30 PM +0200) 3feccb2b 4c1f8634

+29 -43
db/data/ferrum/playlists.ibd

This is a binary file and will not be displayed.

db/data/ferrum/tracks.ibd

This is a binary file and will not be displayed.

db/data/ferrum/users.ibd

This is a binary file and will not be displayed.

+8 -5
web/src/modules/passport.js
··· 4 4 5 5 module.exports = function(passport) { 6 6 // local strategy 7 - passport.use(new LocalStrategy(function(username, password, done) { 8 - // match username 9 - db.query("SELECT * FROM users WHERE username = ?", [username], function(err, result) { 7 + passport.use(new LocalStrategy({ 8 + usernameField: "email", 9 + passwordField: "password" 10 + }, function(email, password, done) { 11 + // match email 12 + db.query("SELECT * FROM users WHERE email = ?", email, function(err, result) { 10 13 if (err) console.log(err); 11 - if (!result[0]) return done(null, false, {username: "exist"}); 14 + if (!result[0]) return done(null, false, {email: "exist"}); 12 15 13 16 // match password 14 17 bcrypt.compare(password, result[0].password, function(err, isMatch) { ··· 24 27 }); 25 28 26 29 passport.deserializeUser(function(userId, done) { 27 - db.query("SELECT * FROM users WHERE userId = ?", [userId], function(err, result) { 30 + db.query("SELECT * FROM users WHERE userId = ?", userId, function(err, result) { 28 31 done(err, result[0]); 29 32 }); 30 33 });
+10 -14
web/src/modules/routes.js
··· 31 31 }); 32 32 const upload = multer({storage: storage}); 33 33 34 - const jsmediatags = require("jsmediatags"); 35 34 const mm = require("music-metadata"); 36 35 const util = require("util"); 37 36 ··· 166 165 // ---------- account ---------- 167 166 168 167 module.exports.login = (req, res) => { 169 - let username = req.body.username; 168 + let email = req.body.email; 170 169 let password = req.body.password; 171 170 let errors = {}; 172 - if (validator.isEmpty(username)) errors.username = "empty"; 173 - if (!validator.isLength(username, {max: 30})) errors.username = "long"; 171 + if (!validator.isEmail(email)) errors.email = "invalid"; 172 + if (validator.isEmpty(email)) errors.email = "empty"; 173 + if (!validator.isLength(email, {max: 60})) errors.email = "long"; 174 174 if (!validator.isLength(password, {min: 8})) errors.password = "short"; 175 175 if (!validator.isLength(password, {max: 100})) errors.password = "long"; 176 176 177 - if (!errors.username && !errors.password) { 177 + 178 + if (!errors.email && !errors.password) { 178 179 // auth 180 + req.body.username = email; 179 181 passport.authenticate("local", function(err, user, info) { 180 182 if (err) return console.log(err); 181 183 if (!user) { 182 - if (info.username) errors.username = info.username; 184 + if (info.email) errors.email = info.email; 183 185 if (info.password) errors.password = info.password; 184 186 res.json({ "errors": errors }); 185 187 } else { ··· 193 195 } 194 196 195 197 module.exports.register = (req, res) => { 196 - let username = req.body.username; 197 198 let email = req.body.email; 198 199 let password = req.body.password; 199 200 let password2 = req.body.password2; 200 201 let errors = {}; 201 - if (validator.isEmpty(username)) errors.username = "empty"; 202 - if (!validator.isLength(username, {max: 30})) errors.username = "long"; 203 202 if (!validator.isEmail(email)) errors.email = "invalid"; 204 203 if (validator.isEmpty(email)) errors.email = "empty"; 205 204 if (!validator.isLength(email, {max: 60})) errors.email = "long"; 206 205 if (!validator.isLength(password, {min: 8})) errors.password = "short"; 207 206 if (!validator.isLength(password, {max: 100})) errors.password = "long"; 208 207 if (!validator.equals(password2, password)) errors.password2 = "match"; 209 - db.query("SELECT * FROM users WHERE username = ? OR email = ?", [username, email], function(err, result) { 208 + db.query("SELECT * FROM users WHERE email = ?", email, function(err, result) { 210 209 if (err) console.log(err); 211 - if (result[0] && result[0].username == username) errors.username = "exist"; 212 210 if (result[0] && result[0].email == email) errors.email = "exist"; 213 - if (result[1] && result[1].username == username) errors.username = "exist"; 214 211 if (result[1] && result[1].email == email) errors.email = "exist"; 215 - if (!errors.username && !errors.email && !errors.password && !errors.password2) { 212 + if (!errors.email && !errors.password && !errors.password2) { 216 213 bcrypt.genSalt(10, function(err, salt) { 217 214 if (err) console.log(err); 218 215 bcrypt.hash(password, salt, function(err, hashedPassword) { 219 216 if (err) console.log(err); 220 217 let values = { 221 218 userId: b32(6), 222 - username: username, 223 219 email: email, 224 220 password: hashedPassword 225 221 };
+1 -3
web/src/pug/login.pug
··· 3 3 .form 4 4 .fields 5 5 .success 6 - .error.username 7 - input.for-login.for-register(type="text", name="username", placeholder="Username", tabindex="-1") 8 6 .error.email 9 - input.for-register(type="text", name="email", placeholder="Email", tabindex="-1") 7 + input.for-login.for-register(type="text", name="email", placeholder="Email", tabindex="-1") 10 8 .error.password 11 9 input.for-login.for-register(type="password", name="password", placeholder="Password", tabindex="-1") 12 10 .error.password2
+10 -21
web/src/static/global.js
··· 1303 1303 } 1304 1304 function resetMsgs() { 1305 1305 success.classList.remove("visible"); 1306 - username. previousElementSibling.classList.remove("visible"); 1307 1306 email. previousElementSibling.classList.remove("visible"); 1308 1307 password. previousElementSibling.classList.remove("visible"); 1309 1308 password2.previousElementSibling.classList.remove("visible"); 1310 1309 } 1311 1310 function displayErr(field, msg) { 1312 - if (field == "username") field = username; 1313 1311 if (field == "email") field = email; 1314 1312 if (field == "password") field = password; 1315 1313 if (field == "password2") field = password2; ··· 1320 1318 var register = document.querySelector("button.register"); 1321 1319 var form = document.querySelector(".form"); 1322 1320 1323 - var username = document.querySelector("input[name='username']"); 1324 1321 var email = document.querySelector("input[name='email']"); 1325 1322 var password = document.querySelector("input[name='password']"); 1326 1323 var password2 = document.querySelector("input[name='password2']"); ··· 1328 1325 function clickLogin() { 1329 1326 resetMsgs(); 1330 1327 if (!form.classList.contains("login")) { 1331 - email.setAttribute("tabindex", "-1"); 1328 + email.setAttribute("tabindex", "0"); 1332 1329 password2.setAttribute("tabindex", "-1"); 1333 - username.setAttribute("tabindex", "0"); 1334 1330 password.setAttribute("tabindex", "0"); 1335 1331 login.setAttribute("tabindex", "0"); 1336 1332 register.setAttribute("tabindex", "0"); ··· 1341 1337 form.classList.add("has-been-expanded"); 1342 1338 } else { 1343 1339 var a = false, b = false; 1344 - if (!a) a = validate("empty", "You should fill this in", username ); 1345 - if (!a) a = validate("longerThan", "Keep it below 30", username, 30 ); 1340 + if (!b) b = validate("empty", "We need your email", email ); 1341 + if (!b) b = validate("longerThan", "Maximum 60 characters :/", email, 60 ); 1342 + if (!b) b = validate("notEmail", "That's email isn't valid", email ); 1346 1343 if (!b) b = validate("shorterThan", "That's a bit short... Try 8 characters", password, 8 ); 1347 1344 if (!b) b = validate("longerThan", "You crossed the 100 characters line", password, 100 ); 1348 1345 1349 1346 if (!a && !b) { 1350 1347 var req = 1351 - "type=login"+ 1352 - "&username="+username.value+ 1348 + "&email="+email.value+ 1353 1349 "&password="+password.value; 1354 1350 xhr(req, "/login", function(res) { 1355 1351 var errors = JSON.parse(res).errors; 1356 1352 if (errors) { 1357 - if (errors.username == "empty") displayErr("username", "You should fill this in"); 1358 - if (errors.username == "long") displayErr("username", "Keep it below 30"); 1359 - if (errors.username == "exist") displayErr("username", "Had trouble finding that user"); 1353 + if (errors.email == "invalid") displayErr("email", "That email isn't valid"); 1354 + if (errors.email == "empty") displayErr("email", "We need your email"); 1355 + if (errors.email == "long") displayErr("email", "Maximum 60 characters :/"); 1356 + if (errors.email == "exist") displayErr("email", "Email already exists"); 1360 1357 if (errors.password == "short") displayErr("password", "That's a bit short... Try 8 characters"); 1361 1358 if (errors.password == "long") displayErr("password", "You crossed the 100 characters line"); 1362 1359 if (errors.password == "incorrect") displayErr("password", "You guessed the wrong password"); ··· 1371 1368 function clickRegister() { 1372 1369 resetMsgs(); 1373 1370 if (!form.classList.contains("register")) { 1374 - username.setAttribute("tabindex", "0"); 1375 1371 email.setAttribute("tabindex", "0"); 1376 1372 password.setAttribute("tabindex", "0"); 1377 1373 password2.setAttribute("tabindex", "0"); ··· 1384 1380 form.classList.add("has-been-expanded"); 1385 1381 } else { 1386 1382 var a = false, b = false, c = false, d = false; 1387 - if (!a) a = validate("empty", "You should fill this in", username ); 1388 - if (!a) a = validate("longerThan", "Keep it below 30", username, 30 ); 1389 1383 if (!b) b = validate("empty", "We need your email", email ); 1390 1384 if (!b) b = validate("longerThan", "Maximum 60 characters :/", email, 60 ); 1391 1385 if (!b) b = validate("notEmail", "That's email isn't valid", email ); ··· 1394 1388 if (!d) d = validate("noMatch", "The passwords do not match", password2, password ); 1395 1389 if (!a && !b && !c && !d) { 1396 1390 var req = 1397 - "type=register"+ 1398 - "&username="+username.value+ 1399 - "&email="+email.value+ 1391 + "email="+email.value+ 1400 1392 "&password="+password.value+ 1401 1393 "&password2="+password2.value; 1402 1394 1403 1395 xhr(req, "/register", function(res) { 1404 1396 var errors = JSON.parse(res).errors; 1405 1397 if (errors) { 1406 - if (errors.username == "empty") displayErr("username", "You should fill this in"); 1407 - if (errors.username == "long") displayErr("username", "Keep it below 30"); 1408 - if (errors.username == "exist") displayErr("username", "Unavailable username"); 1409 1398 if (errors.email == "invalid") displayErr("email", "That email isn't valid"); 1410 1399 if (errors.email == "empty") displayErr("email", "We need your email"); 1411 1400 if (errors.email == "long") displayErr("email", "Maximum 60 characters :/");
web/src/tracks/493hzfr8qr.mp3

This is a binary file and will not be displayed.