2020-08-03 18:30:32 +02:00
|
|
|
import * as program from 'commander';
|
|
|
|
|
2018-05-15 23:17:47 +02:00
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
2018-05-12 21:12:28 +02:00
|
|
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
2018-05-16 03:11:58 +02:00
|
|
|
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
|
2020-08-03 18:30:32 +02:00
|
|
|
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
2019-03-18 15:33:43 +01:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2020-08-03 18:30:32 +02:00
|
|
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
2018-05-17 03:16:42 +02:00
|
|
|
import { SyncService } from 'jslib/abstractions/sync.service';
|
2018-05-12 21:12:28 +02:00
|
|
|
|
2019-03-16 03:34:59 +01:00
|
|
|
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
2018-05-13 03:24:28 +02:00
|
|
|
|
2018-05-16 03:11:58 +02:00
|
|
|
import { Utils } from 'jslib/misc/utils';
|
|
|
|
|
2019-03-18 15:33:43 +01:00
|
|
|
import { LoginCommand as BaseLoginCommand } from 'jslib/cli/commands/login.command';
|
|
|
|
|
|
|
|
export class LoginCommand extends BaseLoginCommand {
|
2020-08-03 18:30:32 +02:00
|
|
|
private cmd: program.Command;
|
|
|
|
|
2019-03-18 15:33:43 +01:00
|
|
|
constructor(authService: AuthService, apiService: ApiService,
|
|
|
|
cryptoFunctionService: CryptoFunctionService, syncService: SyncService,
|
2020-08-03 18:30:32 +02:00
|
|
|
i18nService: I18nService, environmentService: EnvironmentService,
|
|
|
|
passwordGenerationService: PasswordGenerationService) {
|
|
|
|
super(authService, apiService, i18nService, environmentService, passwordGenerationService,
|
2020-08-04 14:50:22 +02:00
|
|
|
cryptoFunctionService, 'cli');
|
2019-03-18 15:33:43 +01:00
|
|
|
this.validatedParams = async () => {
|
|
|
|
const key = await cryptoFunctionService.randomBytes(64);
|
|
|
|
process.env.BW_SESSION = Utils.fromBufferToB64(key);
|
|
|
|
};
|
|
|
|
this.success = async () => {
|
|
|
|
await syncService.fullSync(true);
|
2020-08-03 18:30:32 +02:00
|
|
|
if (this.cmd.sso != null && this.canInteract) {
|
|
|
|
const res = new MessageResponse('You are logged in!', '\n' +
|
|
|
|
'To unlock your vault, use the `unlock` command. ex:\n' +
|
|
|
|
'$ bw unlock');
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
const res = new MessageResponse('You are logged in!', '\n' +
|
|
|
|
'To unlock your vault, set your session key to the `BW_SESSION` environment variable. ex:\n' +
|
|
|
|
'$ export BW_SESSION="' + process.env.BW_SESSION + '"\n' +
|
|
|
|
'> $env:BW_SESSION="' + process.env.BW_SESSION + '"\n\n' +
|
|
|
|
'You can also pass the session key to any command with the `--session` option. ex:\n' +
|
|
|
|
'$ bw list items --session ' + process.env.BW_SESSION);
|
|
|
|
res.raw = process.env.BW_SESSION;
|
|
|
|
return res;
|
|
|
|
}
|
2019-03-18 15:33:43 +01:00
|
|
|
};
|
2018-05-16 03:11:58 +02:00
|
|
|
}
|
2020-08-03 18:30:32 +02:00
|
|
|
|
|
|
|
run(email: string, password: string, cmd: program.Command) {
|
|
|
|
this.cmd = cmd;
|
|
|
|
return super.run(email, password, cmd);
|
|
|
|
}
|
2018-05-12 21:12:28 +02:00
|
|
|
}
|