Guest User

Untitled

a guest
May 28th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. const instructions = Platform.select({
  2. ios: 'Press Cmd+R to reload,n' +
  3. 'Cmd+D or shake for dev menu',
  4. android: 'Double tap R on your keyboard to reload,n' +
  5. 'Shake or press menu button for dev menu',
  6. });
  7.  
  8. import { TabNavigator, StackNavigator } from 'react-navigation';
  9. import Icon from 'react-native-vector-icons/Ionicons';
  10. import EvilIcons from 'react-native-vector-icons/EvilIcons';
  11. import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
  12. import { Container, Header, Content, Card, CardItem, Thumbnail, Button, Left, Body, Right, Item, Input } from 'native-base';
  13.  
  14. const ACCESS_TOKEN = 'access_token';
  15. export default class Landing extends Component {
  16. static navigationOptions = {
  17. header: false
  18. };
  19. constructor(props) {
  20. super(props);
  21. this.state = {
  22. username: "",
  23. password: "",
  24. error: "",
  25. };
  26. }
  27.  
  28. async storeToken(accessToken){
  29. try{
  30. await AsyncStorage.setItem(ACCESS_TOKEN, access_token)
  31. this.getToken();
  32. } catch (error) {
  33. console.log("Something went wrong")
  34. }
  35. }
  36.  
  37. async getToken(accessToken){
  38. try{
  39. let token = await AsyncStorage.getItem(ACCESS_TOKEN)
  40. console.log("token is: " + token)
  41. } catch (error) {
  42. console.log("Something went wrong")
  43. }
  44. }
  45.  
  46. async removeToken(){
  47. try{
  48. await AsyncStorage.getItem(ACCESS_TOKEN)
  49. console.log("token is: " + token)
  50. this.getToken();
  51. } catch (error) {
  52. console.log("Something went wrong")
  53. }
  54. }
  55.  
  56. async onLoginPressed() {
  57. this.setState({showProgress: true})
  58. try {
  59. let response = await fetch('https://fb3b2e18.ngrok.io/login', {
  60. method: 'POST',
  61. headers: {
  62. 'Accept': 'application/json',
  63. 'Content-Type': 'application/json',
  64. },
  65. body: JSON.stringify({
  66. username: this.state.username,
  67. password: this.state.password,
  68. })
  69. });
  70. let res = await response.text();
  71. if (response.status >= 200 && response.status < 300) {
  72. //Handle success
  73. this.setState({error: ""});
  74. let accessToken = res;
  75. this.storeToken(accessToken);
  76. console.log( "res token: " + accessToken);
  77. //On success we will store the access_token in the AsyncStorage
  78. this.storeToken(accessToken);
  79. } else {
  80. //Handle error
  81. let error = res;
  82. throw error;
  83. }
  84. } catch(error) {
  85. this.removeToken();
  86. this.setState({error: error});
  87. console.log("error " + error);
  88. }
  89. }
  90.  
  91. render() {
  92. const {goBack} = this.props.navigation;
  93. var {navigate} = this.props.navigation;
  94. return (
  95. <ImageBackground source={require('./landing.png')} style={styles.backgroundImage}>
  96. <ScrollView automaticallyAdjustContentInsets={false} style={styles.scrollView}>
  97. <Text style={styles.welcome}>
  98. Welcome to Flipclip
  99. </Text>
  100. <View style={{alignItems: 'center', flex: 1,marginBottom: 60}}>
  101. <Item style={{width: 310,marginBottom: 10}}>
  102. <EvilIcons style={{color:'#fefefe'}} name='user' size={20} />
  103. <Input
  104. style={{color: '#f5f5f5',fontSize: 14,fontFamily: 'Montserrat-Regular',}}
  105. placeholder='User Name'
  106. placeholderTextColor= '#f5f5f5'
  107. onChangeText={ (text)=> this.setState({username: text}) }
  108. />
  109. </Item>
  110. <Item style={{width: 310}}>
  111. <Icon style={{color:'#fefefe'}} name='ios-lock-outline' size={20}/>
  112. <Input
  113. style={{color: '#f5f5f5',fontSize: 14, marginLeft: 5,fontFamily: 'Montserrat-Regular',}}
  114. placeholder='Password'
  115. placeholderTextColor= '#f5f5f5'
  116. onChangeText={ (text)=> this.setState({password: text}) }
  117. />
  118. </Item>
  119. </View>
  120. <View style={{alignSelf: 'center', flex: 1}}>
  121. <Button block transparent style={styles.LoginButton} onPress = {this.onLoginPressed.bind(this)} >
  122. <Text style={styles.logintext}>Sign In</Text>
  123. </Button>
  124. </View>
  125. <View style={{justifyContent: 'center'}}>
  126. <Text style={styles.SignUpResendOtpText}>
  127. Don’t have an account?&nbsp;
  128. <Text style={styles.SignUpResendOtpLink} onPress = { () => navigate ("SignUp", {}) }>
  129. Sign Up
  130. </Text>
  131. </Text>
  132. </View>
  133.  
  134. <Text style={styles.error}>
  135. {this.state.error}
  136. </Text>
  137. </ScrollView>
  138. </ImageBackground>
  139. )
  140. }
  141. }
  142.  
  143. const styles = StyleSheet.create({
  144. scrollView:{
  145. backgroundColor: 'rgba(0,0,0,0.7)',
  146. flex:1,
  147. },
  148. backgroundImage: {
  149. flex: 1,
  150. width: null,
  151. height: null,
  152. },
  153.  
  154. text: {
  155. color: 'white',
  156. fontSize: 32,
  157. },
  158.  
  159. uploaderName:{
  160. fontSize: 16,
  161. color: '#fefefe'
  162. },
  163. welcome: {
  164. fontSize: 28,
  165. color: '#f5f5f5',
  166. textAlign: 'center',
  167. marginTop: 201,
  168. marginBottom: 135,
  169. fontFamily: 'FredokaOne-Regular'
  170. },
  171. instructions: {
  172. textAlign: 'center',
  173. color: '#333333',
  174. marginBottom: 5,
  175. },
  176. LoginButton: {
  177. borderRadius:100,
  178. backgroundColor: '#ff0046',
  179. width: 310,
  180. marginBottom: 20,
  181. },
  182. logintext:{
  183. color: '#f5f5f5',
  184. fontSize: 14,
  185. fontFamily: 'Montserrat-Medium',
  186. },
  187. error: {
  188. color: 'red',
  189. paddingTop: 10
  190. },
  191. SignUpResendOtpText: {
  192. color: '#f5f5f5',
  193. textAlign: 'center',
  194. fontSize: 14,
  195. fontFamily: 'Montserrat-Regular',
  196. },
  197. SignUpResendOtpLink:{
  198. color: '#ff0046',
  199. textAlign: 'center',
  200. fontSize: 14,
  201. fontFamily: 'Montserrat-Medium',
  202. textDecorationLine: 'none',
  203. textDecorationStyle: 'solid',
  204. textDecorationColor: '#000'
  205. },
  206. success: {
  207. color: 'green',
  208. paddingTop: 10
  209. },
  210. });
  211.  
  212. <Button block transparent style={styles.LoginButton} onPress = {this.onLoginPressed.bind(this)} >
  213.  
  214. <Button block transparent style={styles.LoginButton} onPress = {() => this.onLoginPressed.bind(this)} >
Add Comment
Please, Sign In to add comment