<commit_before>import joi from '@hapi/joi';

const objectID = joi.string().length(24);
const userName = joi.string()
  .min(3).max(32)
  .pattern(/^[^\s\n]+$/);
const userEmail = joi.string().email();
const userPassword = joi.string().min(6);

const newStylePagination = joi.object({
  page: joi.object({
    offset: joi.number().min(0),
    limit: joi.number().min(0),
  }),
});
const oldStylePagination = joi.object({
  page: joi.number().min(0),
  limit: joi.number().min(0),
});
const pagination = [
  newStylePagination,
  oldStylePagination,
];

// Validations for authentication routes:

export const register = joi.object({
  body: joi.object({
    email: userEmail.required(),
    username: userName.required(),
    password: <PASSWORD>(),
  }),
});

export const login = joi.object({
  query: joi.object({
    session: joi.string().valid('token', 'cookie').default('token'),
  }),
  body: joi.object({
    email: userEmail.required(),
    // This is less strict than the password validation used in `register`,
    // because we check this against the DB anyway, and an error message
    // about mismatching passwords makes more sense when logging in than an
    // error message about the password being too short.
    password: joi.string().required(),
  }),
});

export const requestPasswordReset = joi.object({
  body: joi.object({
    email: userEmail.required(),
  }),
});

export const passwordReset = joi.object({
  params: joi.object({
    reset: joi.string().required(),
  }),
  body: joi.object({
    password: <PASSWORD>.<PASSWORD>(),
  }),<commit_msg>Loosen validation in login and password reset forms.<commit_after>import joi from '@hapi/joi';

const objectID = joi.string().length(24);
const userName = joi.string()
  .min(3).max(32)
  .pattern(/^[^\s\n]+$/);
const userEmail = joi.string().email();
const userPassword = joi.string().min(6);

const newStylePagination = joi.object({
  page: joi.object({
    offset: joi.number().min(0),
    limit: joi.number().min(0),
  }),
});
const oldStylePagination = joi.object({
  page: joi.number().min(0),
  limit: joi.number().min(0),
});
const pagination = [
  newStylePagination,
  oldStylePagination,
];

// Validations for authentication routes:

export const register = joi.object({
  body: joi.object({
    email: userEmail.required(),
    username: userName.required(),
    password: <PASSWORD>(),
  }),
});

export const login = joi.object({
  query: joi.object({
    session: joi.string().valid('token', 'cookie').default('token'),
  }),
  body: joi.object({
    // This is less strict than the email and password validation used in
    // `register`, because we check this against the DB anyway, and an
    // error message about a nonexistent account or mismatching passwords
    // makes more sense when logging in than an error message about the
    // email being incorrectly formatted or the password being too short.
    email: joi.string().required(),
    password: joi.string().required(),
  }),
});

export const requestPasswordReset = joi.object({
  body: joi.object({
    // Checked against DB like in `login`.
    email: joi.string().required(),
  }),
});

export const passwordReset = joi.object({
  params: joi.object({
    reset: joi.string().required(),
  }),
  body: joi.object({
    password: <PASSWORD>(),
  }),
{'fraction_non_alphanumeric': 0.1646525679758308, 'fraction_numerical': 0.006042296072507553, 'mean_word_length': 3.7640287769784173, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2533003', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1048, 'n_words': 287}