Guest User

Untitled

a guest
Oct 26th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { StyleSheet, View, ScrollView, Text, Image, Dimensions, TouchableOpacity, AsyncStorage, KeyboardAvoidingView } from 'react-native';
  3. const { width, height } = Dimensions.get("window");
  4. import { onSignIn } from "./auth";
  5. import { Container, Header, Content, Form, Input, Label, Item, Button } from 'native-base';
  6. import background from "../../images/blurry-blue.jpg";
  7. import mark from "../../images/MarriageIconcolor1.png";
  8. import axios from 'axios';
  9. import { BACKEND_URL } from '../../config.js'
  10.  
  11. class LoginScreen extends Component {
  12.  
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. isLoading: false,
  17. userName: null,
  18. password: null
  19. }
  20. this.signIn = this.signIn.bind(this)
  21. }
  22.  
  23. signIn() {
  24. var thiss=this;
  25. axios.post(BACKEND_URL+'/api/User/login', {
  26. userName: this.state.userName,
  27. password: this.state.password
  28. })
  29. .then(function (response) {
  30. if(response.data.message == 'Success'){
  31. // Set up root Auth Token and Headers
  32. axios.defaults.headers.common['Authorization'] = "bearer "+response.data.data.accessToken;
  33. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  34. AsyncStorage.setItem('@userData:', JSON.stringify(response.data.data));
  35. onSignIn().then(() => console.log("auth set"));
  36. console.log("thiss.props.navigation",thiss.props)
  37. thiss.props.navigation.navigate('asder')
  38. thiss.setState({ isLoading: false });
  39. }
  40. })
  41. .catch(function (error) {
  42. alert("Please check your crendentials")
  43. });
  44. }
  45.  
  46. render() {
  47. return(
  48. <View style={{ flex: 1, flexDirection: 'column' }}>
  49. <Image source={background} style={styles.background} resizeMode="cover">
  50. <View style={{ width: '100%', height: '40%', paddingVertical: 30 }}>
  51. <Image source={mark} style={styles.mark} resizeMode="contain" />
  52. </View>
  53. <View style={{ width: '98%', height: '60%' }}>
  54. <Form>
  55. <KeyboardAvoidingView behavior="padding">
  56. <Item floatingLabel>
  57. <Label>Username</Label>
  58. <Input onChangeText={(value) => this.setState({ userName: value }) }/>
  59. </Item>
  60. <Item floatingLabel>
  61. <Label>Password</Label>
  62. <Input onChangeText={(value) => this.setState({ password: value }) }/>
  63. </Item>
  64. </KeyboardAvoidingView>
  65. </Form>
  66. <TouchableOpacity activeOpacity={.1}>
  67. <View>
  68. <Text style={styles.forgotPasswordText}>Forgot Password?</Text>
  69. </View>
  70. </TouchableOpacity>
  71. <Button block style={{ backgroundColor:'#FF0000', margin: 15, marginTop: 25 }} onPress={this.signIn} >
  72. <Text style={{ color: '#FFFFFF' }}>Sign In</Text>
  73. </Button>
  74. <TouchableOpacity activeOpacity={.1} onPress={() => this.props.navigation.navigate('signUp')}>
  75. <View>
  76. <Text style={styles.signupWrapper}>Don't have an account? Sign up</Text>
  77. </View>
  78. </TouchableOpacity>
  79. </View>
  80. </Image>
  81. </View>
  82. )
  83. }
  84. }
  85.  
  86. const styles = StyleSheet.create({
  87. container: {
  88. flex: 1,
  89. },
  90. background: {
  91. width: null,
  92. height: null,
  93. flex: 1,
  94. },
  95. markWrap: {
  96. flex: 1,
  97. paddingVertical: 30,
  98. },
  99. mark: {
  100. width: null,
  101. height: null,
  102. flex: 1,
  103. },
  104. forgotPasswordText: {
  105. color: "white",
  106. backgroundColor: "transparent",
  107. textAlign: "right",
  108. paddingTop: 5,
  109. fontSize:12
  110. },
  111. signupWrapper: {
  112. textAlign:'center',
  113. color: "black",
  114. textDecorationLine: 'underline'
  115. }
  116. });
  117.  
  118. export default LoginScreen;
Add Comment
Please, Sign In to add comment