Advertisement
Guest User

Untitled

a guest
May 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 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. this.showLoginError = this.showLoginError.bind(this);
  24. }
  25.  
  26. render() {
  27. return (
  28. <View style={styles.container}>
  29. <Text>Sign In</Text>
  30.  
  31. <Text style={styles.label}>Username:</Text>
  32. <TextInput
  33. autoCapitalize={'none'}
  34. style={styles.input}
  35. value={this.state.username}
  36. onChangeText={(text) => this.setState({username: text})}
  37. />
  38.  
  39. <Text style={styles.label}>Password:</Text>
  40. <TextInput
  41. secureTextEntry={true}
  42. style={styles.input}
  43. value={this.state.password}
  44. onChangeText={ (text) => this.setState({password: text}) }
  45. />
  46.  
  47. <Text style={styles.label}>{this.state.errorMessage}</Text>
  48. <Button text={'Sign In'} onPress={ () => this.onPress() } />
  49. </View>
  50. );
  51. }
  52.  
  53. showLoginError(user, error) {
  54. this.setState({errorMessage: error.message});
  55. }
  56. onPress() {
  57. console.log(this);
  58. Parse.User.logIn(this.state.username, this.state.password, {
  59. success: function(user) {
  60. console.log(user);
  61. },
  62. error: this.showLoginError
  63. });
  64. }
  65. }
  66.  
  67. const styles = StyleSheet.create({
  68. container: {
  69. flex: 1,
  70. justifyContent: 'center',
  71. alignItems: 'center'
  72. },
  73. input: {
  74. padding: 4,
  75. height: 40,
  76. borderColor: 'gray',
  77. borderWidth: 1,
  78. borderRadius: 5,
  79. margin: 5,
  80. width: 200,
  81. alignSelf: 'center'
  82. },
  83. label: {
  84. fontSize: 18
  85. }
  86. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement