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';
|
2019-03-18 15:33:43 +01:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.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 {
|
|
|
|
constructor(authService: AuthService, apiService: ApiService,
|
|
|
|
cryptoFunctionService: CryptoFunctionService, syncService: SyncService,
|
|
|
|
i18nService: I18nService) {
|
|
|
|
super(authService, apiService, i18nService);
|
|
|
|
this.validatedParams = async () => {
|
|
|
|
const key = await cryptoFunctionService.randomBytes(64);
|
|
|
|
process.env.BW_SESSION = Utils.fromBufferToB64(key);
|
|
|
|
};
|
|
|
|
this.success = async () => {
|
|
|
|
await syncService.fullSync(true);
|
2018-05-16 04:47:52 +02:00
|
|
|
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' +
|
2018-05-17 05:27:47 +02:00
|
|
|
'$ export BW_SESSION="' + process.env.BW_SESSION + '"\n' +
|
|
|
|
'> $env:BW_SESSION="' + process.env.BW_SESSION + '"\n\n' +
|
2018-05-16 04:47:52 +02:00
|
|
|
'You can also pass the session key to any command with the `--session` option. ex:\n' +
|
2018-05-18 15:16:34 +02:00
|
|
|
'$ bw list items --session ' + process.env.BW_SESSION);
|
2018-05-16 04:47:52 +02:00
|
|
|
res.raw = process.env.BW_SESSION;
|
2019-03-18 15:33:43 +01:00
|
|
|
return res;
|
|
|
|
};
|
2018-05-16 03:11:58 +02:00
|
|
|
}
|
2018-05-12 21:12:28 +02:00
|
|
|
}
|