bitwarden-estensione-browser/src/app/settings/profile.component.ts

53 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-06-21 17:43:50 +02:00
import {
Component,
OnInit,
} from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { UserService } from 'jslib-common/abstractions/user.service';
2018-06-21 17:43:50 +02:00
import { UpdateProfileRequest } from 'jslib-common/models/request/updateProfileRequest';
2018-06-21 17:43:50 +02:00
import { ProfileResponse } from 'jslib-common/models/response/profileResponse';
2018-06-21 17:43:50 +02:00
@Component({
selector: 'app-profile',
templateUrl: 'profile.component.html',
})
export class ProfileComponent implements OnInit {
loading = true;
profile: ProfileResponse;
2018-11-15 05:13:50 +01:00
fingerprint: string;
2018-06-21 17:43:50 +02:00
formPromise: Promise<any>;
constructor(private apiService: ApiService, private i18nService: I18nService,
private toasterService: ToasterService, private userService: UserService,
private cryptoService: CryptoService, private logService: LogService) { }
2018-06-21 17:43:50 +02:00
async ngOnInit() {
this.profile = await this.apiService.getProfile();
this.loading = false;
2018-11-15 05:13:50 +01:00
const fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
if (fingerprint != null) {
this.fingerprint = fingerprint.join('-');
}
2018-06-21 17:43:50 +02:00
}
async submit() {
try {
const request = new UpdateProfileRequest(this.profile.name, this.profile.masterPasswordHint);
this.formPromise = this.apiService.putProfile(request);
await this.formPromise;
this.toasterService.popAsync('success', null, this.i18nService.t('accountUpdated'));
} catch (e) {
this.logService.error(e);
}
2018-06-21 17:43:50 +02:00
}
}