-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
97 lines (86 loc) · 2.69 KB
/
login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React, {Component} from 'react';
import {
View,
Text,
StyleSheet,
Image,
TextInput,
TouchableHighlight,
ActivityIndicator
} from 'react-native';
import Styles from './style';
import Buffer from 'buffer';
import AuthService from './services/authService';
class Login extends Component {
constructor(props) {
super(props);
this.state = {
showProgress: false,
};
}
render() {
var errorCtrl = <View />;
if(!this.state.success && this.state.badCredentials){
errorCtrl = <Text style={Styles.error}>
That username and password combination did not work
</Text>;
}
if(this.state.UnknownError){
errorCtrl = <Text style={Styles.error}>
We experienced an unexpected issue
</Text>;
}
return (
<View style={Styles.container}>
<Image style={Styles.logo} source={require('./img/Octocat.png')}/>
<Text style={Styles.heading}>
Github Browser
</Text>
<TextInput
style={Styles.input}
placeholder='Github username'
onChangeText={(text) => this.setState({username: text})}/>
<TextInput
style={Styles.input}
placeholder='Github password'
secureTextEntry={true}
onChangeText={(text) => this.setState({password: text})}/>
<TouchableHighlight
style={Styles.button}
onPress={this
.onLoginPressed
.bind(this)}>
<Text style={Styles.buttonText}>
Login
</Text>
</TouchableHighlight>
{errorCtrl}
<ActivityIndicator
style={{
marginTop: 20,
opacity: this.state.showProgress
? 1.0
: 0.0
}}
animating={true}
size='large'/>
</View>
);
}
onLoginPressed() {
this.setState({showProgress: true});
var auth = new AuthService();
auth.login({
username: this.state.username,
password: this.state.password
},(result)=>{
this.setState(Object.assign({
showProgress: false
},result));
if(result.success && this.props.onLogin){
this.props.onLogin();
}
});
};
}
export default Login;