You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
966 B

4 years ago
  1. 'use strict';
  2. const AuthPrompt = require('../types/auth');
  3. function defaultAuthenticate(value, state) {
  4. if (value.username === this.options.username && value.password === this.options.password) {
  5. return true;
  6. }
  7. return false;
  8. }
  9. const factory = (authenticate = defaultAuthenticate) => {
  10. const choices = [
  11. { name: 'username', message: 'username' },
  12. {
  13. name: 'password',
  14. message: 'password',
  15. format(input) {
  16. if (this.options.showPassword) {
  17. return input;
  18. }
  19. let color = this.state.submitted ? this.styles.primary : this.styles.muted;
  20. return color(this.symbols.asterisk.repeat(input.length));
  21. }
  22. }
  23. ];
  24. class BasicAuthPrompt extends AuthPrompt.create(authenticate) {
  25. constructor(options) {
  26. super({ ...options, choices });
  27. }
  28. static create(authenticate) {
  29. return factory(authenticate);
  30. }
  31. }
  32. return BasicAuthPrompt;
  33. };
  34. module.exports = factory();