From 1862d43bfb6d593cc897e443c3b0b62232c6d8e0 Mon Sep 17 00:00:00 2001 From: majormjr Date: Sat, 30 Apr 2016 17:48:45 -0400 Subject: [PATCH] added logout, improved login and logout ui --- app/dist/dist/css/AdminLTE.css | 5 + app/dist/dist/css/factorio-server-manager.css | 12 +++ app/index.html | 2 + auth.go | 2 +- handlers.go | 2 +- main.go | 2 +- ui/App/App.jsx | 20 ++-- ui/App/components/Header.jsx | 5 + ui/App/components/HiddenSidebar.jsx | 29 +++++- ui/App/components/LoginContent.jsx | 94 ++++++++++--------- ui/App/components/ServerCtl/ServerCtl.jsx | 2 +- 11 files changed, 116 insertions(+), 59 deletions(-) create mode 100644 app/dist/dist/css/factorio-server-manager.css diff --git a/app/dist/dist/css/AdminLTE.css b/app/dist/dist/css/AdminLTE.css index a8988b4..9f4950c 100644 --- a/app/dist/dist/css/AdminLTE.css +++ b/app/dist/dist/css/AdminLTE.css @@ -4918,3 +4918,8 @@ table.text-center th { white-space: normal !important; } } + +.col-centered { + float: none; + margin: 0 auto; +} diff --git a/app/dist/dist/css/factorio-server-manager.css b/app/dist/dist/css/factorio-server-manager.css new file mode 100644 index 0000000..2be3794 --- /dev/null +++ b/app/dist/dist/css/factorio-server-manager.css @@ -0,0 +1,12 @@ +/* Custom CSS for Factorio Server Manager */ + +.col-centered { + float: none; + margin: 0 auto; +} + +.absolute-center { + margin: auto; + position: absolute; + top: 0; left: 0; bottom: 0; right: 0; +} diff --git a/app/index.html b/app/index.html index e60cc66..e314585 100644 --- a/app/index.html +++ b/app/index.html @@ -16,6 +16,8 @@ + + diff --git a/auth.go b/auth.go index 53b0b01..0de3eba 100644 --- a/auth.go +++ b/auth.go @@ -47,7 +47,7 @@ func (auth *AuthHTTP) createRoles() { } } -func (auth *AuthHTTP) createUser(username, password, role, email string) error { +func (auth *AuthHTTP) createInitialUser(username, password, role, email string) error { user := httpauth.UserData{Username: username, Role: role, Email: email} err := auth.backend.SaveUser(user) if err != nil { diff --git a/handlers.go b/handlers.go index 078b7b6..00f389a 100644 --- a/handlers.go +++ b/handlers.go @@ -649,7 +649,7 @@ func GetCurrentLogin(w http.ResponseWriter, r *http.Request) { } return } - fmt.Println(user, err) + resp.Success = true resp.Data = user diff --git a/main.go b/main.go index 8a00a25..c286780 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { Auth = initAuth() Auth.createAuthDb(config.DatabaseFile) Auth.createRoles() - err := Auth.createUser(config.Username, config.Password, "admin", "") + err := Auth.createInitialUser(config.Username, config.Password, "admin", "") if err != nil { log.Printf("Error creating user: %s", err) } diff --git a/ui/App/App.jsx b/ui/App/App.jsx index 11a984a..91e67b2 100644 --- a/ui/App/App.jsx +++ b/ui/App/App.jsx @@ -18,6 +18,7 @@ class App extends React.Component { serverStatus: {}, saves: [], loggedIn: false, + username: "", } } @@ -31,14 +32,13 @@ class App extends React.Component { } checkLogin() { - console.log(this.state); $.ajax({ url: "/api/user/status", dataType: "json", success: (data) => { - console.log(data.success); if (data.success === true) { - this.setState({loggedIn: true}) + this.setState({loggedIn: true, + username: data.data.Username}) } } }) @@ -87,7 +87,10 @@ class App extends React.Component { if (this.state.loggedIn) { var resp =
-
+
; + username={this.state.username} + loggedIn={this.state.loggedIn} + checkLogin={this.checkLogin} + />
} else { var resp =

Not Logged in

; - console.log(resp); } return( diff --git a/ui/App/components/Header.jsx b/ui/App/components/Header.jsx index f8147a2..e984b76 100644 --- a/ui/App/components/Header.jsx +++ b/ui/App/components/Header.jsx @@ -25,4 +25,9 @@ class Header extends React.Component { } } +Header.propTypes = { + username: React.PropTypes.string.isRequired, + loggedIn: React.PropTypes.bool.isRequired, +} + export default Header diff --git a/ui/App/components/HiddenSidebar.jsx b/ui/App/components/HiddenSidebar.jsx index e08d065..f30bc95 100644 --- a/ui/App/components/HiddenSidebar.jsx +++ b/ui/App/components/HiddenSidebar.jsx @@ -1,16 +1,37 @@ import React from 'react'; -import {Link} from 'react-router'; +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) { + username =

{this.props.username}

+ } + return(