-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove token after used or when expired #106
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ var utils = require("./utils"); | |
|
||
var MATRICOLA = /^[0-9]{6}$/; | ||
var TOKEN = /^[A-Fa-f0-9]{40}$/; | ||
var MAYBE_EMPTY_TOKEN = /^(|[A-Fa-f0-9]{40})$/; | ||
var PWDHASH = /^[A-Fa-f0-9]{32}$/; | ||
var URL = /^(|http(|s)\:\/\/[A-Za-z0-9\.\-\_\%\?\&\=\/]+)$/; | ||
|
||
|
@@ -111,12 +112,32 @@ exports.saveUsers = function (matricola, hash, callback) { | |
return; | ||
} | ||
console.log("backend: password stored for %s", matricola); | ||
callback(); | ||
exports.removeToken(matricola, function (error) { | ||
if (error) { | ||
callback(error); | ||
return; | ||
} | ||
callback(); | ||
}); | ||
}); | ||
|
||
}); | ||
}; | ||
|
||
exports.removeToken = function (matricola, callback) { | ||
var delToken = {Matricola: matricola, | ||
Token: "", | ||
TokenDate: ""}; | ||
exports.writeStudentInfo(delToken, function (error) { | ||
if (error) { | ||
callback(error); | ||
return; | ||
} | ||
console.log("backend: token removed for %s", delToken.Matricola); | ||
callback(); | ||
}); | ||
}; | ||
|
||
exports.readStudentInfo = function (matricola, callback) { | ||
|
||
console.info("backend: readStudentInfo"); | ||
|
@@ -169,6 +190,9 @@ function doWriteInfo(curInfo, callback) { | |
var knownKeys = { | ||
"Nome": /^[A-Za-z\'\- ]+$/, | ||
"Cognome": /^[A-Za-z\'\- ]+$/, | ||
"Matricola": MATRICOLA, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the matricola has always been part of the structure, and earlier it worked without adding the regexp for matricola in knownKeys, I'm not sure I get the rationale of adding the regexp to knownKeys now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do more tests, but probably when I removed it earlier not everything worked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last time I tested the workflow of backend.hasValidKeys() and it worked without matricola in knownKeys. Unfortunately I haven't tested well backend.writeStudentInfo(newInfo). In general newInfo is an object with a matricola and other info to write. backend.writeStudentInfo() check the regexp before writing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to hurry. When you have time, can you please test all the code paths and report which is the code that fails if we remove (read: avoid to add in this pull request) the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. writeStudentInfo() in |
||
"Token": MAYBE_EMPTY_TOKEN, | ||
"TokenDate": /^(|[0-9]{14})$/, | ||
"Blog": URL, | ||
"Twitter": /^(|@[A-Za-z0-9_]{1,15})$/, | ||
"Wikipedia": /^(|(U|u)tente\:[^\{\}\[\]\#\|\<\>][^\{\}\[\]\#\|\<\>]+)$/, | ||
|
@@ -212,12 +236,12 @@ exports.writeStudentInfo = function (newInfo, callback) { | |
for (index = 0; index < keys.length; ++index) { | ||
key = keys[index]; | ||
if (knownKeys[key] === undefined) { | ||
console.warn("backend: unknown key"); | ||
console.warn("backend: unknown key %s", key); | ||
callback("backend: unknown key"); | ||
return; | ||
} | ||
if (newInfo[key].match(knownKeys[key]) === null) { | ||
console.info("backend: regexp does not match"); | ||
console.info("backend: regexp does not match for %s", key); | ||
callback("signup: regexp does not match"); | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason of passing the matricola here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use backend.writeStudentInfo() we have to pass matricola.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right