Skip to content
Snippets Groups Projects
Select Git revision
  • ae8c9c7d7f0efa8b0950ca544b9ae2cf9747471b
  • main default protected
  • jw_sonar
  • v6.0.0 protected
  • interactive-mode-preference
  • bedran_exercise-list
  • add_route_user
  • Jw_sonar_backup
  • exercise_list_filter
  • assignment_filter
  • add_route_assignments
  • move-to-esm-only
  • 6.0.0-dev
  • Pre-alpha
  • 5.0.0
  • Latest
  • 4.2.0
  • 4.1.1
  • 4.1.0
  • 4.0.1
  • 4.0.0
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.3.0
  • 3.2.3
  • 3.2.2
  • 3.2.0
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
32 results

SessionAppLoginCommand.ts

Blame
  • SessionAppLoginCommand.ts 1.82 KiB
    import chalk            from 'chalk';
    import CommanderCommand from '../../CommanderCommand';
    import inquirer         from 'inquirer';
    import SessionManager   from '../../../managers/SessionManager';
    
    
    class SessionAppLoginCommand extends CommanderCommand {
        protected commandName: string = 'login';
    
        private static _instance: SessionAppLoginCommand;
    
        private constructor() { super(); }
    
        public static get instance(): SessionAppLoginCommand {
            if ( !SessionAppLoginCommand._instance ) {
                SessionAppLoginCommand._instance = new SessionAppLoginCommand();
            }
    
            return SessionAppLoginCommand._instance;
        }
    
        protected defineCommand() {
            this.command
            .description('login into the application')
            .requiredOption('-u, --user <string>', '[required] username to use when connecting to server')
            .option('-p, --password <string>', 'password to use when connecting to server. If password is not given it\'s asked')
            .action(this.commandAction.bind(this));
        }
    
        protected async commandAction(options: any): Promise<void> {
            if ( !options.password ) {
                options.password = (await inquirer.prompt({
                                                              type   : 'password',
                                                              name   : 'password',
                                                              message: 'Please enter your password',
                                                              mask   : ''
                                                          })).password;
            }
    
            console.log(chalk.cyan('Please wait while we are logging in you to Dojo...'));
    
            await SessionManager.login(options.user, options.password);
    
            SessionManager.checkPermissions(true, 4);
        }
    }
    
    
    export default SessionAppLoginCommand.instance;