"use strict";
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*
Redeeming a password reset works as follows:

1. check that the password reset id is valid still; error if not
2. check that the password is valid; error if not
3. invalidate password reset id by writing that it is used to the database
4. write hash of new password to the database
5. respond success and sign user in.
*/
const redeem_password_reset_1 = __importDefault(require("@cocalc/server/auth/redeem-password-reset"));
const sign_in_1 = require("./sign-in");
const get_params_1 = __importDefault(require("lib/api/get-params"));
async function redeemPasswordResetAPIEndPoint(req, res) {
    const { password, passwordResetId } = (0, get_params_1.default)(req);
    let account_id;
    try {
        account_id = await (0, redeem_password_reset_1.default)(password, passwordResetId);
    }
    catch (err) {
        res.json({ error: `${err.message}` });
        return;
    }
    await (0, sign_in_1.signUserIn)(req, res, account_id);
    return;
}
exports.default = redeemPasswordResetAPIEndPoint;
//# sourceMappingURL=redeem-password-reset.js.map