This commit is contained in:
@@ -1,38 +1,41 @@
|
||||
import { Types } from 'mongoose';
|
||||
import { Types } from "mongoose";
|
||||
|
||||
import { Log, Strategy, Token } from '..';
|
||||
import { STRATEGIES } from '../constants/strategies';
|
||||
import { AuthDocument } from '../schema/auth';
|
||||
import { getLoginToken } from '../utils/getLoginToken';
|
||||
import { StrategyDocument } from '../schema/strategy';
|
||||
import { Action } from '../constants/action';
|
||||
import { Log, Strategy, Token } from "..";
|
||||
import { STRATEGIES } from "../constants/strategies";
|
||||
import { AuthDocument } from "../schema/auth";
|
||||
import { getLoginToken } from "../utils/getLoginToken";
|
||||
import { StrategyDocument } from "../schema/strategy";
|
||||
import { Action } from "../constants/action";
|
||||
|
||||
export const resetPasswordPost = async (token: string, password: string) => {
|
||||
const parentId = await Token.validateResetToken(token);
|
||||
const parentId = await Token.validateResetToken(token);
|
||||
|
||||
if (parentId) {
|
||||
let parent: AuthDocument;
|
||||
let strategy: StrategyDocument | null = await Strategy.findOne({ parent: parentId, method: STRATEGIES.LOCAL });
|
||||
if (parentId) {
|
||||
let parent: AuthDocument;
|
||||
let strategy: StrategyDocument | null = await Strategy.findOne({
|
||||
parent: parentId,
|
||||
method: STRATEGIES.LOCAL,
|
||||
});
|
||||
|
||||
if (strategy) {
|
||||
parent = await strategy.getAuthRecord();
|
||||
strategy.key = password;
|
||||
await strategy.save();
|
||||
} else {
|
||||
strategy = await Strategy.create({
|
||||
key: password,
|
||||
method: STRATEGIES.LOCAL,
|
||||
parent: <Types.ObjectId>parentId,
|
||||
});
|
||||
if (strategy) {
|
||||
parent = await strategy.getAuthRecord();
|
||||
strategy.key = password;
|
||||
await strategy.save();
|
||||
} else {
|
||||
strategy = await Strategy.create({
|
||||
key: password,
|
||||
method: STRATEGIES.LOCAL,
|
||||
parent: <Types.ObjectId>parentId,
|
||||
});
|
||||
|
||||
parent = await strategy.getAuthRecord();
|
||||
parent.strategies.push(strategy._id);
|
||||
await parent.save();
|
||||
}
|
||||
|
||||
Log.add(parent._id, Action.RESET);
|
||||
return { record: parent.record, token: getLoginToken(parent) };
|
||||
parent = await strategy.getAuthRecord();
|
||||
parent.strategies.push(strategy._id);
|
||||
await parent.save();
|
||||
}
|
||||
|
||||
return false;
|
||||
Log.add(parent._id, Action.RESET);
|
||||
return { record: parent.record, token: getLoginToken(parent) };
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user