ForgotPwdVL.js 10 KB

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