(req)
| 235 | } |
| 236 | |
| 237 | async handleLogIn(req) { |
| 238 | const user = await this._authenticateUserFromRequest(req); |
| 239 | const authData = req.body && req.body.authData; |
| 240 | // Check if user has provided their required auth providers |
| 241 | Auth.checkIfUserHasProvidedConfiguredProvidersForLogin( |
| 242 | req, |
| 243 | authData, |
| 244 | user.authData, |
| 245 | req.config |
| 246 | ); |
| 247 | |
| 248 | let authDataResponse; |
| 249 | let validatedAuthData; |
| 250 | if (authData) { |
| 251 | const res = await Auth.handleAuthDataValidation( |
| 252 | authData, |
| 253 | new RestWrite( |
| 254 | req.config, |
| 255 | req.auth, |
| 256 | '_User', |
| 257 | { objectId: user.objectId }, |
| 258 | req.body || {}, |
| 259 | user, |
| 260 | req.info.clientSDK, |
| 261 | req.info.context |
| 262 | ), |
| 263 | user |
| 264 | ); |
| 265 | authDataResponse = res.authDataResponse; |
| 266 | validatedAuthData = res.authData; |
| 267 | } |
| 268 | |
| 269 | // handle password expiry policy |
| 270 | if (req.config.passwordPolicy && req.config.passwordPolicy.maxPasswordAge) { |
| 271 | let changedAt = user._password_changed_at; |
| 272 | |
| 273 | if (!changedAt) { |
| 274 | // password was created before expiry policy was enabled. |
| 275 | // simply update _User object so that it will start enforcing from now |
| 276 | changedAt = new Date(); |
| 277 | req.config.database.update( |
| 278 | '_User', |
| 279 | { username: user.username }, |
| 280 | { _password_changed_at: Parse._encode(changedAt) } |
| 281 | ); |
| 282 | } else { |
| 283 | // check whether the password has expired |
| 284 | if (changedAt.__type == 'Date') { |
| 285 | changedAt = new Date(changedAt.iso); |
| 286 | } |
| 287 | // Calculate the expiry time. |
| 288 | const expiresAt = new Date( |
| 289 | changedAt.getTime() + 86400000 * req.config.passwordPolicy.maxPasswordAge |
| 290 | ); |
| 291 | if (expiresAt < new Date()) |
| 292 | // fail of current time is past password expiry time |
| 293 | { throw new Parse.Error( |
| 294 | Parse.Error.OBJECT_NOT_FOUND, |
no test coverage detected