1/*
2 * Copyright (c) 2022-2023 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 Log from '../utils/log';
17import UserAuthModel from '../model/userAuthModel';
18import UserIdmModel from '../model/userIdmModel';
19import router from '@system.router';
20
21class EntryViewController {
22  private readonly TAG: string = 'EntryViewController';
23
24  constructor() {
25    Log.info(this.TAG, 'constructor+');
26    UserIdmModel.updateFaceInfo();
27    Log.info(this.TAG, 'constructor-');
28  }
29
30  async doPINAuth(): Promise<void> {
31    try {
32      Log.info(this.TAG, 'doPINAuth+');
33      let challenge = await UserIdmModel.getChallenge();
34      let token = await UserAuthModel.authPin(challenge);
35      if (token.length === 0) {
36        Log.error(this.TAG, 'authPin fail ');
37        throw 1;
38      }
39      UserIdmModel.setToken(token);
40      Log.info(this.TAG, 'set token ok');
41    } catch (err) {
42      Log.error(this.TAG, 'exception ' + JSON.stringify(err));
43      Log.info(this.TAG, 'doPINAuth -');
44      throw 1;
45    }
46    if (UserIdmModel.getFaceNum() === 0) {
47      Log.info(this.TAG, 'route to enrollIntro');
48      router.replace({uri: 'pages/enrollIntro'});
49    } else {
50      Log.info(this.TAG, 'route to faceConfig');
51      router.replace({uri: 'pages/faceConfig'});
52    }
53
54    Promise.resolve(0);
55    Log.info(this.TAG, 'doPINAuth -');
56  }
57}
58
59let entryViewController = new EntryViewController();
60export default entryViewController as EntryViewController;