forget_password.js 6.8 KB

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