Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new feature] Password page #92

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/AdminPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class AdminPage extends Component {
content = (<div className="admin-section-title"> You are authorized to move/delete files. </div>)
}else{
content = (<React.Fragment>
<div className="admin-section-title">Type password to move/delete file </div>
<div className="admin-section-title">Enter password to move/delete file </div>
<div className="admin-section-content">
<input className="admin-intput" ref={pathInput => this.passwordInputRef = pathInput}
placeholder="...type here" onChange={this.setPasswordCookie.bind(this)}/>
Expand Down
34 changes: 34 additions & 0 deletions src/client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import screenfull from 'screenfull';
const clientUtil = require("./clientUtil");
const { getSearchInputText } = clientUtil;
import { ToastContainer } from 'react-toastify';
import ReactDOM from 'react-dom';
import Cookie from "js-cookie";
import 'react-toastify/dist/ReactToastify.css';

// http://localhost:3000/
Expand Down Expand Up @@ -102,8 +104,40 @@ class App extends Component {
// You can also log the error to an error reporting service
console.error(error, info);
}

getPasswordInput(){
const pathInput = ReactDOM.findDOMNode(this.passwordInputRef);
const text = (pathInput && pathInput.value) || "";
return text;
}

setPasswordCookie(){
const text = this.getPasswordInput();
Cookie.set("home-password", text, { expires: 3 });
this.forceUpdate();
}

renderPasswordInput(){
let content = (<React.Fragment>
<div className="admin-section-title">Enter password to use Shigureader</div>
<div className="admin-section-content">
<input className="admin-intput" ref={pathInput => this.passwordInputRef = pathInput}
placeholder="...type here" onChange={this.setPasswordCookie.bind(this)}/>
</div>
</React.Fragment>);

return (
<div className="home-admin-section">
{content}
</div>
)
}

render() {
if(!clientUtil.isAllowedToEnter()){
return this.renderPasswordInput();
}

// document.title = this.getWebTitle();
if(this.searchText){
const path = clientUtil.getSearhLink(this.searchText);
Expand Down
11 changes: 11 additions & 0 deletions src/client/clientUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ module.exports.isAuthorized = function(){
}
}

module.exports.isAllowedToEnter = function(){
const userConfig = require('@config/user-config');
if(!userConfig.home_password){
return true;
}

const Cookie = require("js-cookie");
const password = Cookie.get('home-password');
return userConfig.home_password === password;
}

// module.exports.cleanSearchStr = function(str){
// // search/ケマオ9% will break everything
// // it is too troublesome to do everything in url encoding
Expand Down
11 changes: 11 additions & 0 deletions src/client/style/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ a {
}
}
}
}

//https://stackoverflow.com/questions/31217268/center-div-on-the-middle-of-screen
.home-admin-section{
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
width: 300px;
height: 200px;
}
8 changes: 7 additions & 1 deletion src/config/user-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@ module.exports.img_reduce_resolution_dimension = "2800x2800";
//But this may cause more Memory usage
//可以阅读文件夹的图片,就不需要打包成zip
//但可能用很多内存
module.exports.view_img_folder = true;
module.exports.view_img_folder = true;


//global password
//when set, user need to enter password to use ShiguReader
//全局密码,设置以后用户必须输入密码才能打开网站
module.exports.home_password = ""