Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import { StyleSheet, Text, View, TextInput, TouchableOpacity, Image, SafeAreaView, KeyboardAvoidingView, Keyboard, AsyncStorage } from 'react-native';
  3. import {createStackNavigator, createAppContainer} from 'react-navigation'
  4. import Dashboard from '../containers/SideNavigation'
  5.  
  6. export default class Login extends React.Component {
  7.  
  8. constructor(props){
  9. super(props)
  10. this.state = {
  11. customer: [{
  12. username: '',
  13. password: ''
  14. }]
  15. }
  16. }
  17.  
  18. componentDidMount(){
  19. // this._loadInitialState().done()
  20. }
  21.  
  22. _loadInitialState = async () => {
  23. var customernumber = await AsyncStorage.getItem('customernumber');
  24. if(customernumber != null){
  25. this.props.navigation.navigate('Dashboard')
  26. }
  27. }
  28.  
  29. login = () => {
  30. let customer = {}
  31. customer.username = this.state.username,
  32. customer.password = this.state.password
  33.  
  34. var url = 'http://192.168.1.33:7000/api/customer/auth';
  35.  
  36. fetch(url, {
  37. method: 'POST',
  38. body: JSON.stringify(customer),
  39. headers: {
  40. 'Content-Type': 'application/json'
  41. }
  42.  
  43. }).then(res => res.json())
  44. .then((res) => {
  45. if(res.message == 'Success'){
  46. AsyncStorage.setItem('customernumber', ''+res.values.customernumber)
  47. this.props.navigation.navigate('Dashboard')
  48. }else{
  49. alert("Wrong username or password")
  50. }
  51. }).done()
  52. }
  53.  
  54. render() {
  55. return (
  56. <SafeAreaView style={styles.container}>
  57. <KeyboardAvoidingView behavior='padding' style={styles.container}>
  58. <View style={styles.logoContainer}>
  59. <Image
  60. style={styles.logo}
  61. source={require('../assets/musulton.jpg')}
  62. />
  63. <Text style={styles.title}>S A K U</Text>
  64. </View>
  65. <View style={styles.inputContainer}>
  66. <TextInput
  67. style={styles.textInput}
  68. placeholder='Username'
  69. onChangeText={(username) => this.setState({username})}
  70. />
  71. <TextInput
  72. style={styles.textInput}
  73. placeholder='Password'
  74. onChangeText={(password) => this.setState({password})}
  75. />
  76.  
  77. <TouchableOpacity style={styles.button}>
  78. <Text style={styles.textButton} onPress={this.login} >Login</Text>
  79. </TouchableOpacity>
  80. <View style={styles.regisContainer}>
  81. <Text style={styles.regisText}>Masa depanmu tergantung pada tabunganmu</Text>
  82. </View>
  83. </View>
  84. </KeyboardAvoidingView>
  85.  
  86. <View style={styles.infoContainer}>
  87. <Text>Simple bank digital from group 2</Text>
  88. <Text style={{fontWeight: 'bold'}}>Agung, Anwar, Denis, Inas, Sulton</Text>
  89. </View>
  90.  
  91. <View style={styles.regisContainer}>
  92. <Text style={styles.regisText} onPress={() => this.props.navigation.navigate('Register')}>Don't have an account?</Text>
  93. </View>
  94. </SafeAreaView>
  95. );
  96. }
  97. }
  98.  
  99. const styles = StyleSheet.create({
  100. container: {
  101. flex: 1,
  102. backgroundColor: 'white'
  103. },
  104. logoContainer:{
  105. justifyContent: 'flex-end',
  106. alignItems: 'center',
  107. flex: 1
  108. },
  109. logo:{
  110. height:120,
  111. width: 120,
  112. borderRadius: 100
  113. },
  114. title:{
  115. textAlign: 'center',
  116. marginVertical: 10,
  117. fontWeight: 'bold',
  118. fontSize: 20
  119. },
  120. inputContainer:{
  121. paddingHorizontal: 40
  122. },
  123. textInput: {
  124. height: 40,
  125. backgroundColor: 'white',
  126. borderColor: 'grey',
  127. borderWidth: 1,
  128. marginBottom: 15,
  129. paddingHorizontal: 10,
  130. borderRadius: 3
  131. },
  132. button: {
  133. paddingVertical: 20,
  134. backgroundColor: 'blue',
  135. borderRadius: 3
  136. },
  137. textButton: {
  138. color: 'white',
  139. textAlign: 'center',
  140. fontWeight: 'bold'
  141. },
  142. regisContainer: {
  143. alignItems: 'center',
  144. paddingVertical: 15,
  145. borderTopColor: 'lightgrey',
  146. borderTopWidth: 1
  147. },
  148. infoContainer: {
  149. alignItems: 'center',
  150. paddingVertical: 25
  151. },
  152. regisText: {
  153. fontWeight: '400',
  154. color: 'black'
  155. }
  156. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement