/** * 忘记密码-重置密码页面 * @邠心vbe on 2021/10/18 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, ScrollView, Image, TextInput } from 'react-native'; import apiUser from '../../api/apiUser'; import Button from '../../components/Button'; import Dialog from '../../components/Dialog'; import { BackIcon } from '../../components/Toolbar'; import { StrengthView } from './Register'; export default class ResetPassword extends Component { constructor(props) { super(props); this.state = { strength: 0, password: '', wrongCount: 0, sendMinutes: 0 }; this.formInfo = { email: '', password: '', verificationCode: '' } } componentWillUnmount() { this.setState({ sendMinutes: 0 }) } getBackTopPosition() { return isIOS ? statusHeight - 18 : 12; } changeInfo(key, value) { this.formInfo[key] = value; } applyStrength(text) { var strength = 0; if (text.length >= 8) { strength += 1; } if (/\d{1,}/.test(text)) { strength += 1; } if (/[A-z]{1,}/.test(text)) { strength += 1; } /*if (/[A-Z]{1,}/.test(text)) { strength += 1; } if (/\W{1,}/.test(text)) { strength += 1; }*/ if (this.state.strength != strength) { this.setState({ password: text, strength: strength }); } else { this.setState({ password: text }); } } sendVerification() { var info = this.formInfo; if (!info.email) { toastShort('Please enter email address'); return; } if (!/^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/.test(info.email)) { toastShort('Email is incorrect format'); return; } Dialog.showProgressDialog() apiUser.sendVerificationCode(info.email).then(res => { Dialog.dismissLoading() this.state.sendMinutes = 60; toastShort('Send verification code successfully'); 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('Please enter email address'); return; } if (!/^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/.test(info.email)) { toastShort('Email is incorrect format'); return; } if (!this.state.password) { toastShort('Please enter password'); return; } if (this.state.strength < 3) { toastShort('Password is not strong'); return; } if (!info.password) { toastShort('Please enter confirm password'); return; } if (info.password != this.state.password) { toastShort('The twice passwords are inconsistent'); return; } if (!info.verificationCode) { toastShort('Please enter verification code'); return; } Dialog.showProgressDialog() apiUser.updatePassword(this.formInfo).then(res => { Dialog.dismissLoading() toastShort('Reset password successfully'); goBack(); }).catch(err => { Dialog.dismissLoading() toastShort(err); }); } render() { return ( Reset Password Email Address this.changeInfo('email', v)} /> New Password { this.applyStrength(value); }} /> Password Strength Your Password Must Have: - 8 or more characters {/* - upper and lower case letters */} - at least one number Confirm Password this.changeInfo('password', v)} /> Verification Code this.changeInfo('verificationCode', v)} />