1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-26 17:08:33 +01:00

apis for change email and change password

This commit is contained in:
Kyle Spearrin 2018-06-21 14:28:49 -04:00
parent d98aeab0c8
commit 322dcf76ae
5 changed files with 88 additions and 0 deletions

View File

@ -6,9 +6,12 @@ import { CipherBulkShareRequest } from '../models/request/cipherBulkShareRequest
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest'; import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
import { CipherRequest } from '../models/request/cipherRequest'; import { CipherRequest } from '../models/request/cipherRequest';
import { CipherShareRequest } from '../models/request/cipherShareRequest'; import { CipherShareRequest } from '../models/request/cipherShareRequest';
import { EmailRequest } from '../models/request/emailRequest';
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
import { FolderRequest } from '../models/request/folderRequest'; import { FolderRequest } from '../models/request/folderRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest'; import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest'; import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { PasswordRequest } from '../models/request/passwordRequest';
import { RegisterRequest } from '../models/request/registerRequest'; import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest'; import { TokenRequest } from '../models/request/tokenRequest';
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest'; import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
@ -32,6 +35,9 @@ export abstract class ApiService {
postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise<any>; postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise<any>;
getProfile: () => Promise<ProfileResponse>; getProfile: () => Promise<ProfileResponse>;
putProfile: (request: UpdateProfileRequest) => Promise<ProfileResponse>; putProfile: (request: UpdateProfileRequest) => Promise<ProfileResponse>;
postEmailToken: (request: EmailTokenRequest) => Promise<any>;
postEmail: (request: EmailRequest) => Promise<any>;
postPassword: (request: PasswordRequest) => Promise<any>;
getAccountRevisionDate: () => Promise<number>; getAccountRevisionDate: () => Promise<number>;
postPasswordHint: (request: PasswordHintRequest) => Promise<any>; postPasswordHint: (request: PasswordHintRequest) => Promise<any>;
postRegister: (request: RegisterRequest) => Promise<any>; postRegister: (request: RegisterRequest) => Promise<any>;

View File

@ -0,0 +1,7 @@
export class EmailRequest {
newEmail: string;
masterPasswordHash: string;
newMasterPasswordHash: string;
token: string;
key: string;
}

View File

@ -0,0 +1,4 @@
export class EmailTokenRequest {
newEmail: string;
masterPasswordHash: string;
}

View File

@ -0,0 +1,5 @@
export class PasswordRequest {
masterPasswordHash: string;
newMasterPasswordHash: string;
key: string;
}

View File

@ -12,9 +12,12 @@ import { CipherBulkShareRequest } from '../models/request/cipherBulkShareRequest
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest'; import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
import { CipherRequest } from '../models/request/cipherRequest'; import { CipherRequest } from '../models/request/cipherRequest';
import { CipherShareRequest } from '../models/request/cipherShareRequest'; import { CipherShareRequest } from '../models/request/cipherShareRequest';
import { EmailRequest } from '../models/request/emailRequest';
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
import { FolderRequest } from '../models/request/folderRequest'; import { FolderRequest } from '../models/request/folderRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest'; import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest'; import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { PasswordRequest } from '../models/request/passwordRequest';
import { RegisterRequest } from '../models/request/registerRequest'; import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest'; import { TokenRequest } from '../models/request/tokenRequest';
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest'; import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
@ -197,6 +200,69 @@ export class ApiService implements ApiServiceAbstraction {
} }
} }
async postEmailToken(request: EmailTokenRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/email-token', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
async postEmail(request: EmailRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/email', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
async postPassword(request: PasswordRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/password', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
async getAccountRevisionDate(): Promise<number> { async getAccountRevisionDate(): Promise<number> {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/revision-date', { const response = await fetch(new Request(this.apiBaseUrl + '/accounts/revision-date', {