| 177 | } |
| 178 | |
| 179 | resetPassword(req) { |
| 180 | const config = req.config; |
| 181 | |
| 182 | if (!config) { |
| 183 | this.invalidRequest(); |
| 184 | } |
| 185 | |
| 186 | const { new_password, token: rawToken } = req.body || {}; |
| 187 | const token = typeof rawToken === 'string' ? rawToken : undefined; |
| 188 | |
| 189 | if ((!token || !new_password) && req.xhr === false) { |
| 190 | return this.goToPage(req, pages.passwordResetLinkInvalid); |
| 191 | } |
| 192 | |
| 193 | if (!token) { |
| 194 | throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'Missing token'); |
| 195 | } |
| 196 | |
| 197 | if (!new_password) { |
| 198 | throw new Parse.Error(Parse.Error.PASSWORD_MISSING, 'Missing password'); |
| 199 | } |
| 200 | |
| 201 | return config.userController |
| 202 | .updatePassword(token, new_password) |
| 203 | .then( |
| 204 | () => { |
| 205 | return Promise.resolve({ |
| 206 | success: true, |
| 207 | }); |
| 208 | }, |
| 209 | err => { |
| 210 | return Promise.resolve({ |
| 211 | success: false, |
| 212 | err, |
| 213 | }); |
| 214 | } |
| 215 | ) |
| 216 | .then(result => { |
| 217 | if (req.xhr) { |
| 218 | if (result.success) { |
| 219 | return Promise.resolve({ |
| 220 | status: 200, |
| 221 | response: 'Password successfully reset', |
| 222 | }); |
| 223 | } |
| 224 | if (result.err) { |
| 225 | throw new Parse.Error(Parse.Error.OTHER_CAUSE, `${result.err}`); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | const query = result.success |
| 230 | ? {} |
| 231 | : { |
| 232 | [pageParams.token]: token, |
| 233 | [pageParams.appId]: config.applicationId, |
| 234 | [pageParams.error]: result.err, |
| 235 | [pageParams.appName]: config.appName, |
| 236 | }; |