mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-24 05:17:24 +02:00
added logout functionality
This commit is contained in:
parent
fe247a6958
commit
e1b2a017d4
@ -61,7 +61,7 @@ func LoginFactorioModPortal(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(statusCode)
|
||||
|
||||
if err != nil {
|
||||
resp.Data = fmt.Sprintf("Error in getUserToken or LoginFactorioModPortal handler: %s", err)
|
||||
resp.Data = fmt.Sprintf("Error trying to login into Factorio: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error in Factorio-Login: %s", err)
|
||||
}
|
||||
@ -86,7 +86,7 @@ func LoginstatusFactorioModPortal(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
resp.Data = fmt.Sprintf("Error in getUserToken or LoginFactorioModPortal handler: %s", err)
|
||||
resp.Data = fmt.Sprintf("Error getting the factorio credentials: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error in Factorio-Login: %s", err)
|
||||
}
|
||||
@ -100,6 +100,32 @@ func LoginstatusFactorioModPortal(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func LogoutFactorioModPortalHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
resp := JSONResponse{
|
||||
Success: false,
|
||||
}
|
||||
|
||||
var credentials FactorioCredentials
|
||||
err = credentials.del()
|
||||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
resp.Data = fmt.Sprintf("Error on logging out of factorio: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error in Factorio-Login: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
resp.Data = false
|
||||
resp.Success = true
|
||||
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error in Factorio-Login: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
//Returns JSON response with the found mods
|
||||
func ModPortalSearchHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
|
@ -163,6 +163,11 @@ var apiRoutes = Routes{
|
||||
"POST",
|
||||
"/mods/factorio/status",
|
||||
LoginstatusFactorioModPortal,
|
||||
}, {
|
||||
"LogoutFactorioModPortal",
|
||||
"POST",
|
||||
"/mods/factorio/logout",
|
||||
LogoutFactorioModPortalHandler,
|
||||
}, {
|
||||
"SearchModPortal",
|
||||
"GET",
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import NativeListener from 'react-native-listener';
|
||||
import ModSearch from './search/ModSearch.jsx';
|
||||
import ModUpload from "./ModUpload.jsx";
|
||||
import ModManager from "./ModManager.jsx";
|
||||
@ -49,6 +50,14 @@ class ModOverview extends React.Component {
|
||||
<div className="box-header" data-widget="collapse" style={{cursor: "pointer"}}>
|
||||
<i className="fa fa-plus"></i>
|
||||
<h3 className="box-title">Add Mod</h3>
|
||||
{this.props.logged_in ?
|
||||
<div className="box-tools pull-right">
|
||||
<NativeListener onClick={this.props.factorioLogoutHandler}>
|
||||
<button className="btn btn-box-tool btn-danger" style={{color: "#fff"}}>Logout
|
||||
</button>
|
||||
</NativeListener>
|
||||
</div>
|
||||
: null}
|
||||
</div>
|
||||
|
||||
<ModSearch
|
||||
@ -104,6 +113,7 @@ ModOverview.propTypes = {
|
||||
updateMod: React.PropTypes.func.isRequired,
|
||||
uploadModSuccessHandler: React.PropTypes.func.isRequired,
|
||||
logged_in: React.PropTypes.bool.isRequired,
|
||||
factorioLogoutHandler: React.PropTypes.func.isRequired,
|
||||
|
||||
modContentClass: instanceOfModsContent.isRequired,
|
||||
};
|
||||
|
@ -16,6 +16,7 @@ class ModsContent extends React.Component {
|
||||
this.deleteModHandler = this.deleteModHandler.bind(this);
|
||||
this.updateModHandler = this.updateModHandler.bind(this);
|
||||
this.uploadModSuccessHandler = this.uploadModSuccessHandler.bind(this);
|
||||
this.factorioLogoutHandler = this.factorioLogoutHandler.bind(this);
|
||||
|
||||
this.state = {
|
||||
logged_in: false,
|
||||
@ -89,6 +90,31 @@ class ModsContent extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
factorioLogoutHandler(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
let this_class = this;
|
||||
|
||||
$.ajax({
|
||||
url: "/api/mods/factorio/logout",
|
||||
method: "POST",
|
||||
dataType: "JSON",
|
||||
success: (data) => {
|
||||
this_class.setState({
|
||||
logged_in: data.data
|
||||
})
|
||||
},
|
||||
error: (jqXHR) => {
|
||||
swal({
|
||||
title: "error logging out of factorio",
|
||||
text: jqXHR.responseJSON.data,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
loadDownloadListSwalHandler() {
|
||||
let $checked_input = $('input[name=version]:checked');
|
||||
let link = $checked_input.data("link");
|
||||
@ -374,6 +400,7 @@ class ModsContent extends React.Component {
|
||||
updateMod={this.updateModHandler}
|
||||
uploadModSuccessHandler={this.uploadModSuccessHandler}
|
||||
modContentClass={this}
|
||||
factorioLogoutHandler={this.factorioLogoutHandler}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user