Advertisement
Guest User

Untitled

a guest
May 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TextInput
  7. } from 'react-native';
  8.  
  9. import Button from '../common/button';
  10.  
  11. var Parse = require('parse/react-native');
  12. var ParseReact = require('parse-react/react-native');
  13.  
  14. export default class Signin extends Component {
  15.  
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. username: '',
  20. password: '',
  21. errorMessage: ''
  22. };
  23. }
  24.  
  25. render() {
  26. return (
  27. <View style={styles.container}>
  28. <Text>Sign In</Text>
  29.  
  30. <Text style={styles.label}>Username:</Text>
  31. <TextInput
  32. autoCapitalize={'none'}
  33. style={styles.input}
  34. value={this.state.username}
  35. onChangeText={(text) => this.setState({username: text})}
  36. />
  37.  
  38. <Text style={styles.label}>Password:</Text>
  39. <TextInput
  40. secureTextEntry={true}
  41. style={styles.input}
  42. value={this.state.password}
  43. onChangeText={ (text) => this.setState({password: text}) }
  44. />
  45.  
  46. <Text style={styles.label}>{this.state.errorMessage}</Text>
  47. <Button text={'Sign In'} onPress={ () => this.onPress() } />
  48. </View>
  49. );
  50. }
  51.  
  52. onPress() {
  53. Parse.User.logIn(this.state.username, this.state.password, {
  54. success: function(user) {
  55. console.log(user);
  56. },
  57. error: function(user, error) {
  58. console.log(error);
  59. this.setState({errorMessage: error.message});
  60. }
  61. });
  62. }
  63. }
  64.  
  65. const styles = StyleSheet.create({
  66. container: {
  67. flex: 1,
  68. justifyContent: 'center',
  69. alignItems: 'center'
  70. },
  71. input: {
  72. padding: 4,
  73. height: 40,
  74. borderColor: 'gray',
  75. borderWidth: 1,
  76. borderRadius: 5,
  77. margin: 5,
  78. width: 200,
  79. alignSelf: 'center'
  80. },
  81. label: {
  82. fontSize: 18
  83. }
  84. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement