mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-03 19:14:03 +00:00 
			
		
		
		
	Can check a password reset token
This commit is contained in:
		@@ -231,4 +231,29 @@ export class AccountHelper {
 | 
			
		||||
 | 
			
		||||
		return token;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get the ID of a user from a password reset token
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param token The token to use
 | 
			
		||||
	 * @returns The ID of the user associated to the token, if it is valid / -1 else
 | 
			
		||||
	 */
 | 
			
		||||
	public static async GetUserIDFromPasswordResetToken(token: string) : Promise<number> {
 | 
			
		||||
		
 | 
			
		||||
		// Query the database
 | 
			
		||||
		const result = await DatabaseHelper.QueryRow({
 | 
			
		||||
			table: USER_TABLE,
 | 
			
		||||
			where: {
 | 
			
		||||
				password_reset_token: token,
 | 
			
		||||
			},
 | 
			
		||||
			customWhere: "password_reset_token_time_create > ?",
 | 
			
		||||
			customWhereArgs:[(time()-60*60*24).toString()] // Tokens are valid for 24 hours
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if(result == null)
 | 
			
		||||
			return -1;
 | 
			
		||||
 | 
			
		||||
		return result.ID;
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user