Nav apraksta

LoginByVerificationCodeViewController.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /**
  2. * Created by zack on 2018/6/24.
  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. } from 'react-native'
  15. import React, {Component} from 'react'
  16. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../utils/DimensionsTools'
  17. import HttpTools from '../../network/HttpTools'
  18. import {signUpByEmail, signUpByPhone, userSmsCode, userEmailCode, userSmsCodeLogin} from '../../network/API'
  19. import ToastMsg from '../../utils/ToastMsg'
  20. import {GlobalUserStorageTool, UserStorageKey} from '../../utils/GlobalUserStorageTool'
  21. import BaseNavigationBarStyle from '../base/BaseNavigationBarStyle'
  22. export default class LoginByVerificationCodeViewController extends Component {
  23. constructor(props) {
  24. super(props)
  25. this.state = {
  26. account: '',
  27. verificationCode: '',
  28. password: '',
  29. phoneCode: '86',
  30. isEmailLoginType: false
  31. }
  32. }
  33. clickBackButton() {
  34. this.props.navigator.pop()
  35. }
  36. getVerificationCode() {
  37. console.log('smscode')
  38. if (!this.state.account.length) {
  39. if (this.state.isEmailLoginType) {
  40. ToastMsg.show('请输入您的邮箱')
  41. }else {
  42. ToastMsg.show('请输入您的手机号')
  43. }
  44. return;
  45. }
  46. let param
  47. let url = ''
  48. if (this.state.isEmailLoginType) {
  49. url = userEmailCode
  50. param = JSON.stringify({
  51. email: this.state.account,
  52. purpose: "login"
  53. })
  54. }else {
  55. url = userSmsCode
  56. param = JSON.stringify({
  57. phone: this.state.account,
  58. phone_code: this.state.phoneCode,
  59. purpose: "login"
  60. })
  61. }
  62. HttpTools.post(url, param, (response) => {
  63. ToastMsg.show('验证码发送成功')
  64. console.log(response)
  65. }, (error) => {
  66. console.warn(error)
  67. })
  68. }
  69. login() {
  70. if (!this.state.account.length) {
  71. if (this.state.isEmailLoginType) {
  72. ToastMsg.show('请输入您的邮箱')
  73. }else {
  74. ToastMsg.show('请输入您的手机号')
  75. }
  76. return;
  77. }
  78. if (!this.state.verificationCode.length) {
  79. ToastMsg.show('请输入您的验证码')
  80. return;
  81. }
  82. let param
  83. if (this.state.isEmailLoginType) {
  84. param = JSON.stringify({
  85. code: this.state.verificationCode,
  86. forget_me: true,
  87. email: this.state.account
  88. })
  89. }else {
  90. param = JSON.stringify({
  91. code: this.state.verificationCode,
  92. forget_me: true,
  93. phone: this.state.account
  94. })
  95. }
  96. HttpTools.post(userSmsCodeLogin, param, (response) => {
  97. if (response && response.token) {
  98. global.token = response.token
  99. GlobalUserStorageTool.save(UserStorageKey.UserInfo, response)
  100. this.props.navigator.pop()
  101. ToastMsg.show('登录成功')
  102. }else {
  103. ToastMsg.show('登录失败')
  104. }
  105. }, (error) => {
  106. ToastMsg.show('登录成功')
  107. })
  108. }
  109. goToCountCodeList() {
  110. this.props.navigator.push({
  111. screen: 'CountCodeListViewController',
  112. title: '国家和地区',
  113. backButtonTitle: '',
  114. passProps: {
  115. didSelectedItem: (phoneCode)=> {
  116. this.setState({phoneCode: phoneCode})
  117. }
  118. },
  119. navigatorStyle: BaseNavigationBarStyle
  120. })
  121. }
  122. didSelectedTag() {
  123. this.setState({isEmailLoginType: !this.state.isEmailLoginType})
  124. }
  125. loginWithAccount() {
  126. this.props.navigator.push({
  127. screen: 'LoginViewController',
  128. title: '',
  129. backButtonTitle: '',
  130. passProps: {
  131. },
  132. navigatorStyle: {
  133. navBarHidden: true
  134. }
  135. })
  136. }
  137. renderAccountView(isEmailLoginType) {
  138. if (!isEmailLoginType) {
  139. return(
  140. <View style={{width: ScreenDimensions.width - 30, height: 49, flexDirection: 'row', alignItems: 'center'}}>
  141. <TouchableOpacity onPress={() => {
  142. this.goToCountCodeList()
  143. }} style={{marginLeft: 0, width: 43, height: 47, justifyContent: 'center', }}>
  144. <Text style={{color: '#b8bcbf', fontSize: 14}}>{this.state.phoneCode}</Text>
  145. </TouchableOpacity>
  146. <View style={{width: 0.5, height: 21,backgroundColor: 'rgba(80, 80, 80, 0.36)'}}/>
  147. <TextInput
  148. onChangeText={(text) => {
  149. this.setState({account: text})
  150. }}
  151. keyboardType={'email-address'}
  152. placeholder={ '请输入手机号'} placeholderTextColor={'#b8bcbf'}
  153. style={[styles.AccountTextInput, {width: ScreenDimensions.width - 30 - 44, paddingLeft: 17}]}/>
  154. </View>
  155. )
  156. }else {
  157. return(
  158. <TextInput onChangeText={(text) => {
  159. this.setState({account: text})
  160. }} keyboardType={'email-address'} placeholder={'请输入邮箱'} placeholderTextColor={'#b8bcbf'} style={[styles.AccountTextInput, {width: ScreenDimensions.width - 30,}]}/>
  161. )
  162. }
  163. }
  164. render() {
  165. return(
  166. <View style={styles.View}>
  167. <View style={styles.NavigationBarBgView}>
  168. <View style={styles.NavigationBar}>
  169. <TouchableOpacity onPress={() => {
  170. this.clickBackButton()
  171. }} style={styles.BackImageView}>
  172. <Image source={require("../../resources/images/TabBar/Learn/btn_back.png")}/>
  173. </TouchableOpacity>
  174. <Image source={require('../../resources/images/LoginSignUp/logo.png')} style={styles.LogoImageView}/>
  175. </View>
  176. </View>
  177. <View style={styles.TagButtonView}>
  178. <TouchableOpacity onPress={() => {
  179. if (this.state.isEmailLoginType) {
  180. this.didSelectedTag()
  181. }
  182. }} style={[{marginRight: 92}]}>
  183. <Text style={this.state.isEmailLoginType === false ? styles.TagButtonTextSelected : styles.TagButtonTextNormal}>{'手机验证码'}</Text>
  184. </TouchableOpacity>
  185. <TouchableOpacity onPress={() => {
  186. if (!this.state.isEmailLoginType) {
  187. this.didSelectedTag()
  188. }
  189. }} style={styles.TagButtonText}>
  190. <Text style={this.state.isEmailLoginType === true ? styles.TagButtonTextSelected : styles.TagButtonTextNormal}>{'邮箱验证码'}</Text>
  191. </TouchableOpacity>
  192. </View>
  193. <View style={styles.AccountTextInputBgView}>
  194. {this.renderAccountView(this.state.isEmailLoginType)}
  195. <View style={styles.LineView}/>
  196. </View>
  197. <View style={styles.VerifyTextInputBgView}>
  198. <View style={styles.VerifyTextInputContainerView}>
  199. <TextInput onChangeText={(text) => {
  200. this.setState({verificationCode: text})
  201. }} keyboardType={'phone-pad'} placeholder={'请输入验证码'} placeholderTextColor={'#b8bcbf'} style={styles.VerifyTextInput}/>
  202. <TouchableOpacity onPress={() => {
  203. this.getVerificationCode()
  204. }} style={styles.VerifyButtonBgView}>
  205. <View style={styles.VerifyLineView}/>
  206. <Text style={styles.VerifyButtonText}>{'获取验证码'}</Text>
  207. </TouchableOpacity>
  208. </View>
  209. <View style={styles.LineView}/>
  210. </View>
  211. <TouchableOpacity onPress={() => {
  212. this.login()
  213. }} style = {styles.SignUpButton}>
  214. <Text style={styles.SignUpButtonText}>{'登录'}</Text>
  215. </TouchableOpacity>
  216. <View style={styles.BottomLoginAndSignUpBgView}>
  217. <TouchableOpacity onPress={() => {
  218. this.loginWithAccount()
  219. }}>
  220. <Text style={styles.AccountLoginText}>{'账号登录'}</Text>
  221. </TouchableOpacity>
  222. <TouchableOpacity onPress={() => {
  223. this.props.navigator.push({
  224. screen: 'SignUpViewController',
  225. title: '',
  226. backButtonTitle: '',
  227. passProps: {
  228. },
  229. navigatorStyle: {
  230. navBarHidden: true
  231. }
  232. })
  233. }}>
  234. <Text style={styles.SignUpText}>{'免费注册'}</Text>
  235. </TouchableOpacity>
  236. </View>
  237. <View style={styles.BottomSignUpView}>
  238. <View style={styles.VBgView}>
  239. <View style={[styles.VLineView, {marginLeft: 15,}]}/>
  240. <Text style={styles.VText}>{'使用其他方式登录'}</Text>
  241. <View style={styles.VLineView}/>
  242. <View />
  243. </View>
  244. <View style={styles.IconBgView}>
  245. <TouchableOpacity style={styles.IconView}>
  246. <Image source={require('../../resources/images/LoginSignUp/wechat.png')}/>
  247. </TouchableOpacity>
  248. <TouchableOpacity style={styles.IconView}>
  249. <Image source={require('../../resources/images/LoginSignUp/QQ.png')}/>
  250. </TouchableOpacity>
  251. <TouchableOpacity style={styles.IconView}>
  252. <Image source={require('../../resources/images/LoginSignUp/weibo.png')}/>
  253. </TouchableOpacity>
  254. <TouchableOpacity style={styles.IconView}>
  255. <Image source={require('../../resources/images/LoginSignUp/Facebook.png')}/>
  256. </TouchableOpacity>
  257. <TouchableOpacity style={styles.IconView}>
  258. <Image source={require('../../resources/images/LoginSignUp/twitter.png')}/>
  259. </TouchableOpacity>
  260. <TouchableOpacity style={styles.IconView}>
  261. <Image source={require('../../resources/images/LoginSignUp/Google.png')}/>
  262. </TouchableOpacity>
  263. </View>
  264. </View>
  265. </View>
  266. )
  267. }
  268. }
  269. const styles = StyleSheet.create({
  270. View: {
  271. width: ScreenDimensions.width,
  272. height: ScreenDimensions.height,
  273. backgroundColor: 'white'
  274. },
  275. NavigationBarBgView: {
  276. position: 'absolute',
  277. left: 0,
  278. top: 0,
  279. height: NavigationBarHeight.height,
  280. width: ScreenDimensions.width,
  281. backgroundColor: "#ffffff",
  282. shadowColor: "#eeeeee",
  283. shadowOffset: {
  284. width: 0,
  285. height: -1
  286. },
  287. shadowRadius: 0,
  288. shadowOpacity: 1,
  289. flexDirection: 'row',
  290. alignItems: 'center',
  291. justifyContent: 'space-between',
  292. elevation: 5, //only for android
  293. },
  294. NavigationBar: {
  295. position: 'absolute',
  296. left: 0,
  297. top: 0,
  298. height: NavigationBarHeight.height,
  299. width: ScreenDimensions.width,
  300. backgroundColor: "#ffffff",
  301. shadowColor: "#eeeeee",
  302. shadowOffset: {
  303. width: 0,
  304. height: -1
  305. },
  306. shadowRadius: 0,
  307. shadowOpacity: 1,
  308. flexDirection: 'row',
  309. alignItems: 'center',
  310. justifyContent: 'center',
  311. elevation: 5, //only for android
  312. },
  313. LogoImageView: {
  314. width: 80,
  315. height: 25,
  316. },
  317. BackImageView: {
  318. position: 'absolute',
  319. left: 15,
  320. top: (NavigationBarHeight.height - 15)/2.0
  321. },
  322. AccountTextInputBgView: {
  323. width: ScreenDimensions.width - 30,
  324. height: 50,
  325. marginLeft: 15,
  326. marginTop: 35
  327. },
  328. LineView: {
  329. width: ScreenDimensions.width - 30,
  330. backgroundColor: '#efeff4',
  331. height: 0.5,
  332. },
  333. AccountTextInput: {
  334. textAlign: 'left',
  335. fontSize: 14,
  336. color: '#4A4A4A',
  337. height:49,
  338. },
  339. VerifyTextInputBgView: {
  340. width: ScreenDimensions.width - 30,
  341. height: 50,
  342. marginLeft: 15,
  343. marginTop: 28
  344. },
  345. VerifyTextInputContainerView: {
  346. width: ScreenDimensions.width - 30,
  347. height: 49,
  348. flexDirection: 'row',
  349. alignItems: 'center',
  350. justifyContent: 'space-between'
  351. },
  352. VerifyTextInput: {
  353. width: ScreenDimensions.width - 30 - 100,
  354. textAlign: 'left',
  355. fontSize: 14,
  356. color: '#4A4A4A',
  357. height:49,
  358. },
  359. VerifyButtonBgView: {
  360. width: 100,
  361. flexDirection: 'row',
  362. alignItems: 'center',
  363. justifyContent: 'space-between',
  364. },
  365. VerifyButtonText: {
  366. fontSize: 14,
  367. color: '#5a9cd9',
  368. },
  369. VerifyLineView: {
  370. width: 1,
  371. height: 21,
  372. backgroundColor: 'rgba(80, 80, 80, 0.36)'
  373. },
  374. PasswordTextInputBgView: {
  375. width: ScreenDimensions.width - 30,
  376. height: 50,
  377. marginLeft: 15,
  378. marginTop: 28,
  379. },
  380. PasswordTextInput: {
  381. width: ScreenDimensions.width - 30,
  382. textAlign: 'left',
  383. fontSize: 14,
  384. color: '#4A4A4A',
  385. height:49,
  386. },
  387. SignUpButton: {
  388. width:ScreenDimensions.width - 30,
  389. height: 50,
  390. backgroundColor: '#e66a6a',
  391. justifyContent: 'center',
  392. alignItems: 'center',
  393. borderRadius: 5,
  394. marginTop: 26,
  395. marginLeft: 15,
  396. },
  397. SignUpButtonText: {
  398. fontSize: 16,
  399. color: '#ffffff'
  400. },
  401. LoginButtonBgView: {
  402. width: ScreenDimensions.width,
  403. justifyContent: 'center',
  404. alignItems: 'center',
  405. marginTop: 18
  406. },
  407. LoginButton: {
  408. },
  409. LoginText1: {
  410. fontSize: 14,
  411. color: '#909090'
  412. },
  413. LoginText2: {
  414. fontSize: 14,
  415. color: '#5a9cd9'
  416. },
  417. BottomSignUpView: {
  418. position: 'absolute',
  419. left: 0,
  420. bottom: 0,
  421. width: ScreenDimensions.width,
  422. height: 100,
  423. },
  424. VBgView: {
  425. flexDirection: 'row',
  426. alignItems: 'center',
  427. justifyContent: 'space-between',
  428. width: ScreenDimensions.width
  429. },
  430. VLineView: {
  431. width: (ScreenDimensions.width - 120 - 15*4)/2.0,
  432. height: 0.5,
  433. backgroundColor: '#e1e3e6'
  434. },
  435. VText: {
  436. fontSize: 14,
  437. color: '#8c8c8c',
  438. width: 120,
  439. textAlign: 'center'
  440. },
  441. IconBgView: {
  442. width: ScreenDimensions.width,
  443. height: 25,
  444. flexDirection: 'row',
  445. alignItems: 'center',
  446. justifyContent: 'space-around',
  447. marginTop: 32
  448. },
  449. IconView: {
  450. width: 25,
  451. height: 25,
  452. },
  453. TagButtonView: {
  454. width: ScreenDimensions.width,
  455. flexDirection: 'row',
  456. alignItems: 'center',
  457. justifyContent: 'center',
  458. marginTop: NavigationBarHeight.height + 40
  459. },
  460. TagButtonTextNormal: {
  461. fontSize: 16,
  462. color: '#505050',
  463. },
  464. TagButtonTextSelected: {
  465. fontSize: 16,
  466. color: '#5a9cd9',
  467. },
  468. BottomLoginAndSignUpBgView: {
  469. width: ScreenDimensions.width - 30,
  470. marginLeft: 15,
  471. marginTop: 23,
  472. flexDirection: 'row',
  473. justifyContent: 'space-between'
  474. },
  475. AccountLoginText: {
  476. fontSize: 13,
  477. color: '#979696',
  478. },
  479. SignUpText: {
  480. fontSize: 13,
  481. color: '#7dafe0',
  482. },
  483. })