[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.

Removed username, just emails

KH (Sep 26, 2017, 8:51 PM +0200) 23795ed7 ee698e80

+39 -60
+4 -4
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(function(email, password, done) { 8 + // match email 9 + db.query("SELECT * FROM users WHERE email = ?", email, function(err, result) { 10 10 if (err) console.log(err); 11 - if (!result[0]) return done(null, false, {username: "exist"}); 11 + if (!result[0]) return done(null, false, {email: "exist"}); 12 12 13 13 // match password 14 14 bcrypt.compare(password, result[0].password, function(err, isMatch) {
+26 -36
web/src/modules/routes.js
··· 181 181 // ---------- account ---------- 182 182 183 183 module.exports.login = (req, res) => { 184 - let username = req.body.username; 184 + let email = req.body.email; 185 185 let password = req.body.password; 186 186 let errors = {}; 187 - if (validator.isEmpty(username)) errors.username = "empty"; 188 - if (!validator.isLength(username, {max: 30})) errors.username = "long"; 187 + if (!validator.isEmail(email)) errors.email = "invalid"; 188 + if (validator.isEmpty(email)) errors.email = "empty"; 189 + if (!validator.isLength(email, {max: 60})) errors.email = "long"; 189 190 if (!validator.isLength(password, {min: 8})) errors.password = "short"; 190 191 if (!validator.isLength(password, {max: 100})) errors.password = "long"; 191 192 192 - if (!errors.username && !errors.password) { 193 + if (!errors.email && !errors.password) { 193 194 // auth 194 195 passport.authenticate("local", function(err, user, info) { 195 196 if (err) return console.log(err); 196 197 if (!user) { 197 - if (info.username) errors.username = info.username; 198 + if (info.email) errors.email = info.email; 198 199 if (info.password) errors.password = info.password; 199 200 res.json({ "errors": errors }); 200 201 } else { ··· 219 220 // console.log("-----err"); 220 221 // console.log(error); 221 222 // }); 222 - client.indices.putMapping({ 223 - index: "users", 224 - type: "user", 225 - body: { 226 - properties: { 227 - username: "text", 228 - email: "text", 229 - password: "text" 230 - } 231 - } 232 - }).then((body) => { 233 - console.log("-----suc"); 234 - console.log(body); 235 - }, (error) => { 236 - console.log("-----err"); 237 - console.log(error); 238 - }); 223 + // client.indices.putMapping({ 224 + // index: "users", 225 + // type: "cooltype", 226 + // body: { 227 + // "properties": { 228 + // "full_name": { 229 + // "type": "text" 230 + // } 231 + // } 232 + // } 233 + // }).then((body) => { 234 + // console.log("-----suc"); 235 + // console.log(body); 236 + // }, (error) => { 237 + // console.log("-----err"); 238 + // console.log(error); 239 + // }); 239 240 240 241 module.exports.register = (req, res) => { 241 - let username = req.body.username; 242 242 let email = req.body.email; 243 243 let password = req.body.password; 244 244 let password2 = req.body.password2; 245 245 let errors = {}; 246 - if (validator.isEmpty(username)) errors.username = "empty"; 247 - if (!validator.isLength(username, {max: 30})) errors.username = "long"; 248 246 if (!validator.isEmail(email)) errors.email = "invalid"; 249 247 if (validator.isEmpty(email)) errors.email = "empty"; 250 248 if (!validator.isLength(email, {max: 60})) errors.email = "long"; 251 249 if (!validator.isLength(password, {min: 8})) errors.password = "short"; 252 250 if (!validator.isLength(password, {max: 100})) errors.password = "long"; 253 251 if (!validator.equals(password2, password)) errors.password2 = "match"; 254 - db.query("SELECT * FROM users WHERE username = ? OR email = ?", [username, email], function(err, result) { 252 + db.query("SELECT * FROM users WHERE email = ?", email, function(err, result) { 255 253 if (err) console.log(err); 256 - if (result[0] && result[0].username == username) errors.username = "exist"; 257 254 if (result[0] && result[0].email == email) errors.email = "exist"; 258 - if (result[1] && result[1].username == username) errors.username = "exist"; 259 255 if (result[1] && result[1].email == email) errors.email = "exist"; 260 - if (!errors.username && !errors.email && !errors.password && !errors.password2) { 256 + if (!errors.email && !errors.password && !errors.password2) { 261 257 bcrypt.genSalt(10, function(err, salt) { 262 258 if (err) { 263 259 jsonResErr(res, {unknown: 55529}); ··· 266 262 if (err) { 267 263 jsonResErr(res, {unknown: 55222}); 268 264 } else { 269 - let values = { 270 - userId: b32(6), 271 - username: username, 272 - email: email, 273 - password: hashedPassword 274 - }; 275 265 client.index({ 276 266 index: "users", 277 267 type: "user", 278 268 body: { 279 - username: username, 269 + userId: b32(6), 280 270 email: email, 281 271 password: hashedPassword 282 272 }
+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
+8 -17
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']"); ··· 1330 1327 if (!form.classList.contains("login")) { 1331 1328 email.setAttribute("tabindex", "-1"); 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 1348 "type=login"+ 1352 - "&username="+username.value+ 1349 + "&email="+email.value+ 1353 1350 "&password="+password.value; 1354 1351 xhr(req, "/login", function(res) { 1355 1352 var errors = JSON.parse(res).errors; 1356 1353 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"); 1354 + if (errors.email == "invalid") displayErr("email", "That email isn't valid"); 1355 + if (errors.email == "empty") displayErr("email", "We need your email"); 1356 + if (errors.email == "long") displayErr("email", "Maximum 60 characters :/"); 1357 + if (errors.email == "exist") displayErr("email", "Email already exists"); 1360 1358 if (errors.password == "short") displayErr("password", "That's a bit short... Try 8 characters"); 1361 1359 if (errors.password == "long") displayErr("password", "You crossed the 100 characters line"); 1362 1360 if (errors.password == "incorrect") displayErr("password", "You guessed the wrong password"); ··· 1371 1369 function clickRegister() { 1372 1370 resetMsgs(); 1373 1371 if (!form.classList.contains("register")) { 1374 - username.setAttribute("tabindex", "0"); 1375 1372 email.setAttribute("tabindex", "0"); 1376 1373 password.setAttribute("tabindex", "0"); 1377 1374 password2.setAttribute("tabindex", "0"); ··· 1384 1381 form.classList.add("has-been-expanded"); 1385 1382 } else { 1386 1383 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 1384 if (!b) b = validate("empty", "We need your email", email ); 1390 1385 if (!b) b = validate("longerThan", "Maximum 60 characters :/", email, 60 ); 1391 1386 if (!b) b = validate("notEmail", "That's email isn't valid", email ); ··· 1395 1390 if (!a && !b && !c && !d) { 1396 1391 var req = 1397 1392 "type=register"+ 1398 - "&username="+username.value+ 1399 1393 "&email="+email.value+ 1400 1394 "&password="+password.value+ 1401 1395 "&password2="+password2.value; ··· 1403 1397 xhr(req, "/register", function(res) { 1404 1398 var errors = JSON.parse(res).errors; 1405 1399 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 1400 if (errors.email == "invalid") displayErr("email", "That email isn't valid"); 1410 1401 if (errors.email == "empty") displayErr("email", "We need your email"); 1411 1402 if (errors.email == "long") displayErr("email", "Maximum 60 characters :/");