Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. import React, { Component } from 'react';
  2.  
  3. // Components
  4. import AuthShared from '../auth_shared';
  5.  
  6. export default class Login extends Component {
  7.  
  8. render() {
  9. return (
  10. <AuthShared login={true}/>
  11. );
  12. }
  13. }
  14.  
  15. import React, { Component } from 'react';
  16.  
  17. // Components
  18. import AuthShared from '../auth_shared';
  19.  
  20. export default class SignUp extends Component {
  21.  
  22. render() {
  23. return (
  24. <AuthShared login={false}/>
  25. );
  26. }
  27. }
  28.  
  29. import React, { Component } from 'react';
  30. import {
  31. AlertIOS,
  32. Dimensions,
  33. Image,
  34. ScrollView,
  35. StyleSheet,
  36. Text,
  37. TextInput,
  38. TouchableOpacity,
  39. View
  40. } from 'react-native';
  41.  
  42. import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
  43. import { Actions } from 'react-native-router-flux';
  44.  
  45. import firebaseApp from 'TextbookSwap/firebase_setup';
  46. import styles from 'TextbookSwap/app_styles';
  47.  
  48. // Components
  49. import HeaderImage from './header_image';
  50.  
  51. // For Firebase Auth
  52. const auth = firebaseApp.auth();
  53.  
  54. export default class Login extends Component {
  55. constructor(props) {
  56. super(props);
  57.  
  58. this.state = {
  59. firstName: '',
  60. lastName: '',
  61. email: '',
  62. password: '',
  63. passwordConfirmation: ''
  64. }
  65. }
  66.  
  67. componentDidMount() {
  68. let user = auth.currentUser;
  69. if (user) {
  70. console.log(msg)
  71. Actions.home
  72. } else {
  73. return;
  74. }
  75. }
  76.  
  77. render() {
  78. return (
  79. <View style={styles.mainContainer}>
  80. <KeyboardAwareScrollView
  81. style={styles.scrollView}
  82. keyboardShouldPersistTaps={false}
  83. automaticallyAdjustContentInsets={true}
  84. alwaysBonceVertical={false}
  85. >
  86. <View style={styles.formInputContainer}>
  87. <HeaderImage />
  88. {this.props.login ? this.renderLogin() : this.renderSignup()}
  89. </View>
  90.  
  91. {this.props.login ? this.renderFooter() : null}
  92.  
  93. </KeyboardAwareScrollView>
  94. </View>
  95. );
  96. }
  97.  
  98. renderLogin() {
  99. return (
  100. <View>
  101. {this.renderEmailAndPasswordForms()}
  102. <View style={styles.authButtonContainer}>
  103. <TouchableOpacity
  104. style={styles.authButton}
  105. onPress={this._logInUser.bind(this)}
  106. >
  107. <Text style={styles.actionText}>Log me in!</Text>
  108. </TouchableOpacity>
  109. </View>
  110. </View>
  111. );
  112. }
  113.  
  114. renderSignup() {
  115. return (
  116. <View>
  117. <View style={[styles.formInputWrapper, styles.formInputInlineWrapper]}>
  118. <View style={{borderColor: '#50514F', borderLeftWidth: 0, borderRightWidth: 0.5, borderTopWidth: 0, borderBottomWidth: 0}}>
  119. <TextInput
  120. style={[styles.formInput, styles.formInputInline]}
  121. autoFocus={true}
  122. autoCapitalize="none"
  123. autoCorrect={false}
  124. placeholder="First Name"
  125. onChangeText={(firstName) => this.setState({firstName})}
  126. />
  127. </View>
  128.  
  129. <TextInput
  130. style={[styles.formInput, styles.formInputInline]}
  131. autoFocus={true}
  132. autoCapitalize="none"
  133. autoCorrect={false}
  134. placeholder="Last Name"
  135. onChangeText={(lastName) => this.setState({lastName})}
  136. />
  137. </View>
  138. {this.renderEmailAndPasswordForms()}
  139.  
  140. <View style={styles.formInputWrapper}>
  141. <TextInput
  142. style={styles.formInput}
  143. secureTextEntry={true}
  144. autoCapitalize="none"
  145. autoCorrect={false}
  146. placeholder="Password Confirmation"
  147. onChangeText={(passwordConfirmation) => this.setState({passwordConfirmation})}
  148. />
  149. </View>
  150.  
  151. <View style={styles.authButtonContainer}>
  152. <TouchableOpacity
  153. style={styles.authButton}
  154. onPress={this._signUpUser.bind(this)}
  155. >
  156. <Text style={styles.actionText}>Sign me up!</Text>
  157. </TouchableOpacity>
  158. </View>
  159. </View>
  160. );
  161. }
  162.  
  163. renderEmailAndPasswordForms() {
  164. return (
  165. <View>
  166. <View style={styles.formInputWrapper}>
  167. <TextInput
  168. style={styles.formInput}
  169. autoFocus={true}
  170. autoCapitalize="none"
  171. autoCorrect={false}
  172. placeholder="Email"
  173. onChangeText={(email) => this.setState({email})}
  174. />
  175. </View>
  176.  
  177. <View style={styles.formInputWrapper}>
  178. <TextInput
  179. style={styles.formInput}
  180. secureTextEntry={true}
  181. autoCapitalize="none"
  182. autoCorrect={false}
  183. placeholder="Password"
  184. onChangeText={(password) => this.setState({password})}
  185. />
  186. </View>
  187.  
  188. </View>
  189. );
  190. }
  191.  
  192. renderFooter() {
  193. return (
  194. <View style={styles.footer}>
  195. <TouchableOpacity
  196. style={styles.footerButton}
  197. onPress={Actions.signup}
  198. >
  199. <Text style={styles.actionText}>No account? Create one!</Text>
  200. </TouchableOpacity>
  201. </View>
  202. );
  203. }
  204.  
  205. _logInUser() {
  206. let email = this.state.email;
  207. let password = this.state.password;
  208.  
  209. auth.signInWithEmailAndPassword(email, password)
  210. .then(Actions.home)
  211. .catch((error) => {
  212. switch(error.code) {
  213. case "auth/wrong-password":
  214. AlertIOS.alert('Uh oh!', 'Invalid password! Please try again.');
  215. break;
  216.  
  217. case "auth/invalid-email":
  218. AlertIOS.alert('Uh oh!', 'Invalid email! Please try again.');
  219. break;
  220.  
  221. case "auth/user-not-found":
  222. AlertIOS.alert('Uh oh!', 'Please check your credentials and try again');
  223. break;
  224. }
  225. });
  226. }
  227.  
  228. _signUpUser() {
  229.  
  230. }
  231. }
  232.  
  233. ...
  234. render() {
  235. return (
  236. <MainContainer>
  237. <Header/>
  238. {React.Children.only(this.props.children)}
  239. <Footer/>
  240. </MainContainer>
  241. );
  242. }
  243. ...
  244.  
  245. import React, { Component } from 'react';
  246. import LoginForm from '../LoginForm.jsx';
  247. import Page from '../Page.jsx';
  248.  
  249. class Login extends Component {
  250. render() {
  251. return (
  252. <Page children={LoginForm}/>
  253. );
  254. }
  255. }
  256.  
  257. export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement