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

Ajax password reset #5332

Merged
merged 22 commits into from
Mar 14, 2019
Merged
Changes from 2 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
41 changes: 40 additions & 1 deletion src/Routers/PublicAPIRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,30 @@ export class PublicAPIRouter extends PromiseRouter {

const { username, token, new_password } = req.body;

if (!username || !token || !new_password) {
if (!username) {
if(req.xhr)
throw new Parse.Error(
Parse.Error.USERNAME_MISSING,
'Missing username'
);
return this.invalidLink(req);
}

if (!token) {
if(req.xhr)
throw new Parse.Error(
Parse.Error.OTHER_CAUSE,
'Missing token'
);
return this.invalidLink(req);
}

if (!new_password) {
if(req.xhr)
throw new Parse.Error(
Parse.Error.PASSWORD_MISSING,
'Missing password'
);
return this.invalidLink(req);
}

Expand All @@ -168,6 +191,14 @@ export class PublicAPIRouter extends PromiseRouter {
.then(
() => {
const params = qs.stringify({ username: username });

if (req.xhr) {
return Promise.resolve({
status: 200,
response: 'Password successfully reset'
});
}

return Promise.resolve({
status: 302,
location: `${config.passwordResetSuccessURL}?${params}`,
moonion marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -181,6 +212,14 @@ export class PublicAPIRouter extends PromiseRouter {
error: err,
app: config.appName,
});

if (req.xhr) {
throw new Parse.Error(
Parse.Error.OTHER_CAUSE,
'Server failed to reset password with provided data'
)
}

return Promise.resolve({
status: 302,
location: `${config.choosePasswordURL}?${params}`,
Expand Down