ResetPasswordV2.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /**
  2. * 忘记密码-重置密码页面V2
  3. * @邠心vbe on 2022/12/23
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, ScrollView, Image, TextInput } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import Button from '../../components/Button';
  9. import Dialog from '../../components/Dialog';
  10. import { BackIcon } from '../../components/Toolbar';
  11. import { StrengthView } from './Register';
  12. export default class ResetPassword extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. strength: 0,
  17. password: '',
  18. wrongCount: 0,
  19. sendMinutes: 0
  20. };
  21. this.formInfo = {
  22. email: '',
  23. password: '',
  24. verificationCode: ''
  25. }
  26. }
  27. componentWillUnmount() {
  28. this.setState({
  29. sendMinutes: 0
  30. })
  31. }
  32. getBackTopPosition() {
  33. return isIOS ? statusHeight - 18 : 12;
  34. }
  35. changeInfo(key, value) {
  36. this.formInfo[key] = value;
  37. }
  38. applyStrength(text) {
  39. var strength = 0;
  40. if (text.length >= 8) {
  41. strength += 1;
  42. }
  43. if (/\d{1,}/.test(text)) {
  44. strength += 1;
  45. }
  46. if (/[A-z]{1,}/.test(text)) {
  47. strength += 1;
  48. }
  49. /*if (/[A-Z]{1,}/.test(text)) {
  50. strength += 1;
  51. }
  52. if (/\W{1,}/.test(text)) {
  53. strength += 1;
  54. }*/
  55. if (this.state.strength != strength) {
  56. this.setState({
  57. password: text,
  58. strength: strength
  59. });
  60. } else {
  61. this.setState({
  62. password: text
  63. });
  64. }
  65. }
  66. sendVerification() {
  67. var info = this.formInfo;
  68. if (!info.email) {
  69. toastShort('Please enter email address');
  70. return;
  71. }
  72. if (!/^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/.test(info.email)) {
  73. toastShort('Email is incorrect format');
  74. return;
  75. }
  76. Dialog.showProgressDialog()
  77. apiUser.sendVerificationCode(info.email).then(res => {
  78. Dialog.dismissLoading()
  79. this.state.sendMinutes = 60;
  80. toastShort('Send verification code successfully');
  81. this.contdownTime();
  82. }).catch(err => {
  83. Dialog.dismissLoading()
  84. toastShort(err);
  85. });
  86. }
  87. contdownTime() {
  88. if (this.state.sendMinutes > 0) {
  89. this.setState({
  90. sendMinutes: this.state.sendMinutes - 1
  91. })
  92. setTimeout(() => {
  93. this.contdownTime();
  94. }, 1000);
  95. }
  96. }
  97. onResetPassword() {
  98. var info = this.formInfo;
  99. console.log('reset info', info);
  100. if (!info.email) {
  101. toastShort('Please enter email address');
  102. return;
  103. }
  104. if (!/^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/.test(info.email)) {
  105. toastShort('Email is incorrect format');
  106. return;
  107. }
  108. if (!this.state.password) {
  109. toastShort('Please enter password');
  110. return;
  111. }
  112. if (this.state.strength < 3) {
  113. toastShort('Password is not strong');
  114. return;
  115. }
  116. if (!info.password) {
  117. toastShort('Please enter confirm password');
  118. return;
  119. }
  120. if (info.password != this.state.password) {
  121. toastShort('The twice passwords are inconsistent');
  122. return;
  123. }
  124. if (!info.verificationCode) {
  125. toastShort('Please enter verification code');
  126. return;
  127. }
  128. Dialog.showProgressDialog()
  129. apiUser.updatePassword(this.formInfo).then(res => {
  130. Dialog.dismissLoading()
  131. toastShort('Reset password successfully');
  132. goBack();
  133. }).catch(err => {
  134. Dialog.dismissLoading()
  135. toastShort(err);
  136. });
  137. }
  138. render() {
  139. return (
  140. <View style={StyleSheet.absoluteFillObject}>
  141. <ScrollView
  142. style={styles.scollView}
  143. keyboardShouldPersistTaps={'handled'}>
  144. <View style={styles.header}>
  145. <View style={styles.logoView}>
  146. {/* <Image
  147. style={styles.logoImg}
  148. source={require('../../images/tool-logo.png')}/> */}
  149. </View>
  150. </View>
  151. <View style={{...styles.backView, top: this.getBackTopPosition()}}>
  152. <Button
  153. style={styles.backButton}
  154. viewStyle={styles.backButtonView}
  155. onClick={() => goBack()}>
  156. <BackIcon/>
  157. <Text style={{color: '#333',fontSize: 16,paddingLeft: 8}}>Back to Login</Text>
  158. </Button>
  159. </View>
  160. <View style={styles.resetView}>
  161. <Text style={styles.title}>Reset Password</Text>
  162. <View style={styles.signInput}>
  163. <Text style={styles.inputLabel}>Email Address</Text>
  164. <TextInput
  165. style={styles.inputView}
  166. placeholder='Email Address'
  167. maxLength={50}
  168. onChangeText={v => this.changeInfo('email', v)}
  169. />
  170. </View>
  171. <View style={styles.signInput}>
  172. <Text style={styles.inputLabel}>New Password</Text>
  173. <TextInput
  174. secureTextEntry={this.state.wrongCount < 3}
  175. style={styles.inputView}
  176. placeholder='Password'
  177. maxLength={20}
  178. onChangeText={(value) => {
  179. this.applyStrength(value);
  180. }}
  181. />
  182. </View>
  183. <View style={styles.signInput}>
  184. <Text style={styles.inputLabel}></Text>
  185. <View style={styles.passwordView}>
  186. <View style={styles.strengthView}>
  187. <Text style={{fontSize:12, paddingRight: 4, color: '#333'}}>Password Strength</Text>
  188. <StrengthView {...this.state}/>
  189. </View>
  190. <View>
  191. <Text style={styles.passwordRole}>Your Password Must Have:</Text>
  192. <Text style={styles.passwordRole}>- 8 or more characters</Text>
  193. {/* <Text style={styles.passwordRole}>- upper and lower case letters</Text> */}
  194. <Text style={styles.passwordRole}>- at least one number</Text>
  195. </View>
  196. </View>
  197. </View>
  198. <View style={styles.signInput}>
  199. <Text style={styles.inputLabel}>Confirm Password</Text>
  200. <TextInput
  201. secureTextEntry={this.state.wrongCount < 3}
  202. style={styles.inputView}
  203. placeholder='Password'
  204. maxLength={20}
  205. onChangeText={v => this.changeInfo('password', v)}
  206. />
  207. </View>
  208. <View style={styles.signInput}>
  209. <Text style={[styles.inputLabel, ui.flex2]}>Verification Code</Text>
  210. <TextInput
  211. style={[styles.inputView, {flex: 2.6, marginLeft: 2}]}
  212. placeholder='Verification Code'
  213. maxLength={6}
  214. onChangeText={v => this.changeInfo('verificationCode', v)}
  215. />
  216. <Button
  217. text={this.state.sendMinutes > 0 ? this.state.sendMinutes : 'Get Code'}
  218. style={styles.sendBtn}
  219. disabled={this.state.sendMinutes > 0}
  220. viewStyle={styles.sendBtnView}
  221. textStyle={styles.sendBtnText}
  222. onClick={() => this.sendVerification()}
  223. />
  224. </View>
  225. </View>
  226. <Text style={styles.divideText}>We will send you an email with the verification code.</Text>
  227. <Button
  228. text='Reset Password'
  229. style={styles.resetButton}
  230. onClick={() => this.onResetPassword()}
  231. />
  232. </ScrollView>
  233. </View>
  234. );
  235. }
  236. }
  237. const styles = StyleSheet.create({
  238. header: {
  239. paddingTop: 56,
  240. backgroundColor: colorThemes
  241. },
  242. backView: {
  243. top: 12,
  244. zIndex: 5,
  245. padding: 16,
  246. position: 'absolute',
  247. flexDirection: 'row'
  248. },
  249. backButton: {
  250. borderRadius: 60,
  251. backgroundColor: 'white'
  252. },
  253. backButtonView: {
  254. height: 43,
  255. paddingLeft: 16,
  256. paddingRight: 16,
  257. alignItems: 'center',
  258. flexDirection: 'row'
  259. },
  260. scollView: {
  261. flex: 1,
  262. backgroundColor: 'white'
  263. },
  264. logoView: {
  265. paddingTop: 40,
  266. paddingBottom: 56,
  267. alignItems: 'center'
  268. },
  269. logoImg: {
  270. width:165.09,
  271. height: 51.94,
  272. },
  273. resetView: {
  274. flex: 1,
  275. padding: 16,
  276. marginTop: -30,
  277. borderTopLeftRadius: 20,
  278. borderTopRightRadius: 20,
  279. backgroundColor: 'white'
  280. },
  281. title: {
  282. color: '#333',
  283. fontSize: 18,
  284. fontWeight: '700',
  285. paddingTop: 4,
  286. paddingBottom: 6,
  287. },
  288. signInput: {
  289. marginTop: 16,
  290. alignItems: 'center',
  291. flexDirection: 'row'
  292. },
  293. inputLabel: {
  294. flex: 1,
  295. color: '#333',
  296. fontSize: 14
  297. },
  298. inputView: {
  299. flex: 2,
  300. color: '#333',
  301. fontSize: 14,
  302. borderRadius: 5,
  303. minHeight: 40,
  304. paddingTop: 6,
  305. paddingLeft: 12,
  306. paddingRight: 12,
  307. paddingBottom: 6,
  308. backgroundColor: '#F5F5F5'
  309. },
  310. passwordView: {
  311. flex: 2,
  312. marginTop: -8,
  313. },
  314. strengthView: {
  315. marginTop: -4,
  316. alignItems: 'center',
  317. paddingBottom: 4,
  318. flexDirection: 'row'
  319. },
  320. passwordRole: {
  321. color: '#999',
  322. fontSize: 10,
  323. lineHeight: 13
  324. },
  325. sendBtn: {
  326. flex: 1.4,
  327. marginLeft: 6
  328. },
  329. sendBtnView: {
  330. flex: 1,
  331. height: 40,
  332. paddingLeft: 4,
  333. paddingRight: 4,
  334. alignItems: 'center',
  335. justifyContent: 'center'
  336. },
  337. sendBtnText: {
  338. color: '#fff',
  339. fontSize: 13,
  340. fontWeight: 'bold'
  341. },
  342. divideText: {
  343. color: '#333',
  344. fontSize: 14,
  345. padding: 58,
  346. textAlign: 'center'
  347. },
  348. resetButton: {
  349. margin: 16
  350. }
  351. })