forked from davidchang/yo-in-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthenticated.html
115 lines (99 loc) · 3.7 KB
/
authenticated.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<head>
<title>Web Version of Yo</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="style.css" rel="stylesheet" type="text/css" media="all">
<!-- React JS -->
<script src="vendor/react-0.10.0.min.js"></script>
<script src="vendor/JSXTransformer-0.10.0.js"></script>
<!-- Firebase JS -->
<script src="vendor/firebase.js"></script>
<!-- Firebase Login JS -->
<script src="vendor/firebase-simple-login.js"></script>
<!-- ReactFire -->
<script src="vendor/reactfire.min.js"></script>
</head>
<body>
<div id="mount"></div>
<script type="text/jsx" src="coreComponents.js"></script>
<script type="text/jsx">
/** @jsx React.DOM */
// APP COMPONENT
var App = React.createClass({
mixins : [ReactFireMixin],
componentWillMount : function() {
var $this = this;
$this.authRef = new FirebaseSimpleLogin(new Firebase(baseUrl), function(error, user) {
$this.setState({
errorMsg : ''
});
if (error) {
// an error occurred while attempting login
$this.setState({
errorMsg : error.message,
authenticated : false
});
} else if (user) {
// user authenticated with Firebase
$this.setState({
name : user.username,
authenticated : true
});
var newRef = new Firebase(baseUrl + '/users/' + user.username);
$this.bindAsObject(newRef, 'user');
newRef.child('name').set(user.username);
} else {
// user is logged out
$this.setState({
authenticated : false
});
}
});
},
getInitialState : function() {
return {
name : '',
user : {},
errorMsg : '',
authenticated : false
};
},
_logout : function() {
this.authRef.logout();
},
_login : function() {
this.authRef.login('twitter', {
rememberMe: true
});
},
render : function() {
if (this.state.authenticated) {
return (
<div>
<a className="margin-bottom btn btn-default btn-large" href="#" onClick={this._logout}>Logout</a>
<UserDisplay user={this.state.user} />
<PeopleToYo name={this.state.name} />
<YoDisplay user={this.state.user} name={this.state.name} />
<h5>Made by <a href="https://twitter.com/davidchizzle">@davidchizzle</a> from <a href="http://davidandsuzi.com">davidandsuzi.com</a></h5>
</div>
);
}
var errorMsg = '';
if (this.state.errorMsg) {
errorMsg = <div className="alert alert-danger" role="alert">Error : {this.state.errorMsg}</div>
}
return (
<div>
<h3>My Web Version of Yo using React and Firebase</h3>
<div className="margin-bottom">If you do not want to log in, you can still view the experience at <a href="index.html">here</a>.</div>
{errorMsg}
<a className="margin-bottom btn btn-primary" href="#" onClick={this._login}>Login</a>
<h5>Made by <a href="https://twitter.com/davidchizzle">@davidchizzle</a> from <a href="http://davidandsuzi.com">davidandsuzi.com</a></h5>
</div>
);
}
});
React.renderComponent(<App />, document.getElementById('mount'));
</script>
</body>
</html>