No Description

ForgotPasswordViewController.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /**
  2. * Created by zack on 2018/6/28.
  3. */
  4. /**
  5. * Created by zack on 2018/6/19.
  6. */
  7. import {
  8. View,
  9. Text,
  10. StyleSheet,
  11. TouchableOpacity,
  12. Platform,
  13. Image,TextInput,
  14. Alert
  15. } from 'react-native'
  16. import React, {Component} from 'react'
  17. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../utils/DimensionsTools'
  18. import HttpTools from '../../network/HttpTools'
  19. import {signUpByEmail, signUpByPhone, userSmsCode, userEmailCode, userPassword} from '../../network/API'
  20. import ToastMsg from '../../utils/ToastMsg'
  21. import {GlobalUserStorageTool, UserStorageKey} from '../../utils/GlobalUserStorageTool'
  22. import BaseNavigationBarStyle from '../base/BaseNavigationBarStyle'
  23. export default class ForgotPasswordViewController extends Component {
  24. constructor(props) {
  25. super(props)
  26. this.state = {
  27. account: '',
  28. verificationCode: '',
  29. password: '',
  30. phoneCode: '86',
  31. isEmailLoginType: false
  32. }
  33. }
  34. clickBackButton() {
  35. this.props.navigator.pop()
  36. }
  37. resetPassword() {
  38. if (!this.state.account.length) {
  39. ToastMsg.show("请输入您的" + this.state.isEmailLoginType === true ? '邮箱' : '手机号');
  40. return
  41. }
  42. if (!this.state.verificationCode.length) {
  43. ToastMsg.show("请输入您的验证码");
  44. return
  45. }
  46. if (!this.state.password.length) {
  47. ToastMsg.show("请输入您的密码");
  48. return
  49. }
  50. if (this.state.password.length < 6) {
  51. ToastMsg.show("密码长度不能少于6位");
  52. return
  53. }
  54. const param = JSON.stringify({
  55. code: this.state.verificationCode,
  56. password: this.state.password,
  57. username: this.state.account
  58. })
  59. HttpTools.put(userPassword, param, (response) => {
  60. if (response && response.token) { //sign up ok
  61. //充值密码成功,
  62. GlobalUserStorageTool.save(UserStorageKey.AccountAndPassword, {account: this.state.account, password: this.state.password})
  63. Alert.alert(
  64. '修改成功',
  65. '',
  66. [
  67. {text: 'OK', onPress: () => {
  68. this.props.navigator.pop()
  69. }},
  70. ],
  71. { cancelable: false }
  72. )
  73. }else {
  74. ToastMsg.show(response && response.msg)
  75. }
  76. }, (error) => {
  77. })
  78. }
  79. didSelectedTag() {
  80. this.setState({isEmailLoginType: !this.state.isEmailLoginType})
  81. }
  82. goToCountCodeList() {
  83. this.props.navigator.push({
  84. screen: 'CountCodeListViewController',
  85. title: '国家和地区',
  86. backButtonTitle: '',
  87. passProps: {
  88. didSelectedItem: (phoneCode)=> {
  89. this.setState({phoneCode: phoneCode})
  90. }
  91. },
  92. navigatorStyle: BaseNavigationBarStyle
  93. })
  94. }
  95. getVerificationCode() {
  96. let param
  97. let url = ''
  98. if (this.state.isEmailLoginType) {
  99. url = userEmailCode
  100. param = JSON.stringify({
  101. email: this.state.account,
  102. purpose: "change_password"
  103. })
  104. }else {
  105. url = userSmsCode
  106. param = JSON.stringify({
  107. phone: this.state.account,
  108. phone_code: this.state.phoneCode,
  109. purpose: "change_password"
  110. })
  111. }
  112. HttpTools.post(url, param, (response) => {
  113. ToastMsg.show('短信验证码已经发送到您的' + this.state.isEmailLoginType === true ? '邮箱' : '手机号')
  114. }, (error) => {
  115. })
  116. }
  117. renderAccountView(isEmailLoginType) {
  118. if (!isEmailLoginType) {
  119. return(
  120. <View style={{width: ScreenDimensions.width - 30, height: 49, flexDirection: 'row', alignItems: 'center'}}>
  121. <TouchableOpacity onPress={() => {
  122. this.goToCountCodeList()
  123. }} style={{marginLeft: 0, width: 43, height: 47, justifyContent: 'center', }}>
  124. <Text style={{color: '#b8bcbf', fontSize: 14}}>{this.state.phoneCode}</Text>
  125. </TouchableOpacity>
  126. <View style={{width: 0.5, height: 21,backgroundColor: 'rgba(80, 80, 80, 0.36)'}}/>
  127. <TextInput
  128. onChangeText={(text) => {
  129. this.setState({account: text})
  130. }}
  131. keyboardType={'email-address'}
  132. placeholder={ '请输入手机号'} placeholderTextColor={'#b8bcbf'}
  133. style={[styles.AccountTextInput, {width: ScreenDimensions.width - 30 - 44, paddingLeft: 17}]}/>
  134. </View>
  135. )
  136. }else {
  137. return(
  138. <TextInput onChangeText={(text) => {
  139. this.setState({account: text})
  140. }} keyboardType={'email-address'} placeholder={'请输入邮箱'} placeholderTextColor={'#b8bcbf'} style={[styles.AccountTextInput, {width: ScreenDimensions.width - 30,}]}/>
  141. )
  142. }
  143. }
  144. render() {
  145. return(
  146. <View style={styles.View}>
  147. <View style={styles.NavigationBarBgView}>
  148. <View style={styles.NavigationBar}>
  149. <TouchableOpacity onPress={() => {
  150. this.clickBackButton()
  151. }} style={styles.BackImageView}>
  152. <Image source={require("../../resources/images/TabBar/Learn/btn_back.png")}/>
  153. </TouchableOpacity>
  154. <Image source={require('../../resources/images/LoginSignUp/logo.png')} style={styles.LogoImageView}/>
  155. </View>
  156. </View>
  157. <View style={styles.TagButtonView}>
  158. <TouchableOpacity onPress={() => {
  159. if (this.state.isEmailLoginType) {
  160. this.didSelectedTag()
  161. }
  162. }} style={[{marginRight: 92}]}>
  163. <Text style={this.state.isEmailLoginType === false ? styles.TagButtonTextSelected : styles.TagButtonTextNormal}>{'手机找回'}</Text>
  164. </TouchableOpacity>
  165. <TouchableOpacity onPress={() => {
  166. if (!this.state.isEmailLoginType) {
  167. this.didSelectedTag()
  168. }
  169. }} style={styles.TagButtonText}>
  170. <Text style={this.state.isEmailLoginType === true ? styles.TagButtonTextSelected : styles.TagButtonTextNormal}>{'邮箱找回'}</Text>
  171. </TouchableOpacity>
  172. </View>
  173. <View style={styles.AccountTextInputBgView}>
  174. {this.renderAccountView(this.state.isEmailLoginType)}
  175. <View style={styles.LineView}/>
  176. </View>
  177. <View style={styles.VerifyTextInputBgView}>
  178. <View style={styles.VerifyTextInputContainerView}>
  179. <TextInput onChangeText={(text) => {
  180. this.setState({verificationCode: text})
  181. }} keyboardType={'phone-pad'} placeholder={'请输入验证码'} placeholderTextColor={'#b8bcbf'} style={styles.VerifyTextInput}/>
  182. <TouchableOpacity onPress={() => {
  183. this.getVerificationCode()
  184. }} style={styles.VerifyButtonBgView}>
  185. <View style={styles.VerifyLineView}/>
  186. <Text style={styles.VerifyButtonText}>{'获取验证码'}</Text>
  187. </TouchableOpacity>
  188. </View>
  189. <View style={styles.LineView}/>
  190. </View>
  191. <View style={styles.PasswordTextInputBgView}>
  192. <TextInput onChangeText={(text) => {
  193. this.setState({password: text})
  194. }} secureTextEntry={true} placeholder={'请输入您的新密码'} placeholderTextColor={'#b8bcbf'} style={styles.PasswordTextInput}/>
  195. <View style={styles.LineView}/>
  196. </View>
  197. <TouchableOpacity onPress={() => {
  198. this.signUp()
  199. }} style = {styles.SignUpButton}>
  200. <Text style={styles.SignUpButtonText}>{'注册'}</Text>
  201. </TouchableOpacity>
  202. </View>
  203. )
  204. }
  205. }
  206. const styles = StyleSheet.create({
  207. View: {
  208. width: ScreenDimensions.width,
  209. height: ScreenDimensions.height,
  210. backgroundColor: 'white'
  211. },
  212. NavigationBarBgView: {
  213. position: 'absolute',
  214. left: 0,
  215. top: 0,
  216. height: NavigationBarHeight.height,
  217. width: ScreenDimensions.width,
  218. backgroundColor: "#ffffff",
  219. shadowColor: "#eeeeee",
  220. shadowOffset: {
  221. width: 0,
  222. height: -1
  223. },
  224. shadowRadius: 0,
  225. shadowOpacity: 1,
  226. flexDirection: 'row',
  227. alignItems: 'center',
  228. justifyContent: 'space-between',
  229. elevation: 5, //only for android
  230. },
  231. NavigationBar: {
  232. position: 'absolute',
  233. left: 0,
  234. top: 0,
  235. height: NavigationBarHeight.height,
  236. width: ScreenDimensions.width,
  237. backgroundColor: "#ffffff",
  238. shadowColor: "#eeeeee",
  239. shadowOffset: {
  240. width: 0,
  241. height: -1
  242. },
  243. shadowRadius: 0,
  244. shadowOpacity: 1,
  245. flexDirection: 'row',
  246. alignItems: 'center',
  247. justifyContent: 'center',
  248. elevation: 5, //only for android
  249. },
  250. LogoImageView: {
  251. width: 80,
  252. height: 25,
  253. },
  254. BackImageView: {
  255. position: 'absolute',
  256. left: 15,
  257. top: (NavigationBarHeight.height - 15)/2.0
  258. },
  259. AccountTextInputBgView: {
  260. width: ScreenDimensions.width - 30,
  261. height: 50,
  262. marginLeft: 15,
  263. marginTop: 35
  264. },
  265. LineView: {
  266. width: ScreenDimensions.width - 30,
  267. backgroundColor: '#efeff4',
  268. height: 0.5,
  269. },
  270. AccountTextInput: {
  271. textAlign: 'left',
  272. fontSize: 14,
  273. color: '#4A4A4A',
  274. height:49,
  275. },
  276. VerifyTextInputBgView: {
  277. width: ScreenDimensions.width - 30,
  278. height: 50,
  279. marginLeft: 15,
  280. marginTop: 28
  281. },
  282. VerifyTextInputContainerView: {
  283. width: ScreenDimensions.width - 30,
  284. height: 49,
  285. flexDirection: 'row',
  286. alignItems: 'center',
  287. justifyContent: 'space-between'
  288. },
  289. VerifyTextInput: {
  290. width: ScreenDimensions.width - 30 - 100,
  291. textAlign: 'left',
  292. fontSize: 14,
  293. color: '#4A4A4A',
  294. height:49,
  295. },
  296. VerifyButtonBgView: {
  297. width: 100,
  298. flexDirection: 'row',
  299. alignItems: 'center',
  300. justifyContent: 'space-between',
  301. },
  302. VerifyButtonText: {
  303. fontSize: 14,
  304. color: '#5a9cd9',
  305. },
  306. VerifyLineView: {
  307. width: 1,
  308. height: 21,
  309. backgroundColor: 'rgba(80, 80, 80, 0.36)'
  310. },
  311. PasswordTextInputBgView: {
  312. width: ScreenDimensions.width - 30,
  313. height: 50,
  314. marginLeft: 15,
  315. marginTop: 28,
  316. },
  317. PasswordTextInput: {
  318. width: ScreenDimensions.width - 30,
  319. textAlign: 'left',
  320. fontSize: 14,
  321. color: '#4A4A4A',
  322. height:49,
  323. },
  324. SignUpButton: {
  325. width:ScreenDimensions.width - 30,
  326. height: 50,
  327. backgroundColor: '#e66a6a',
  328. justifyContent: 'center',
  329. alignItems: 'center',
  330. borderRadius: 5,
  331. marginTop: 26,
  332. marginLeft: 15,
  333. },
  334. SignUpButtonText: {
  335. fontSize: 16,
  336. color: '#ffffff'
  337. },
  338. LoginButtonBgView: {
  339. width: ScreenDimensions.width,
  340. justifyContent: 'center',
  341. alignItems: 'center',
  342. marginTop: 18
  343. },
  344. LoginButton: {
  345. },
  346. LoginText1: {
  347. fontSize: 14,
  348. color: '#909090'
  349. },
  350. LoginText2: {
  351. fontSize: 14,
  352. color: '#5a9cd9'
  353. },
  354. BottomSignUpView: {
  355. position: 'absolute',
  356. left: 0,
  357. bottom: 0,
  358. width: ScreenDimensions.width,
  359. height: 100,
  360. },
  361. VBgView: {
  362. flexDirection: 'row',
  363. alignItems: 'center',
  364. justifyContent: 'space-between',
  365. width: ScreenDimensions.width
  366. },
  367. VLineView: {
  368. width: (ScreenDimensions.width - 120 - 15*4)/2.0,
  369. height: 0.5,
  370. backgroundColor: '#e1e3e6'
  371. },
  372. VText: {
  373. fontSize: 14,
  374. color: '#8c8c8c',
  375. width: 120,
  376. textAlign: 'center'
  377. },
  378. IconBgView: {
  379. width: ScreenDimensions.width,
  380. height: 25,
  381. flexDirection: 'row',
  382. alignItems: 'center',
  383. justifyContent: 'space-around',
  384. marginTop: 32
  385. },
  386. IconView: {
  387. width: 25,
  388. height: 25,
  389. },
  390. TagButtonView: {
  391. width: ScreenDimensions.width,
  392. flexDirection: 'row',
  393. alignItems: 'center',
  394. justifyContent: 'center',
  395. marginTop: NavigationBarHeight.height + 40
  396. },
  397. TagButtonTextNormal: {
  398. fontSize: 16,
  399. color: '#505050',
  400. },
  401. TagButtonTextSelected: {
  402. fontSize: 16,
  403. color: '#5a9cd9',
  404. },
  405. })