1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-08-27 23:31:41 +02:00

logout command

This commit is contained in:
Kyle Spearrin 2018-05-15 23:26:36 -04:00
parent 33effb1a4d
commit 6fff69c0ea
4 changed files with 47 additions and 9 deletions

View File

@ -2,9 +2,9 @@ import { AuthService } from 'jslib/services/auth.service';
import { I18nService } from './services/i18n.service';
import { NodeEnvSecureStorageService } from './services/nodeEnvSecureStorage.service';
import { NodeMessagingService } from './services/nodeMessaging.service';
import { NodePlatformUtilsService } from './services/nodePlatformUtils.service';
import { NodeStorageService } from './services/nodeStorage.service';
import { NoopMessagingService } from './services/noopMessaging.service';
import { AppIdService } from 'jslib/services/appId.service';
import { AuditService } from 'jslib/services/audit.service';
@ -28,7 +28,7 @@ import { UserService } from 'jslib/services/user.service';
import { Program } from './program';
export class Main {
messagingService: NodeMessagingService;
messagingService: NoopMessagingService;
storageService: NodeStorageService;
secureStorageService: NodeStorageService;
i18nService: I18nService;
@ -64,9 +64,9 @@ export class Main {
this.cryptoFunctionService);
this.appIdService = new AppIdService(this.storageService);
this.tokenService = new TokenService(this.storageService);
this.messagingService = new NodeMessagingService();
this.messagingService = new NoopMessagingService();
this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService,
(expired: boolean) => { /* do nothing */ });
(expired: boolean) => { this.logout(); });
this.environmentService = new EnvironmentService(this.apiService, this.storageService);
this.userService = new UserService(this.tokenService, this.storageService);
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
@ -82,7 +82,7 @@ export class Main {
() => { /* do nothing */ });
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
this.storageService, this.messagingService, (expired: boolean) => { /* do nothing */ });
this.storageService, this.messagingService, (expired: boolean) => { this.logout(); });
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
this.totpService = new TotpService(this.storageService, this.cryptoFunctionService);
this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService,
@ -95,6 +95,22 @@ export class Main {
this.program.run();
}
async logout() {
process.env.BW_SESSION = null;
const userId = await this.userService.getUserId();
await Promise.all([
this.syncService.setLastSync(new Date(0)),
this.tokenService.clearToken(),
this.cryptoService.clearKeys(),
this.userService.clear(),
this.settingsService.clear(userId),
this.cipherService.clear(userId),
this.folderService.clear(userId),
this.collectionService.clear(userId),
this.passwordGenerationService.clear(),
]);
}
private async init() {
this.containerService.attachToWindow(global);
await this.environmentService.setUrlsFromStorage();

View File

@ -0,0 +1,17 @@
import * as program from 'commander';
import { AuthService } from 'jslib/abstractions/auth.service';
import { Response } from '../models/response';
import { MessageResponse } from '../models/response/messageResponse';
export class LogoutCommand {
constructor(private authService: AuthService, private logoutCallback: () => Promise<void>) { }
async run(cmd: program.Command) {
await this.logoutCallback();
this.authService.logOut(() => { /* Do nothing */ });
const res = new MessageResponse('You have logged out.', null);
return Response.success(res);
}
}

View File

@ -10,6 +10,7 @@ import { EncodeCommand } from './commands/encode.command';
import { GetCommand } from './commands/get.command';
import { ListCommand } from './commands/list.command';
import { LoginCommand } from './commands/login.command';
import { LogoutCommand } from './commands/logout.command';
import { SyncCommand } from './commands/sync.command';
import { Response } from './models/response';
@ -48,7 +49,7 @@ export class Program {
.option('-m, --method <method>', 'Two-step login method.')
.option('-c, --code <code>', 'Two-step login code.')
.action(async (email: string, password: string, cmd: program.Command) => {
// await this.exitIfAuthed();
await this.exitIfAuthed();
const command = new LoginCommand(this.main.authService, this.main.apiService,
this.main.cryptoFunctionService);
const response = await command.run(email, password, cmd);
@ -60,7 +61,11 @@ export class Program {
.description('Log out of the current Bitwarden user account.')
.action(async (cmd) => {
await this.exitIfNotAuthed();
// TODO
const command = new LogoutCommand(this.main.authService, async () => {
await this.main.logout();
});
const response = await command.run(cmd);
this.processResponse(response, cmd);
});
program

View File

@ -1,7 +1,7 @@
import { MessagingService } from 'jslib/abstractions/messaging.service';
export class NodeMessagingService implements MessagingService {
export class NoopMessagingService implements MessagingService {
send(subscriber: string, arg: any = {}) {
// TODO
// Do nothing...
}
}