forget_password.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. TextInput,
  6. TouchableOpacity,
  7. Image,
  8. ScrollView,
  9. } from 'react-native';
  10. import login_css from './login_css';
  11. import public_css from '../../source/css/public_css';
  12. import {CheckPassword, CheckPhoneNumber} from '../../source/inspect/inspect';
  13. import {RequestNetwork} from '../../data/encryption';
  14. import {ToastShow} from '../../components/toast/toast';
  15. import {WhiteSpace, WingBlank} from '@ant-design/react-native';
  16. export default class forget_password extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.afterEnd = this._afterEnd;
  20. this.state = {
  21. phone: '',
  22. user_password: '',
  23. user_password_again: '',
  24. verification_code: '',
  25. token: '',
  26. timeLeft: 60,
  27. begin: 0,
  28. isDisable: false,
  29. };
  30. }
  31. render() {
  32. return (
  33. <View style={[public_css.body]}>
  34. <View style={public_css.body}>
  35. <View style={login_css.bg}>
  36. <View style={login_css.login_bg_img}>
  37. <Image
  38. source={require('../../source/img/login/login_bg.png')}
  39. style={login_css.bgImg}
  40. resizeMode="cover"
  41. />
  42. </View>
  43. <View style={login_css.full_box}>
  44. <ScrollView style={login_css.inner_con}>
  45. <WhiteSpace />
  46. <WingBlank>
  47. <View style={login_css.input_item}>
  48. <Text style={login_css.text_label}>手机号</Text>
  49. <TextInput
  50. style={login_css.text_input}
  51. placeholder="请输入您的手机号码"
  52. clearButtonMode="while-editing"
  53. secureTextEntry={false}
  54. onChangeText={(text) => {
  55. this.setState({
  56. phone: text,
  57. });
  58. }}
  59. />
  60. </View>
  61. </WingBlank>
  62. <WingBlank>
  63. <View style={login_css.input_item}>
  64. <Text style={login_css.text_label}>密码</Text>
  65. <TextInput
  66. style={login_css.text_input}
  67. placeholder="请输入您的密码"
  68. clearButtonMode="while-editing"
  69. secureTextEntry
  70. onChangeText={(text) => {
  71. this.setState({
  72. user_password: text,
  73. });
  74. }}
  75. />
  76. </View>
  77. </WingBlank>
  78. <WingBlank>
  79. <View style={login_css.input_item}>
  80. <Text style={login_css.text_label}>确认密码</Text>
  81. <TextInput
  82. style={login_css.text_input}
  83. placeholder="再次输入您的密码"
  84. clearButtonMode="while-editing"
  85. secureTextEntry
  86. onChangeText={(text) => {
  87. this.setState({
  88. user_password_again: text,
  89. });
  90. }}
  91. />
  92. </View>
  93. </WingBlank>
  94. <WingBlank>
  95. <View style={login_css.input_item}>
  96. <Text style={login_css.text_label}>验证码</Text>
  97. <TextInput
  98. style={login_css.text_input}
  99. placeholder="请输入您的短信验证码"
  100. clearButtonMode="while-editing"
  101. onChangeText={(text) => {
  102. this.setState({
  103. verification_code: text,
  104. });
  105. }}
  106. />
  107. <TouchableOpacity
  108. style={login_css.vertify}
  109. disabled={this.state.isDisable}
  110. onPress={this._beginCountDown.bind(this)}>
  111. <Text style={login_css.texts}>
  112. {this.state.begin === 0
  113. ? '获取验证码'
  114. : this.state.timeLeft + '秒后重试'}
  115. </Text>
  116. </TouchableOpacity>
  117. </View>
  118. </WingBlank>
  119. <TouchableOpacity
  120. style={login_css.button}
  121. onPress={() => this.verificationCode()}>
  122. <View style={login_css.buttonView}>
  123. <Text style={login_css.buttonText}>修改密码</Text>
  124. </View>
  125. </TouchableOpacity>
  126. <WhiteSpace />
  127. <WhiteSpace />
  128. <WhiteSpace />
  129. <WhiteSpace />
  130. </ScrollView>
  131. </View>
  132. </View>
  133. </View>
  134. </View>
  135. );
  136. }
  137. //开始验证码计时
  138. _beginCountDown() {
  139. if (this.state.begin === 1) {
  140. return;
  141. }
  142. let time = this.state.timeLeft;
  143. let afterEnd = this.afterEnd;
  144. let begin = this.state.begin;
  145. this.countDownInfo(time, afterEnd, begin);
  146. this.sendVerificationCode();
  147. }
  148. //更新验证码状态
  149. countDownInfo(time, callback, begin) {
  150. if (time > 0) {
  151. this.state.begin = 1;
  152. let that = this;
  153. let interval = setInterval(function () {
  154. if (that.state.timeLeft < 1) {
  155. clearInterval(interval);
  156. callback(that);
  157. that.setState({
  158. isDisable: false,
  159. });
  160. } else {
  161. let totalTime = that.state.timeLeft;
  162. that.setState({
  163. timeLeft: totalTime - 1,
  164. isDisable: true,
  165. });
  166. }
  167. }, 1000);
  168. }
  169. }
  170. //提交登录信息
  171. sendVerificationCode = async () => {
  172. let {status, msg} = CheckPhoneNumber(`${this.state.phone}`);
  173. if (status) {
  174. const url = '/sms/getSmscode';
  175. let token = null;
  176. let response = await RequestNetwork(
  177. url,
  178. token,
  179. {
  180. phoneNo: this.state.phone,
  181. },
  182. false,
  183. 1,
  184. );
  185. if (response) {
  186. ToastShow(1, '验证码发送成功!');
  187. } else {
  188. ToastShow(1, '验证码发送失败!');
  189. }
  190. } else {
  191. ToastShow(1, msg);
  192. }
  193. };
  194. //验证短信验证码是否正确
  195. verificationCode = async () => {
  196. if (this.state.verification_code == '') {
  197. ToastShow(1, '验证码不能为空!');
  198. return;
  199. }
  200. let {status, msg} = CheckPhoneNumber(`${this.state.user_name}`);
  201. if (status) {
  202. let {status, msg} = CheckPassword(`${this.state.user_password}`);
  203. if (status) {
  204. let {status, msg} = CheckPassword(`${this.state.user_password_again}`);
  205. if (status) {
  206. const url = '/sms/matchSmscode';
  207. let token = null;
  208. let response = await RequestNetwork(
  209. url,
  210. token,
  211. {
  212. phoneNo: this.state.phone,
  213. smscode: this.state.verification_code,
  214. },
  215. false,
  216. 1,
  217. );
  218. if (response) {
  219. this.submitData();
  220. } else {
  221. ToastShow(1, '验证码不正确!');
  222. }
  223. } else {
  224. ToastShow(1, msg);
  225. }
  226. } else {
  227. ToastShow(1, msg);
  228. }
  229. } else {
  230. ToastShow(1, msg);
  231. }
  232. };
  233. //提交修改密码数据
  234. submitData = async () => {
  235. const url = '/auth/comm/user/forgotpwd';
  236. let token = null;
  237. let response = await RequestNetwork(
  238. url,
  239. token,
  240. {
  241. mobile: this.state.phone,
  242. password: this.state.user_password,
  243. confirmPassword: this.state.user_password_again,
  244. smsCode: this.state.verification_code,
  245. reqChannel: 3,
  246. },
  247. false,
  248. 1,
  249. );
  250. if (response) {
  251. // setInterval(() => {
  252. // this.setState({
  253. // spinner: isLoading,
  254. // });
  255. // }, 3000);
  256. ToastShow(1, '修改密码成功!');
  257. } else {
  258. ToastShow(1, '忘记密码失败,请重试!');
  259. }
  260. };
  261. }