• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Logger from '../model/Logger'
17import appAccount from '@ohos.account.appAccount'
18
19const TAG: string = '[AccountModel]'
20const app: appAccount.AppAccountManager = appAccount.createAppAccountManager()
21
22export class AccountModel {
23  async addAccount(username: string) {
24    await app.addAccount(username)
25    Logger.info(TAG, `addAccount success`)
26    return
27  }
28
29  async deleteAccount(username: string) {
30    await app.deleteAccount(username)
31    Logger.info(TAG, `deleteAccount success`)
32    return
33  }
34
35  async setAccountCredential(username: string, credentialType: string, credential: string) {
36    await app.setAccountCredential(username, credentialType, credential)
37    Logger.info(TAG, `setAccountCredential success`)
38    return
39  }
40
41  async setAccountExtraInfo(name: string, extraInfo: string) {
42    await app.setAccountExtraInfo(name, extraInfo)
43    Logger.info(TAG, `setAccountExtraInfo success`)
44    return
45  }
46
47  async setAssociatedData(name: string, key: string, value: string) {
48    await app.setAssociatedData(name, key, value)
49    Logger.info(TAG, `setAssociatedData success`)
50    return
51  }
52
53  async getAccountCredential(name: string, credentialType: string) {
54    let result = await app.getAccountCredential(name, credentialType)
55    Logger.info(TAG, `getAccountCredential success`)
56    return result
57  }
58
59  async getAccountExtraInfo(name: string) {
60    let result = await app.getAccountExtraInfo(name)
61    Logger.info(TAG, `getAccountExtraInfo success`)
62    return result
63  }
64
65  async getAssociatedData(name: string, key: string) {
66    let result = await app.getAssociatedData(name, key)
67    Logger.info(TAG, `getAssociatedData success`)
68    return result
69  }
70}
71