コード例 #1
0
ファイル: lockable.js プロジェクト: lykmapipo/irina
        function (lockable, next) {
          //check if unlock token expired
          const isTokenExpired = !Utils.isAfter(new Date(), lockable.unlockTokenExpiryAt);

          if (isTokenExpired) {
            //if expired
            next(new Error('Unlock token expired'));
          } else {
            //otherwise continue with token verification
            next(null, lockable);
          }
        },
コード例 #2
0
ファイル: confirmable.js プロジェクト: lykmapipo/irina
        //TODO check presence of confirmation token
        function (next) {
          //check if confirmation token expired
          const isTokenExpiry = !Utils.isAfter(new Date(), confirmable.confirmationTokenExpiryAt);

          if (isTokenExpiry) {
            //if token expired
            next(new Error('Confirmation token expired'));
          } else {
            //otherwise continue with token verification
            next(null, confirmable);
          }
        },
コード例 #3
0
ファイル: confirmable.js プロジェクト: lykmapipo/irina
  schema.methods.isConfirmed = function (done) {
    //this context is of model instance
    const confirmable = this;

    //check if already confirmed
    const isConfirmed =
      (confirmable.confirmedAt && confirmable.confirmedAt !== null);

    //check if confirmation token expired
    const isTokenExpired = !Utils.isAfter(new Date(), confirmable.confirmationTokenExpiryAt);

    //account has not been confirmed
    //and token has not yet expire
    if (!isConfirmed && !isTokenExpired) {
      done(new Error('Account not confirmed'));
    }

    //account has not been confirmed and
    //confirmation token is expired
    else if (!isConfirmed && isTokenExpired) {
      //compose confirmation
      async
      .waterfall(
        [
          function generateConfirmationToken(next) {
            confirmable.generateConfirmationToken(next);
          },
          function sendConfirmation(confirmable, next) {
            confirmable.sendConfirmation(next);
          }
        ],
        function (error /*, confirmable*/ ) {
          //is there any error during
          //compose new confirmation?
          if (error) {
            done(error);
          }
          //new confirmation token is
          // and send successfully
          else {
            done(new Error(
              'Confirmation token expired. Check your email for confirmation instructions.'
            ));
          }
        });
    }

    //is confirmed
    else {
      done(null, confirmable);
    }
  };
コード例 #4
0
ファイル: lockable.js プロジェクト: lykmapipo/irina
  schema.methods.isLocked = function (done) {
    //this context is of model instance
    const lockable = this;

    //check if already locked
    const isLocked =
      lockable.lockedAt && lockable.lockedAt !== null;

    //check if unlock token expired
    const isUnlockTokenExpired = !Utils.isAfter(new Date(), lockable.unlockTokenExpiryAt);

    //account is not locked
    //back-off
    if (!isLocked) {
      done(null, lockable);
    }

    //is locked and
    //unlock token is not expired
    else if (isLocked && !isUnlockTokenExpired) {
      done(new Error(
        'Account locked. Check unlock instructions sent to you.'));
    }

    //is locked and
    //unlock token is expired
    else {
      //compose lock
      async.waterfall([
        function generateUnlockToken(next) {
          lockable.generateUnlockToken(next);
        },
        function sendUnLock(lockable, next) {
          lockable.sendUnLock(next);
        }
      ], function (error /*, lockable*/ ) {
        //is there any error during
        //compose new lock?
        if (error) {
          done(error);
        }
        //new unlock token generated
        // and send successfully
        else {
          done(new Error(
            'Account locked. Check unlock instructions sent to you.'
          ));
        }
      });
    }
  };
コード例 #5
0
ファイル: confirmable.js プロジェクト: Roujdami/sails-police
Confirmable.prototype.checkConfirmation = function(confirmable, done) {
    //this context is of Confirmable
    var self = this;

    //check if already confirmed
    var isConfirmed =
        (confirmable.confirmedAt && confirmable.confirmedAt !== null);

    //check if confirmation token expired
    var isTokenExpired =
        (!Utils.isAfter(new Date(), confirmable.confirmationTokenExpiryAt));

    //is already confirmed
    if (!isConfirmed && !isTokenExpired) {
        done(new Error('Account not confirmed'));

    }
    //is not confirmed and
    //confirmation token is expired 
    else if (!isConfirmed && isTokenExpired) {
        //compose confirmation
        self
            .composeConfirmation(confirmable, function(error, confirmable) {
                //is there any error during
                //compose new confirmation?
                if (error) {
                    done(error);
                }
                //new confirmation token is
                // and send successfully
                else {
                    done(new Error('Confirmation token expired. Check your email for confirmation.'));
                }
            });
    }
    //is confirmed 
    else {
        done(null, confirmable);
    }
};