/** * 忘记密码-重置密码LUMI版 * @邠心vbe on 2024/06/05 */ import React, { Component } from 'react'; import { View, ScrollView, StyleSheet, TextInput } from 'react-native'; import apiUser from '../../api/apiUser'; import Dialog from '../../components/Dialog'; import TextView from '../../components/TextView'; import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage'; import utils from '../../utils/utils'; import { PageList } from '../Router'; export default class ForgotPwdVL extends Component { constructor(props) { super(props); this.state = { email: '', strength: 0, password: '', sendMinutes: 0, isChange: false, strengthCheck: { minLength: false, wordCase: false, oneNumber: false, allCheck: false }, showPassword: false, confirmStatusColor: "#F5F5F5" }; this.formInfo = { email: '', password: '', verificationCode: '' } } componentDidMount() { const action = this.props.route?.params?.action ?? ""; if (action == "change") { this.setState({ isChange: true }); const email = userInfo.email; this.formInfo.email = email; this.setState({ email: email }); } } changeInfo(key, value) { this.formInfo[key] = value; } applyStrength(text) { const strength = this.state.strengthCheck; strength.allCheck = true; if (text.length >= 8) { strength.minLength = true; } else { strength.minLength = false; strength.allCheck = false; } if (/\d{1,}/.test(text)) { strength.oneNumber = true; } else { strength.oneNumber = false; strength.allCheck = false; } if (/[a-z]{1,}/.test(text) && /[A-Z]{1,}/.test(text)) { strength.wordCase = true; } else { strength.wordCase = false; strength.allCheck = false; } this.setState({ password: text, strengthCheck: strength }); } sendVerification() { var info = this.formInfo; if (!info.email) { toastShort($t('sign.plsInputEmail')); return; } if (!utils.isValidEmail(info.email)) { toastShort($t('sign.errEmailFormat')); return; } Dialog.showProgressDialog() apiUser.sendVerificationCode(info.email).then(res => { Dialog.dismissLoading() this.state.sendMinutes = res.data?.resendTime ?? 60; toastShort($t('sign.sendOTPSuccess')); this.contdownTime(); }).catch(err => { Dialog.dismissLoading() toastShort(err); }); } contdownTime() { if (this.state.sendMinutes > 0) { this.setState({ sendMinutes: this.state.sendMinutes - 1 }) setTimeout(() => { this.contdownTime(); }, 1000); } } onResetPassword() { var info = this.formInfo; console.log('reset info', info); if (!info.email) { toastShort($t('sign.plsInputEmail')); return; } if (!utils.isValidEmail(info.email)) { toastShort($t('sign.errEmailFormat')); return; } /*if (!info.verificationCode) { toastShort($t('sign.plsInputOTP')); return; }*/ if (!this.state.password) { toastShort($t('sign.plsInputPassword')); return; } if (!this.state.strengthCheck.allCheck) { toastShort($t('sign.errPasswordStrong')); return; } if (!info.password) { toastShort($t('sign.plsInputPassword2')); return; } if (info.password != this.state.password) { toastShort($t('sign.errPasswordConfirm')); return; } Dialog.showProgressDialog() apiUser.updatePassword(this.formInfo).then(res => { Dialog.dismissLoading() toastShort($t('sign.resetPasswordSuccess')); if (this.isChange) { this.requestLogout(); } else { goBack(); } }).catch(err => { Dialog.dismissLoading() toastShort(err); }); } async requestLogout() { const data = await getStorageJsonSync('loginData'); if (data && data.email) { delete data.password setStorageJson('loginData', data); setStorage('RegisterTokenDate', ""); } global.userInfo = {} /*this.setState({ isLogin: false, userInfo: {} });*/ setAccessToken(''); routeUtil.bridge2Page(PageList.login); } changeSecurety() { this.setState({ showPassword: !this.state.showPassword }) } render() { return ( Email Address { this.state.isChange ? : this.changeInfo('email', v)}/> } {/* Verification Code this.changeInfo('verificationCode', v)} />