Skip to content
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

fix issue 1770: #1773

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/js/auth-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// Log the user in on the client and the server
async function login () {
alert(`login from this page is no more possible.\n\nYou must ask the pod owner to modify this page or remove it.`)
alert('login from this page is no more possible.\n\nYou must ask the pod owner to modify this page or remove it.')
/* deprecated since inrupt/solid-auth-client
const session = await auth.popupLogin()
if (session) {
Expand Down
73 changes: 36 additions & 37 deletions common/js/index-buttons.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
'use strict'
var keyname = 'SolidServerRootRedirectLink';
function register() {
alert(2); window.location.href = "/register";
const keyname = 'SolidServerRootRedirectLink'
function register () {
alert(2); window.location.href = '/register'
}
document.addEventListener('DOMContentLoaded', async function() {
const authn = UI.authn
const authSession = UI.authn.authSession
document.addEventListener('DOMContentLoaded', async function () {
const authn = UI.authn
const authSession = UI.authn.authSession

if (!authn.currentUser()) await authn.checkUser();
let user = authn.currentUser();
if (!authn.currentUser()) await authn.checkUser()
let user = authn.currentUser()

// IF LOGGED IN: SET SolidServerRootRedirectLink. LOGOUT
if( user ) {
window.localStorage.setItem(keyname, user.uri);
await authSession.logout();
}
else {
let webId = window.localStorage.getItem(keyname);
// IF LOGGED IN: SET SolidServerRootRedirectLink. LOGOUT
if (user) {
window.localStorage.setItem(keyname, user.uri)
await authSession.logout()
} else {
let webId = window.localStorage.getItem(keyname)

// IF NOT LOGGED IN AND COOKIE EXISTS: REMOVE COOKIE, HIDE WELCOME, SHOW LINK TO PROFILE
if( webId ) {
window.localStorage.removeItem(keyname);
document.getElementById('loggedIn').style.display = "block";
document.getElementById('loggedIn').innerHTML = `<p>Your WebID is : <a href="${webId}">${webId}</a>.</p> <p>Visit your profile to log into your Pod.</p>`;
}
// IF NOT LOGGED IN AND COOKIE EXISTS: REMOVE COOKIE, HIDE WELCOME, SHOW LINK TO PROFILE
if (webId) {
window.localStorage.removeItem(keyname)
document.getElementById('loggedIn').style.display = 'block'
document.getElementById('loggedIn').innerHTML = `<p>Your WebID is : <a href="${webId}">${webId}</a>.</p> <p>Visit your profile to log into your Pod.</p>`
}

// IF NOT LOGGED IN AND COOKIE DOES NOT EXIST
// SHOW WELCOME, SHOW LOGIN BUTTON
// HIDE LOGIN BUTTON, ADD REGISTER BUTTON
else {
let loginArea = document.getElementById('loginStatusArea');
let html = `<input type="button" onclick="window.location.href='/register'" value="Register to get a Pod" class="register-button">`
let span = document.createElement("span")
span.innerHTML = html
loginArea.appendChild(span);
loginArea.appendChild(UI.login.loginStatusBox(document, null, {}))
const logInButton = loginArea.querySelectorAll('input')[1];
logInButton.value = "Log in to see your WebID";
const signUpButton = loginArea.querySelectorAll('input')[2];
signUpButton.style.display = "none";
}
// IF NOT LOGGED IN AND COOKIE DOES NOT EXIST
// SHOW WELCOME, SHOW LOGIN BUTTON
// HIDE LOGIN BUTTON, ADD REGISTER BUTTON
else {
let loginArea = document.getElementById('loginStatusArea')
let html = '<input type="button" onclick="window.location.href=\'/register\'" value="Register to get a Pod" class="register-button">'
let span = document.createElement('span')
span.innerHTML = html
loginArea.appendChild(span)
loginArea.appendChild(UI.login.loginStatusBox(document, null, {}))
const logInButton = loginArea.querySelectorAll('input')[1]
logInButton.value = 'Log in to see your WebID'
const signUpButton = loginArea.querySelectorAll('input')[2]
signUpButton.style.display = 'none'
}
})
}
})
2 changes: 1 addition & 1 deletion default-views/auth/reset-link-sent.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

<div class="alert alert-success">
<p>A Reset Password link has been sent to your email.</p>
<p>A Reset Password link has been from the associated email account.</p>
</div>
</div>
</body>
Expand Down
40 changes: 23 additions & 17 deletions lib/requests/password-reset-email-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class PasswordResetEmailRequest extends AuthRequest {
static post (req, res) {
const request = PasswordResetEmailRequest.fromParams(req, res)

debug(`User '${request.username}' requested to be sent a password reset email`)
debug(
`User '${request.username}' requested to be sent a password reset email`
)

return PasswordResetEmailRequest.handlePost(request)
}
Expand All @@ -93,9 +95,9 @@ class PasswordResetEmailRequest extends AuthRequest {
return Promise.resolve()
.then(() => request.validate())
.then(() => request.loadUser())
.then(userAccount => request.sendResetLink(userAccount))
.then(() => request.renderSuccess())
.catch(error => request.error(error))
.then((userAccount) => request.sendResetLink(userAccount))
.then(() => request.resetLinkMessage())
.catch((error) => request.error(error))
}

/**
Expand All @@ -120,16 +122,17 @@ class PasswordResetEmailRequest extends AuthRequest {
loadUser () {
const username = this.username

return this.accountManager.accountExists(username)
.then(exists => {
if (!exists) {
throw new Error('Account not found for that username')
}
return this.accountManager.accountExists(username).then((exists) => {
if (!exists) {
// For security reason avoid leaking error information
// See: https://github.com/nodeSolidServer/node-solid-server/issues/1770
return this.resetLinkMessage()
}

const userData = { username }
const userData = { username }

return this.accountManager.userAccountFrom(userData)
})
return this.accountManager.userAccountFrom(userData)
})
}

/**
Expand All @@ -143,14 +146,17 @@ class PasswordResetEmailRequest extends AuthRequest {
sendResetLink (userAccount) {
const accountManager = this.accountManager

return accountManager.loadAccountRecoveryEmail(userAccount)
.then(recoveryEmail => {
return accountManager
.loadAccountRecoveryEmail(userAccount)
.then((recoveryEmail) => {
userAccount.email = recoveryEmail

debug('Sending recovery email to:', recoveryEmail)

return accountManager
.sendPasswordResetEmail(userAccount, this.returnToUrl)
return accountManager.sendPasswordResetEmail(
userAccount,
this.returnToUrl
)
})
}

Expand Down Expand Up @@ -191,7 +197,7 @@ class PasswordResetEmailRequest extends AuthRequest {
/**
* Displays the 'your reset link has been sent' success message view
*/
renderSuccess () {
resetLinkMessage () {
this.response.render('auth/reset-link-sent')
}
}
Expand Down
Loading
Loading