mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2024-12-31 03:11:17 +02:00
improved authentication and logout
This commit is contained in:
parent
1862d43bfb
commit
314d189620
@ -18,10 +18,6 @@ type JSONResponse struct {
|
||||
Data interface{} `json:"data,string"`
|
||||
}
|
||||
|
||||
func Index(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "hello world")
|
||||
}
|
||||
|
||||
// Returns JSON response of all mods installed in factorio/mods
|
||||
func ListInstalledMods(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
@ -585,14 +581,14 @@ func LoginUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Logging in user: %v", string(body))
|
||||
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshaling server settings JSON: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Logging in user: %s", user.Username)
|
||||
|
||||
err = Auth.aaa.Login(w, r, user.Username, user.Password, "/")
|
||||
if err != nil {
|
||||
log.Printf("Error logging in user: %s, error: %s", user.Username, err)
|
||||
|
@ -1,8 +1,38 @@
|
||||
import React from 'react';
|
||||
import {IndexLink} from 'react-router';
|
||||
import {IndexLink, browserHistory} from 'react-router';
|
||||
|
||||
class Header extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.onLogout = this.onLogout.bind(this);
|
||||
}
|
||||
|
||||
onLogout(e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
url: "/api/logout",
|
||||
dataType: "json",
|
||||
success: (resp) => {
|
||||
console.log(resp)
|
||||
alert(resp.data)
|
||||
}
|
||||
});
|
||||
// Wait for 1 second for logout callback to complete
|
||||
setTimeout(() => {
|
||||
browserHistory.push("/login");
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
render() {
|
||||
var loginMenu;
|
||||
if (this.props.loggedIn) {
|
||||
loginMenu =
|
||||
<ul className="nav navbar-nav">
|
||||
<li>
|
||||
<a href="javascript:void(0)" onClick={this.onLogout}><i className="fa fa-gears fa-fw"></i>Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
return(
|
||||
<header className="main-header">
|
||||
|
||||
@ -13,11 +43,7 @@ class Header extends React.Component {
|
||||
<span className="sr-only">Toggle navigation</span>
|
||||
</a>
|
||||
<div className="navbar-custom-menu">
|
||||
<ul className="nav navbar-nav">
|
||||
<li>
|
||||
<a href="#" data-toggle="control-sidebar"><i className="fa fa-gears"></i></a>
|
||||
</li>
|
||||
</ul>
|
||||
{loginMenu}
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
@ -4,28 +4,12 @@ import {Link, browserHistory} from 'react-router';
|
||||
class HiddenSidebar extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.onLogout = this.onLogout.bind(this);
|
||||
}
|
||||
|
||||
capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
onLogout(e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
url: "/api/logout",
|
||||
dataType: "json",
|
||||
success: (resp) => {
|
||||
alert(resp)
|
||||
}
|
||||
});
|
||||
// Wait for 1 second for logout callback to complete
|
||||
setTimeout(() => {
|
||||
browserHistory.push("/login");
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
render() {
|
||||
var username;
|
||||
if (this.props.loggedIn) {
|
||||
@ -33,42 +17,172 @@ class HiddenSidebar extends React.Component {
|
||||
}
|
||||
|
||||
return(
|
||||
<aside className="control-sidebar control-sidebar-dark">
|
||||
<ul className="control-sidebar-menu">
|
||||
<aside id="control-sidebar" className="control-sidebar control-sidebar-dark">
|
||||
<ul className="nav nav-tabs nav-justified control-sidebar-tabs">
|
||||
<li className="active"><a href="control-sidebar-theme-demo-options-tab" data-toggle="tab"><i className="fa fa-wrench"></i></a></li>
|
||||
<li><a href="#control-sidebar-home-tab" data-toggle="tab"><i className="fa fa-home"></i></a></li>
|
||||
<li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i className="fa fa-gears"></i></a></li>
|
||||
</ul>
|
||||
<div className="tab-content">
|
||||
<div className="tab-pane" id="control-sidebar-home-tab">
|
||||
<h3 className="control-sidebar-heading">Recent Activity</h3>
|
||||
<ul className="control-sidebar-menu">
|
||||
<li>
|
||||
<Link to="/login" activeClassName="active">
|
||||
<i className="menu-icon fa fa-birthday-cake bg-red"></i>
|
||||
|
||||
<div className="menu-info">
|
||||
<i classNameName="menu-icon fa fa-lock bg-green"></i>
|
||||
<h4 className="control-sidebar-subheading">Login</h4>
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:void(0)">
|
||||
<i className="menu-icon fa fa-lock bg-yellow"></i>
|
||||
|
||||
<div className="menu-info">
|
||||
|
||||
<h4 className="control-sidebar-subheading">Logout</h4>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3 className="control-sidebar-heading">Tasks Progress</h3>
|
||||
<div classNameName="table-responsive">
|
||||
<table classNameName="table table-border">
|
||||
<thead>
|
||||
<tr>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Object.keys(this.props.serverStatus).map(function(key) {
|
||||
return(
|
||||
<tr key={key}>
|
||||
<td>{this.capitalizeFirstLetter(key)}</td>
|
||||
<td>{this.props.serverStatus[key]}</td>
|
||||
</tr>
|
||||
)
|
||||
}, this)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<ul className="control-sidebar-menu">
|
||||
<li>
|
||||
<Link to="/login" activeClassName="active">
|
||||
<i className="menu-icon fa fa-lock bg-green"></i>
|
||||
Login
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<a onClick={this.onLogout}>
|
||||
<i className="menu-icon fa fa-lock bg-red"></i>
|
||||
Login
|
||||
<a href="javascript:void(0)">
|
||||
<h4 className="control-sidebar-subheading">
|
||||
Custom Template Design
|
||||
<span className="label label-danger pull-right">70%</span>
|
||||
</h4>
|
||||
|
||||
<div className="progress progress-xxs">
|
||||
<div className="progress-bar progress-bar-danger"></div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
Current user: {username}
|
||||
<div className="table-responsive">
|
||||
<table className="table table-border">
|
||||
<thead>
|
||||
<tr>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Object.keys(this.props.serverStatus).map(function(key) {
|
||||
return(
|
||||
<tr key={key}>
|
||||
<td>{this.capitalizeFirstLetter(key)}</td>
|
||||
<td>{this.props.serverStatus[key]}</td>
|
||||
</tr>
|
||||
)
|
||||
}, this)}
|
||||
</tbody>
|
||||
</table>
|
||||
<li>
|
||||
<a href="javascript:void(0)">
|
||||
<h4 className="control-sidebar-subheading">
|
||||
Update Resume
|
||||
<span className="label label-success pull-right">95%</span>
|
||||
</h4>
|
||||
|
||||
<div className="progress progress-xxs">
|
||||
<div className="progress-bar progress-bar-success"></div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:void(0)">
|
||||
<h4 className="control-sidebar-subheading">
|
||||
Laravel Integration
|
||||
<span className="label label-warning pull-right">50%</span>
|
||||
</h4>
|
||||
|
||||
<div className="progress progress-xxs">
|
||||
<div className="progress-bar progress-bar-warning"></div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:void(0)">
|
||||
<h4 className="control-sidebar-subheading">
|
||||
Back End Framework
|
||||
<span className="label label-primary pull-right">68%</span>
|
||||
</h4>
|
||||
|
||||
<div className="progress progress-xxs">
|
||||
<div className="progress-bar progress-bar-primary"></div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="control-sidebar-bg" style={{position: "fixed", height: "auto"}}></div>
|
||||
</aside>
|
||||
|
||||
<div className="tab-pane" id="control-sidebar-settings-tab">
|
||||
<form method="post">
|
||||
<h3 className="control-sidebar-heading">General Settings</h3>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-sidebar-subheading">
|
||||
Report panel usage
|
||||
<input type="checkbox" className="pull-right" checked="" />
|
||||
</label>
|
||||
|
||||
<p>
|
||||
Some information about this general settings option
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-sidebar-subheading">
|
||||
Allow mail redirect
|
||||
<input type="checkbox" className="pull-right" checked="" />
|
||||
</label>
|
||||
|
||||
<p>
|
||||
Other sets of options are available
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-sidebar-subheading">
|
||||
Expose author name in posts
|
||||
<input type="checkbox" className="pull-right" checked="" />
|
||||
</label>
|
||||
|
||||
<p>
|
||||
Allow the user to show his name in blog posts
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h3 className="control-sidebar-heading">Chat Settings</h3>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-sidebar-subheading">
|
||||
Show me as online
|
||||
<input type="checkbox" className="pull-right" checked="" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-sidebar-subheading">
|
||||
Turn off notifications
|
||||
<input type="checkbox" className="pull-right" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-sidebar-subheading">
|
||||
Delete chat history
|
||||
<a href="javascript:void(0)" className="text-red pull-right"><i className="fa fa-trash-o"></i></a>
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user