127 lines
2.6 KiB
TypeScript
127 lines
2.6 KiB
TypeScript
/**
|
|
* App Lock Service - API calls for application lock management
|
|
*/
|
|
|
|
import api from './api';
|
|
import type { ApiResponse } from '../types';
|
|
|
|
/**
|
|
* App lock status interface
|
|
*/
|
|
export interface AppLockStatus {
|
|
is_enabled: boolean;
|
|
is_locked: boolean;
|
|
failed_attempts: number;
|
|
locked_until?: string;
|
|
}
|
|
|
|
/**
|
|
* Set password request interface
|
|
*/
|
|
export interface SetPasswordRequest {
|
|
password: string;
|
|
}
|
|
|
|
/**
|
|
* Verify password request interface
|
|
*/
|
|
export interface VerifyPasswordRequest {
|
|
password: string;
|
|
}
|
|
|
|
/**
|
|
* Verify password response interface
|
|
*/
|
|
export interface VerifyPasswordResponse {
|
|
valid: boolean;
|
|
failed_attempts: number;
|
|
locked_until?: string;
|
|
}
|
|
|
|
/**
|
|
* Change password request interface
|
|
*/
|
|
export interface ChangePasswordRequest {
|
|
old_password: string;
|
|
new_password: string;
|
|
}
|
|
|
|
/**
|
|
* Disable lock request interface
|
|
*/
|
|
export interface DisableLockRequest {
|
|
password: string;
|
|
}
|
|
|
|
/**
|
|
* Get app lock status
|
|
*/
|
|
export async function getAppLockStatus(): Promise<AppLockStatus> {
|
|
const response = await api.get<ApiResponse<AppLockStatus>>('/app-lock/status');
|
|
if (!response.data) {
|
|
throw new Error(response.error || 'Failed to get app lock status');
|
|
}
|
|
return response.data;
|
|
}
|
|
|
|
/**
|
|
* Set app lock password
|
|
*/
|
|
export async function setAppLockPassword(password: string): Promise<void> {
|
|
const response = await api.post<ApiResponse<void>>('/app-lock/password', {
|
|
password,
|
|
});
|
|
if (!response.success && response.error) {
|
|
throw new Error(response.error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Verify app lock password
|
|
*/
|
|
export async function verifyAppLockPassword(password: string): Promise<VerifyPasswordResponse> {
|
|
const response = await api.post<ApiResponse<VerifyPasswordResponse>>('/app-lock/verify', {
|
|
password,
|
|
});
|
|
if (!response.data) {
|
|
throw new Error(response.error || 'Failed to verify password');
|
|
}
|
|
return response.data;
|
|
}
|
|
|
|
/**
|
|
* Change app lock password
|
|
*/
|
|
export async function changeAppLockPassword(
|
|
oldPassword: string,
|
|
newPassword: string
|
|
): Promise<void> {
|
|
const response = await api.post<ApiResponse<void>>('/app-lock/password/change', {
|
|
old_password: oldPassword,
|
|
new_password: newPassword,
|
|
});
|
|
if (!response.success && response.error) {
|
|
throw new Error(response.error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Disable app lock
|
|
*/
|
|
export async function disableAppLock(password: string): Promise<void> {
|
|
const response = await api.post<ApiResponse<void>>('/app-lock/disable', {
|
|
password,
|
|
});
|
|
if (!response.success && response.error) {
|
|
throw new Error(response.error);
|
|
}
|
|
}
|
|
|
|
export default {
|
|
getAppLockStatus,
|
|
setAppLockPassword,
|
|
verifyAppLockPassword,
|
|
changeAppLockPassword,
|
|
disableAppLock,
|
|
};
|