rename collection auth email verification to verify and add to collection schema json

This commit is contained in:
Dan Ribbens
2020-11-09 14:10:37 -05:00
parent c6b00c9aca
commit c00e5e8904
15 changed files with 48 additions and 20 deletions

View File

@@ -81,7 +81,7 @@ const Routes = () => {
</Route>
{collections.map((collection) => {
if (collection?.auth?.emailVerification) {
if (collection?.auth?.verify) {
return (
<Route
key={`${collection.slug}-verify`}

View File

@@ -16,7 +16,7 @@ import './index.scss';
const baseClass = 'auth-fields';
const Auth = (props) => {
const { useAPIKey, requirePassword, emailVerification, collection: { slug }, email } = props;
const { useAPIKey, requirePassword, verify, collection: { slug }, email } = props;
const [changingPassword, setChangingPassword] = useState(requirePassword);
const { getField } = useFormFields();
const modified = useFormModified();
@@ -117,7 +117,7 @@ const Auth = (props) => {
)}
</div>
)}
{emailVerification && (
{verify && (
<Checkbox
label="Verified"
name="_verified"
@@ -131,7 +131,7 @@ const Auth = (props) => {
Auth.defaultProps = {
useAPIKey: false,
requirePassword: false,
emailVerification: false,
verify: false,
collection: undefined,
email: '',
};
@@ -139,7 +139,7 @@ Auth.defaultProps = {
Auth.propTypes = {
useAPIKey: PropTypes.bool,
requirePassword: PropTypes.bool,
emailVerification: PropTypes.bool,
verify: PropTypes.bool,
collection: PropTypes.shape({
slug: PropTypes.string,
}),

View File

@@ -93,7 +93,7 @@ const DefaultEditView = (props) => {
<Auth
useAPIKey={auth.useAPIKey}
requirePassword={!isEditing}
emailVerification={auth.emailVerification}
verify={auth.verify}
collection={collection}
email={data?.email}
/>
@@ -239,7 +239,10 @@ DefaultEditView.propTypes = {
timestamps: PropTypes.bool,
auth: PropTypes.shape({
useAPIKey: PropTypes.bool,
emailVerification: PropTypes.bool,
verify: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.object,
]),
maxLoginAttempts: PropTypes.number,
}),
upload: PropTypes.shape({}),

View File

@@ -33,7 +33,7 @@ async function login(args) {
const userDoc = await Model.findByUsername(email);
if (!userDoc || (args.collection.config.auth.emailVerification && userDoc._verified === false)) {
if (!userDoc || (args.collection.config.auth.verify && userDoc._verified === false)) {
throw new AuthenticationError();
}

View File

@@ -9,7 +9,7 @@ module.exports = ({ operations }, { Model, config }) => {
return new PassportAPIKey(opts, true, async (apiKey, done, req) => {
try {
const where = {};
if (config.auth.emailVerification) {
if (config.auth.verify) {
where.and = [
{
apiKey: {

View File

@@ -19,7 +19,7 @@ module.exports = ({ config, collections, operations }) => {
const collection = collections[token.collection];
const where = {};
if (collection.config.auth.emailVerification) {
if (collection.config.auth.verify) {
where.and = [
{
email: {

View File

@@ -91,7 +91,7 @@ function registerCollections() {
unlock,
} = this.requestHandlers.collections.auth;
if (collection.auth.emailVerification) {
if (collection.auth.verify) {
router
.route(`/${slug}/verify/:token`)
.post(verifyEmail);

View File

@@ -161,7 +161,7 @@ async function create(args) {
if (data.email) {
data.email = data.email.toLowerCase();
}
if (collectionConfig.auth.emailVerification) {
if (collectionConfig.auth.verify) {
data._verified = false;
data._verificationToken = crypto.randomBytes(20).toString('hex');
}
@@ -209,7 +209,7 @@ async function create(args) {
// 10. Send verification email if applicable
// /////////////////////////////////////
if (collectionConfig.auth && collectionConfig.auth.emailVerification && !disableVerificationEmail) {
if (collectionConfig.auth && collectionConfig.auth.verify && !disableVerificationEmail) {
sendVerificationEmail({
config: this.config,
sendEmail: this.sendEmail,

View File

@@ -233,7 +233,6 @@ const sanitizeCollection = (collections, collection) => {
if (!sanitized.hooks.beforeLogin) sanitized.hooks.beforeLogin = [];
if (!sanitized.hooks.afterLogin) sanitized.hooks.afterLogin = [];
if (!collection.auth.forgotPassword) sanitized.auth.forgotPassword = {};
if (!collection.auth.verify) sanitized.auth.verify = {};
let authFields = baseAuthFields;
@@ -241,7 +240,7 @@ const sanitizeCollection = (collections, collection) => {
authFields = authFields.concat(baseAPIKeyFields);
}
if (collection.auth.emailVerification) {
if (collection.auth.verify) {
authFields.push({
name: '_verified',
type: 'checkbox',

View File

@@ -22,7 +22,6 @@ const buildEmail = require('./email/build');
const identifyAPI = require('./express/middleware/identifyAPI');
const errorHandler = require('./express/middleware/errorHandler');
const performFieldOperations = require('./fields/performFieldOperations');
const validateSchema = require('./schema/validateSchema');
const localOperations = require('./collections/operations/local');
const localGlobalOperations = require('./globals/operations/local');

View File

@@ -29,6 +29,33 @@
"type": "object",
"description": "Callable functions to determine permission access"
},
"auth": {
"type": "object",
"description": "Authentication properties",
"default": false,
"properties": {
"verify": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "object",
"properties": {
"generateEmailSubject": {
"type": "string",
"description": "Subject field used when sending verify email for new user accounts"
},
"generateEmailHTML": {
"type": "object",
"description": "Function that returns HTML for the body of the email sent to verify user accounts"
}
}
}
]
}
}
},
"fields": {
"type": "array",
"description": "The attributes of the collection",

View File

@@ -28,7 +28,7 @@
},
"ogImage": {
"type": "string",
"default": "/ok.jpg"
"description": "src url for the admin image"
},
"favicon": {
"type": "string",