Skip to content

Commit 314d189

Browse files
committed
improved authentication and logout
1 parent 1862d43 commit 314d189

File tree

3 files changed

+194
-58
lines changed

3 files changed

+194
-58
lines changed

handlers.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ type JSONResponse struct {
1818
Data interface{} `json:"data,string"`
1919
}
2020

21-
func Index(w http.ResponseWriter, r *http.Request) {
22-
fmt.Fprintln(w, "hello world")
23-
}
24-
2521
// Returns JSON response of all mods installed in factorio/mods
2622
func ListInstalledMods(w http.ResponseWriter, r *http.Request) {
2723
var err error
@@ -585,14 +581,14 @@ func LoginUser(w http.ResponseWriter, r *http.Request) {
585581
return
586582
}
587583

588-
log.Printf("Logging in user: %v", string(body))
589-
590584
err = json.Unmarshal(body, &user)
591585
if err != nil {
592586
log.Printf("Error unmarshaling server settings JSON: %s", err)
593587
return
594588
}
595589

590+
log.Printf("Logging in user: %s", user.Username)
591+
596592
err = Auth.aaa.Login(w, r, user.Username, user.Password, "/")
597593
if err != nil {
598594
log.Printf("Error logging in user: %s, error: %s", user.Username, err)

ui/App/components/Header.jsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
import React from 'react';
2-
import {IndexLink} from 'react-router';
2+
import {IndexLink, browserHistory} from 'react-router';
33

44
class Header extends React.Component {
5+
constructor(props) {
6+
super(props);
7+
this.onLogout = this.onLogout.bind(this);
8+
}
9+
10+
onLogout(e) {
11+
e.preventDefault();
12+
$.ajax({
13+
url: "/api/logout",
14+
dataType: "json",
15+
success: (resp) => {
16+
console.log(resp)
17+
alert(resp.data)
18+
}
19+
});
20+
// Wait for 1 second for logout callback to complete
21+
setTimeout(() => {
22+
browserHistory.push("/login");
23+
}, 1000);
24+
}
25+
526
render() {
27+
var loginMenu;
28+
if (this.props.loggedIn) {
29+
loginMenu =
30+
<ul className="nav navbar-nav">
31+
<li>
32+
<a href="javascript:void(0)" onClick={this.onLogout}><i className="fa fa-gears fa-fw"></i>Logout</a>
33+
</li>
34+
</ul>
35+
}
636
return(
737
<header className="main-header">
838

@@ -13,11 +43,7 @@ class Header extends React.Component {
1343
<span className="sr-only">Toggle navigation</span>
1444
</a>
1545
<div className="navbar-custom-menu">
16-
<ul className="nav navbar-nav">
17-
<li>
18-
<a href="#" data-toggle="control-sidebar"><i className="fa fa-gears"></i></a>
19-
</li>
20-
</ul>
46+
{loginMenu}
2147
</div>
2248
</nav>
2349
</header>

ui/App/components/HiddenSidebar.jsx

Lines changed: 160 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,185 @@ import {Link, browserHistory} from 'react-router';
44
class HiddenSidebar extends React.Component {
55
constructor(props) {
66
super(props);
7-
this.onLogout = this.onLogout.bind(this);
87
}
98

109
capitalizeFirstLetter(string) {
1110
return string.charAt(0).toUpperCase() + string.slice(1);
1211
}
1312

14-
onLogout(e) {
15-
e.preventDefault();
16-
$.ajax({
17-
url: "/api/logout",
18-
dataType: "json",
19-
success: (resp) => {
20-
alert(resp)
21-
}
22-
});
23-
// Wait for 1 second for logout callback to complete
24-
setTimeout(() => {
25-
browserHistory.push("/login");
26-
}, 1000);
27-
}
28-
2913
render() {
3014
var username;
3115
if (this.props.loggedIn) {
3216
username = <p>{this.props.username}</p>
3317
}
3418

3519
return(
36-
<aside className="control-sidebar control-sidebar-dark">
37-
<ul className="control-sidebar-menu">
20+
<aside id="control-sidebar" className="control-sidebar control-sidebar-dark">
21+
<ul className="nav nav-tabs nav-justified control-sidebar-tabs">
22+
<li className="active"><a href="control-sidebar-theme-demo-options-tab" data-toggle="tab"><i className="fa fa-wrench"></i></a></li>
23+
<li><a href="#control-sidebar-home-tab" data-toggle="tab"><i className="fa fa-home"></i></a></li>
24+
<li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i className="fa fa-gears"></i></a></li>
25+
</ul>
26+
<div className="tab-content">
27+
<div className="tab-pane" id="control-sidebar-home-tab">
28+
<h3 className="control-sidebar-heading">Recent Activity</h3>
29+
<ul className="control-sidebar-menu">
30+
<li>
31+
<Link to="/login" activeClassName="active">
32+
<i className="menu-icon fa fa-birthday-cake bg-red"></i>
33+
34+
<div className="menu-info">
35+
<i classNameName="menu-icon fa fa-lock bg-green"></i>
36+
<h4 className="control-sidebar-subheading">Login</h4>
37+
</div>
38+
</Link>
39+
</li>
40+
<li>
41+
<a href="javascript:void(0)">
42+
<i className="menu-icon fa fa-lock bg-yellow"></i>
43+
44+
<div className="menu-info">
45+
46+
<h4 className="control-sidebar-subheading">Logout</h4>
47+
</div>
48+
</a>
49+
</li>
50+
</ul>
51+
52+
<h3 className="control-sidebar-heading">Tasks Progress</h3>
53+
<div classNameName="table-responsive">
54+
<table classNameName="table table-border">
55+
<thead>
56+
<tr>
57+
</tr>
58+
</thead>
59+
<tbody>
60+
{Object.keys(this.props.serverStatus).map(function(key) {
61+
return(
62+
<tr key={key}>
63+
<td>{this.capitalizeFirstLetter(key)}</td>
64+
<td>{this.props.serverStatus[key]}</td>
65+
</tr>
66+
)
67+
}, this)}
68+
</tbody>
69+
</table>
70+
</div>
71+
<ul className="control-sidebar-menu">
3872
<li>
39-
<Link to="/login" activeClassName="active">
40-
<i className="menu-icon fa fa-lock bg-green"></i>
41-
Login
42-
</Link>
73+
<a href="javascript:void(0)">
74+
<h4 className="control-sidebar-subheading">
75+
Custom Template Design
76+
<span className="label label-danger pull-right">70%</span>
77+
</h4>
78+
79+
<div className="progress progress-xxs">
80+
<div className="progress-bar progress-bar-danger"></div>
81+
</div>
82+
</a>
4383
</li>
4484
<li>
45-
<a onClick={this.onLogout}>
46-
<i className="menu-icon fa fa-lock bg-red"></i>
47-
Login
85+
<a href="javascript:void(0)">
86+
<h4 className="control-sidebar-subheading">
87+
Update Resume
88+
<span className="label label-success pull-right">95%</span>
89+
</h4>
90+
91+
<div className="progress progress-xxs">
92+
<div className="progress-bar progress-bar-success"></div>
93+
</div>
4894
</a>
4995
</li>
50-
</ul>
51-
Current user: {username}
52-
<div className="table-responsive">
53-
<table className="table table-border">
54-
<thead>
55-
<tr>
56-
</tr>
57-
</thead>
58-
<tbody>
59-
{Object.keys(this.props.serverStatus).map(function(key) {
60-
return(
61-
<tr key={key}>
62-
<td>{this.capitalizeFirstLetter(key)}</td>
63-
<td>{this.props.serverStatus[key]}</td>
64-
</tr>
65-
)
66-
}, this)}
67-
</tbody>
68-
</table>
96+
<li>
97+
<a href="javascript:void(0)">
98+
<h4 className="control-sidebar-subheading">
99+
Laravel Integration
100+
<span className="label label-warning pull-right">50%</span>
101+
</h4>
102+
103+
<div className="progress progress-xxs">
104+
<div className="progress-bar progress-bar-warning"></div>
105+
</div>
106+
</a>
107+
</li>
108+
<li>
109+
<a href="javascript:void(0)">
110+
<h4 className="control-sidebar-subheading">
111+
Back End Framework
112+
<span className="label label-primary pull-right">68%</span>
113+
</h4>
114+
115+
<div className="progress progress-xxs">
116+
<div className="progress-bar progress-bar-primary"></div>
117+
</div>
118+
</a>
119+
</li>
120+
</ul>
121+
</div>
122+
123+
<div className="tab-pane" id="control-sidebar-settings-tab">
124+
<form method="post">
125+
<h3 className="control-sidebar-heading">General Settings</h3>
126+
127+
<div className="form-group">
128+
<label className="control-sidebar-subheading">
129+
Report panel usage
130+
<input type="checkbox" className="pull-right" checked="" />
131+
</label>
132+
133+
<p>
134+
Some information about this general settings option
135+
</p>
136+
</div>
137+
138+
<div className="form-group">
139+
<label className="control-sidebar-subheading">
140+
Allow mail redirect
141+
<input type="checkbox" className="pull-right" checked="" />
142+
</label>
143+
144+
<p>
145+
Other sets of options are available
146+
</p>
147+
</div>
148+
149+
<div className="form-group">
150+
<label className="control-sidebar-subheading">
151+
Expose author name in posts
152+
<input type="checkbox" className="pull-right" checked="" />
153+
</label>
154+
155+
<p>
156+
Allow the user to show his name in blog posts
157+
</p>
158+
</div>
159+
160+
<h3 className="control-sidebar-heading">Chat Settings</h3>
161+
162+
<div className="form-group">
163+
<label className="control-sidebar-subheading">
164+
Show me as online
165+
<input type="checkbox" className="pull-right" checked="" />
166+
</label>
167+
</div>
168+
169+
<div className="form-group">
170+
<label className="control-sidebar-subheading">
171+
Turn off notifications
172+
<input type="checkbox" className="pull-right" />
173+
</label>
174+
</div>
175+
176+
<div className="form-group">
177+
<label className="control-sidebar-subheading">
178+
Delete chat history
179+
<a href="javascript:void(0)" className="text-red pull-right"><i className="fa fa-trash-o"></i></a>
180+
</label>
181+
</div>
182+
</form>
69183
</div>
70-
<div className="control-sidebar-bg" style={{position: "fixed", height: "auto"}}></div>
71-
</aside>
184+
</div>
185+
</aside>
72186
)
73187
}
74188
}

0 commit comments

Comments
 (0)