ForgotPwdVL.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /**
  2. * 忘记密码-重置密码LUMI版
  3. * @邠心vbe on 2024/06/05
  4. */
  5. import React, { Component } from 'react';
  6. import { View, ScrollView, StyleSheet, TextInput } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import Dialog from '../../components/Dialog';
  9. import TextView from '../../components/TextView';
  10. import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
  11. import utils from '../../utils/utils';
  12. import { PageList } from '../Router';
  13. export default class ForgotPwdVL extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. email: '',
  18. strength: 0,
  19. password: '',
  20. sendMinutes: 0,
  21. isChange: false,
  22. strengthCheck: {
  23. minLength: false,
  24. wordCase: false,
  25. oneNumber: false,
  26. allCheck: false
  27. },
  28. showPassword: false,
  29. confirmStatusColor: "#F5F5F5"
  30. };
  31. this.formInfo = {
  32. email: '',
  33. password: '',
  34. verificationCode: ''
  35. }
  36. }
  37. componentDidMount() {
  38. const action = this.props.route?.params?.action ?? "";
  39. if (action == "change") {
  40. this.setState({
  41. isChange: true
  42. });
  43. const email = userInfo.email;
  44. this.formInfo.email = email;
  45. this.setState({
  46. email: email
  47. });
  48. }
  49. }
  50. changeInfo(key, value) {
  51. this.formInfo[key] = value;
  52. }
  53. applyStrength(text) {
  54. const strength = this.state.strengthCheck;
  55. strength.allCheck = true;
  56. if (text.length >= 8) {
  57. strength.minLength = true;
  58. } else {
  59. strength.minLength = false;
  60. strength.allCheck = false;
  61. }
  62. if (/\d{1,}/.test(text)) {
  63. strength.oneNumber = true;
  64. } else {
  65. strength.oneNumber = false;
  66. strength.allCheck = false;
  67. }
  68. if (/[a-z]{1,}/.test(text) && /[A-Z]{1,}/.test(text)) {
  69. strength.wordCase = true;
  70. } else {
  71. strength.wordCase = false;
  72. strength.allCheck = false;
  73. }
  74. this.setState({
  75. password: text,
  76. strengthCheck: strength
  77. });
  78. }
  79. sendVerification() {
  80. var info = this.formInfo;
  81. if (!info.email) {
  82. toastShort($t('sign.plsInputEmail'));
  83. return;
  84. }
  85. if (!utils.isValidEmail(info.email)) {
  86. toastShort($t('sign.errEmailFormat'));
  87. return;
  88. }
  89. Dialog.showProgressDialog()
  90. apiUser.sendVerificationCode(info.email).then(res => {
  91. Dialog.dismissLoading()
  92. this.state.sendMinutes = res.data?.resendTime ?? 60;
  93. toastShort($t('sign.sendOTPSuccess'));
  94. this.contdownTime();
  95. }).catch(err => {
  96. Dialog.dismissLoading()
  97. toastShort(err);
  98. });
  99. }
  100. contdownTime() {
  101. if (this.state.sendMinutes > 0) {
  102. this.setState({
  103. sendMinutes: this.state.sendMinutes - 1
  104. })
  105. setTimeout(() => {
  106. this.contdownTime();
  107. }, 1000);
  108. }
  109. }
  110. onResetPassword() {
  111. var info = this.formInfo;
  112. console.log('reset info', info);
  113. if (!info.email) {
  114. toastShort($t('sign.plsInputEmail'));
  115. return;
  116. }
  117. if (!utils.isValidEmail(info.email)) {
  118. toastShort($t('sign.errEmailFormat'));
  119. return;
  120. }
  121. /*if (!info.verificationCode) {
  122. toastShort($t('sign.plsInputOTP'));
  123. return;
  124. }*/
  125. if (!this.state.password) {
  126. toastShort($t('sign.plsInputPassword'));
  127. return;
  128. }
  129. if (!this.state.strengthCheck.allCheck) {
  130. toastShort($t('sign.errPasswordStrong'));
  131. return;
  132. }
  133. if (!info.password) {
  134. toastShort($t('sign.plsInputPassword2'));
  135. return;
  136. }
  137. if (info.password != this.state.password) {
  138. toastShort($t('sign.errPasswordConfirm'));
  139. return;
  140. }
  141. Dialog.showProgressDialog()
  142. apiUser.updatePassword(this.formInfo).then(res => {
  143. Dialog.dismissLoading()
  144. toastShort($t('sign.resetPasswordSuccess'));
  145. if (this.isChange) {
  146. this.requestLogout();
  147. } else {
  148. goBack();
  149. }
  150. }).catch(err => {
  151. Dialog.dismissLoading()
  152. toastShort(err);
  153. });
  154. }
  155. async requestLogout() {
  156. const data = await getStorageJsonSync('loginData');
  157. if (data && data.email) {
  158. delete data.password
  159. setStorageJson('loginData', data);
  160. setStorage('RegisterTokenDate', "");
  161. }
  162. global.userInfo = {}
  163. /*this.setState({
  164. isLogin: false,
  165. userInfo: {}
  166. });*/
  167. setAccessToken('');
  168. routeUtil.bridge2Page(PageList.login);
  169. }
  170. changeSecurety() {
  171. this.setState({
  172. showPassword: !this.state.showPassword
  173. })
  174. }
  175. render() {
  176. return (
  177. <ScrollView
  178. style={styles.scollView}
  179. keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}>
  180. <View style={styles.resetView}>
  181. <TextView style={styles.inputLabel}>Email Address</TextView>
  182. <View style={styles.signInput}>
  183. { this.state.isChange
  184. ? <TextInput
  185. style={styles.inputView}
  186. placeholder={$t('sign.labelEmail')}
  187. placeholderTextColor={textPlacehoder}
  188. value={this.state.email}
  189. editable={false}
  190. maxLength={50}/>
  191. : <TextInput
  192. style={styles.inputView}
  193. placeholder={$t('sign.labelEmail')}
  194. placeholderTextColor={textPlacehoder}
  195. maxLength={50}
  196. keyboardType="email-address"
  197. textContentType='emailAddress'
  198. clearButtonMode='while-editing'
  199. onChangeText={v => this.changeInfo('email', v)}/>
  200. }
  201. </View>
  202. {/* <Text style={styles.inputLabel}>Verification Code</Text>
  203. <View style={ui.flexc}>
  204. <View style={[styles.signInput, ui.flex2]}>
  205. <TextInput
  206. style={[styles.inputView, {flex: 2.6, marginLeft: 2}]}
  207. placeholder={$t('sign.labelOtp')}
  208. placeholderTextColor={textPlacehoder}
  209. maxLength={6}
  210. keyboardType="number-pad"
  211. textContentType="telephoneNumber"
  212. onChangeText={v => this.changeInfo('verificationCode', v)}
  213. />
  214. </View>
  215. <Button
  216. text={this.state.sendMinutes > 0 ? (this.state.sendMinutes + " s") : $t('sign.btnSendOTP')}
  217. style={styles.sendBtn}
  218. disabled={this.state.sendMinutes > 0}
  219. viewStyle={styles.sendBtnView}
  220. textStyle={styles.sendBtnText}
  221. onClick={() => this.sendVerification()}/>
  222. </View> */}
  223. <TextView style={styles.inputLabel}>New Password</TextView>
  224. <View style={styles.signInput}>
  225. <TextInput
  226. secureTextEntry={!this.state.showPassword}
  227. style={styles.inputView}
  228. placeholder={$t('sign.labelNewPassword')}
  229. placeholderTextColor={textPlacehoder}
  230. maxLength={20}
  231. onChangeText={(value) => this.applyStrength(value)}/>
  232. <MaterialCommunityIcons
  233. name={this.state.showPassword ? "eye" : "eye-off"}
  234. size={16}
  235. color={"#DADADA"}
  236. onPress={() => this.changeSecurety()}/>
  237. </View>
  238. <View style={styles.passwordTipView}>
  239. <View style={ui.flexc}>
  240. <MaterialIcons
  241. name="check-circle-outline"
  242. color={this.state.strengthCheck.minLength ? colorAccent : colorCancel}
  243. size={18}/>
  244. <TextView style={styles.passwordTipText}>8 or more characters</TextView>
  245. </View>
  246. <View style={ui.flexc}>
  247. <MaterialIcons
  248. name="check-circle-outline"
  249. color={this.state.strengthCheck.wordCase ? colorAccent : colorCancel}
  250. size={18}/>
  251. <TextView style={styles.passwordTipText}>Upper and Lower case letters</TextView>
  252. </View>
  253. <View style={ui.flexc}>
  254. <MaterialIcons
  255. name="check-circle-outline"
  256. color={this.state.strengthCheck.oneNumber ? colorAccent : colorCancel}
  257. size={18}/>
  258. <TextView style={styles.passwordTipText}>At least one number</TextView>
  259. </View>
  260. </View>
  261. <TextView style={styles.inputLabel}>{$t('sign.labelConfirmPassword')}</TextView>
  262. <View style={styles.signInput}>
  263. <TextInput
  264. secureTextEntry={!this.state.showPassword}
  265. style={styles.inputView}
  266. placeholder={$t('sign.labelConfirmPassword')}
  267. placeholderTextColor={textPlacehoder}
  268. maxLength={20}
  269. onChangeText={v => this.changeInfo('password', v)}/>
  270. <MaterialCommunityIcons
  271. name={this.state.showPassword ? "eye" : "eye-off"}
  272. size={16}
  273. color={"#DADADA"}
  274. onPress={() => this.changeSecurety()}/>
  275. </View>
  276. <Button
  277. text={$t('common.confirm')}
  278. style={styles.resetButton}
  279. onClick={() => this.onResetPassword()}
  280. />
  281. </View>
  282. </ScrollView>
  283. );
  284. }
  285. }
  286. const styles = StyleSheet.create({
  287. scollView: {
  288. flex: 1,
  289. backgroundColor: colorLight
  290. },
  291. resetView: {
  292. padding: 16,
  293. backgroundColor: colorLight
  294. },
  295. inputLabel: {
  296. color: textPrimary,
  297. fontSize: 14,
  298. paddingBottom: 8
  299. },
  300. signInput: {
  301. marginBottom: 16,
  302. borderRadius: 0,
  303. paddingLeft: 16,
  304. paddingRight: 16,
  305. alignItems: 'center',
  306. flexDirection: 'row',
  307. borderWidth: 1,
  308. borderRadius: 4,
  309. borderColor: "#DADADA"
  310. },
  311. inputView: {
  312. flex: 1,
  313. height: 48,
  314. color: textPrimary,
  315. fontSize: 12
  316. },
  317. sendBtn: {
  318. flex: 1.2,
  319. marginLeft: 16,
  320. marginRight: 0,
  321. marginBottom: 16,
  322. borderRadius: 6,
  323. backgroundColor: colorPrimary
  324. },
  325. sendBtnView: {
  326. flex: 1,
  327. height: 48,
  328. paddingLeft: 4,
  329. paddingRight: 4,
  330. alignItems: 'center',
  331. justifyContent: 'center'
  332. },
  333. sendBtnText: {
  334. color: textButton,
  335. fontSize: 13,
  336. fontWeight: 'bold'
  337. },
  338. passwordTipView: {
  339. marginTop: -8,
  340. paddingBottom: 16
  341. },
  342. passwordTipText: {
  343. color: "#666",
  344. fontSize: 14,
  345. paddingTop: 2,
  346. paddingLeft: 8,
  347. paddingBottom: 2
  348. },
  349. resetButton: {
  350. marginTop: 32,
  351. marginBottom: 16,
  352. borderRadius: 4,
  353. backgroundColor: colorPrimary
  354. }
  355. })