#HarmonyOS NEXT 体验官#调用云服务认证体系 原创

鸿蒙时代
发布于 2024-8-3 10:26
浏览
0收藏

一、介绍
基于鸿蒙Next实现应用的认证注册流程。
二、场景需求

用户注册模块:

邮箱/手机号验证:

密码设置:

个人信息填写:

用户登录模块:

邮箱/手机号与密码登录:
用户输入注册时的邮箱/手机号和密码。
第三方登录选项:
提供使用社交账号(如微信、Facebook、Google等)直接登录的选项。

忘记密码模块:

找回密码流程:
用户输入注册时的邮箱/手机号,系统发送重置链接或验证码。
用户通过链接或验证码进入重置密码界面。

多因素认证(可选):

用户在登录后可选择启用多因素认证(如短信验证码、邮箱验证、Authenticator应用等)。

错误处理与反馈:

系统需提供清晰的错误信息(如“邮箱已被注册”、“密码格式不正确”等)。
注册成功后显示欢迎信息并引导用户进行后续操作(如设置个人资料)。

潜在价值:提供安全、简便的注册与认证流程,提高用户体验。通过验证机制确保数据安全,减少虚假账户,同时保护用户隐私。
提升用户的快速注册与登录效率,增强用户留存和活跃度。
这种认证注册流程可以确保用户体验流畅,同时满足安全性与隐私保护的需求。

三、业务步骤
第一步:在页面初始化的时候判定账号是否注册
第二步:账号注册登录,直接显示可操作页面
第三步:账号未注册登录,进入注册登录环节
第四步:注册认证账号完成

四、效果展示
#HarmonyOS NEXT 体验官#调用云服务认证体系-鸿蒙开发者社区

五:代码展示:

import { promptAction, router } from '@kit.ArkUI';
import cloud from '@hw-agconnect/cloud';
import { PointsList } from '../PointsList';
import schema from '../idiom-schema.json';
import { Logger } from '@hw-agconnect/hmcore';
import { TAG } from '@ohos/hypium/src/main/Constant';

import { CommonConstants, FooterTabType } from '../common/CommonConstants';
import { HomePage } from '../pages/HomePage'
import { IdiomPage } from '../pages/IdiomPage'
import { PointsListPage } from '../pages/PointsListPage'
import { MinePage } from '../pages/MinePage'

AppStorage.setOrCreate('isLogin', true)
AppStorage.setOrCreate('Phone', 'admin')
AppStorage.setOrCreate('Password', '123456')


@Entry
@Component
struct Index {
  @State currentIndex: number = 0;
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  private controller: TabsController = new TabsController()
  @Provide pointsList: PointsList[] = [] //排上榜单数据

  @Builder
  tabBuilder(tabList: FooterTabType[], index: number) {
    Column() {
      Image(this.currentIndex === index ? tabList[index].icon_select : tabList[index].icon_normal)
        .width(28)
        .height(28)
        .objectFit(ImageFit.Contain)
      Text(tabList[index].title)
        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
        .fontSize(12)
        .fontWeight(500)
        .lineHeight(20)
    }.width('100%')
  }

  onPageShow(): void {
    if (router.getParams() as number != null && router.getParams() as number != undefined) {
      this.currentIndex = router.getParams() as number
    } else {
      this.currentIndex = 0
    }
    this.isSilentLogin() // 是否登录
  }

  isSilentLogin() {
    cloud.auth().getCurrentUser().then(user => {
      if (user) {
        //业务逻辑
        AppStorage.set('isLogin', false)
        return
      }
      AppStorage.set('isLogin', true)
    });
  }

  build() {
    Stack() {
      Tabs({ barPosition: BarPosition.End, controller: this.controller }) {
        TabContent() {
          Column() {
            HomePage()
          }.height('100%')
          .width('100%')
          .backgroundColor(0xeeeeee)
        }.tabBar(this.tabBuilder(CommonConstants.FOOTER_TAB_TITLE, 0))

        TabContent() {
          Column() {
            IdiomPage()
          }.height('100%')
          .width('100%')
          .backgroundColor(0xeeeeee)
        }.tabBar(this.tabBuilder(CommonConstants.FOOTER_TAB_TITLE, 1))

        TabContent() {
          Column() {
            PointsListPage()
          }.height('100%')
          .width('100%')
          .backgroundColor(0xeeeeee)
        }.tabBar(this.tabBuilder(CommonConstants.FOOTER_TAB_TITLE, 2))

        TabContent() {
          Column() {
            MinePage()
          }.height('100%')
          .width('100%')
          .backgroundColor(0xeeeeee)

        }.tabBar(this.tabBuilder(CommonConstants.FOOTER_TAB_TITLE, 3))

      }
      .scrollable(false)
      .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
      .height("100%")
      .width("100%")
      .onChange((idx: number) => {
        this.currentIndex = idx
      })

    }
    .height('100%')
    .width('100%')
  }
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
已于2024-8-3 10:27:24修改
收藏
回复
举报


回复
    相关推荐