Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. login.js
  2.  
  3. import React from 'react';
  4. import {
  5. TextInput,
  6. AppRegistry,
  7. Platform,
  8. StyleSheet,
  9. Text,
  10. Image,
  11. ImageBackground,
  12. View,
  13. Button,
  14. TouchableOpacity
  15.  
  16. }
  17. from 'react-native';
  18. import {StackNavigator} from 'react-navigation'
  19. import * as firebase from 'firebase';
  20.  
  21. //import {Container , Content, Header, Form, Input, Item, Button, Label } from 'native-base';
  22.  
  23. export default class App extends React.Component {
  24.  
  25. constructor(props){
  26. super(props)
  27. this.state =({
  28. email:'',
  29. password:''
  30. })
  31. }
  32.  
  33.  
  34.  
  35. signUpUser = (email,password) => {
  36. try {
  37. if (this.state.password.length < 6){
  38. alert("Minimal 6 karakter")
  39. return;
  40. }
  41.  
  42. firebase.auth().createUserWithEmailAndPassword(email, password)
  43. }
  44. catch (error) {
  45. console.log(error.toString())
  46. }
  47. }
  48.  
  49. loginUser = (email,password) => {
  50.  
  51. try {
  52.  
  53. firebase.auth().signInWithEmailAndPassword(email,password).then(function(user){
  54. console.log(user)
  55. this.props.navigation.navigate("Menu");
  56. })
  57. }
  58.  
  59. catch (error) {
  60. console.log(error.toString())
  61. }
  62. }
  63.  
  64.  
  65. render() {
  66. return (
  67. <ImageBackground
  68. style={styles.stretch}
  69. source={require('../images/bg.jpg')}>
  70. <View style={styles.top}>
  71. <Image source={require('../images/icon.png')}/>
  72.  
  73. <TextInput style = {styles.searchInput}
  74. underlineColorAndroid = "transparent"
  75. placeholder ='Username'
  76. onChangeText={(email) => this.setState({email})}
  77. />
  78.  
  79. <TextInput style = {styles.searchInput}
  80. underlineColorAndroid = "transparent"
  81. placeholder ='Password'
  82. onChangeText={(password) => this.setState({password})}
  83. />
  84.  
  85. <TouchableOpacity
  86. onPress={() => this.loginUser(this.state.email,this.state.password)}
  87. style = {styles.searchInput}>
  88. <Text style = {styles.submitButtonText}> Login </Text>
  89. </TouchableOpacity>
  90.  
  91. <TouchableOpacity
  92. onPress={() => this.signUpUser(this.state.email,this.state.password)}
  93. style = {styles.searchInput}>
  94. <Text style = {styles.submitButtonText}> SignUp </Text>
  95. </TouchableOpacity>
  96.  
  97. </View>
  98.  
  99. </ImageBackground>
  100. );
  101. }
  102. }
  103.  
  104. const styles = StyleSheet.create({
  105. container: {
  106. flex: 1,
  107. backgroundColor: '#fff',
  108. alignItems: 'center',
  109. justifyContent: 'center',
  110. },
  111. stretch: {
  112. flex: 1,
  113. width: '100%',
  114. height: '100%',
  115. },
  116. top: {
  117. marginTop: 80,
  118. height: '60%',
  119. paddingTop: 10,
  120. alignItems: 'center',
  121. justifyContent: 'center',
  122. },
  123. topdua: {
  124. height: '100%',
  125. alignItems: 'center',
  126. justifyContent: 'center',
  127. },
  128. searchInput:{
  129. marginTop: 15,
  130. height:40,
  131. width:'70%',
  132. borderWidth:2,
  133. //color:'#fff',
  134. borderColor:'#fff',
  135. borderRadius:5,
  136. },
  137. submitButtonText:{
  138. height: 40,
  139. width: '70%',
  140. color: '#fff',
  141. alignItems: 'center',
  142. justifyContent: 'center',
  143. }
  144. });
  145.  
  146.  
  147.  
  148.  
  149.  
  150. app.js
  151.  
  152. import React from 'react';
  153. import {
  154. TextInput,
  155. AppRegistry,
  156. Platform,
  157. StyleSheet,
  158. Text,
  159. Image,
  160. ImageBackground,
  161. View,
  162. Button,
  163. TouchableOpacity
  164.  
  165. }
  166. from 'react-native';
  167. import * as firebase from 'firebase';
  168. import {StackNavigator} from 'react-navigation';
  169. import Login from './app/pages/login.js';
  170. import Menu from './app/pages/menu.js';
  171.  
  172. const RootRouter = StackNavigator({
  173. Login: {
  174. screen: Login, navigationOptions: {title: 'Login'}
  175. },
  176. Menu: {
  177. screen: Menu, navigationOptions: {title: 'Menu'}
  178. }
  179.  
  180. })
  181.  
  182.  
  183.  
  184. export default class App extends React.Component {
  185. componentWillMount() {
  186. firebase.initializeApp({
  187. apiKey: "AIzaSyAsUKhwvoN7pfVz0cqWyIdZqmCqPFyjsO0",
  188. authDomain: "sunprojectprototype.firebaseapp.com",
  189. databaseURL: "https://sunprojectprototype.firebaseio.com",
  190. projectId: "sunprojectprototype",
  191. storageBucket: "sunprojectprototype.appspot.com",
  192. messagingSenderId: "1084510740952",
  193. });
  194.  
  195. }
  196.  
  197. render() {
  198. return ( <RootRouter /> );
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement