Skip to content

Commit

Permalink
Prevent signups with env var
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ngr31 committed Sep 19, 2020
1 parent 490e91b commit cec1569
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</svg>
</p>

Current version: **1.0-beta3**
Current version: **1.0-beta4**

## About
The idea for this app came from using my Hobonichi Techo planner every morning to write down what I needed to accomplish that day & using it for scratching down random thoughts and notes as the day went on. The closest thing I've seen to an app for replacing this system is Noteplan, but I don't use a Mac or an iOS device, and it's not self-hostable, so I decided to write my own.
Expand Down Expand Up @@ -47,9 +47,10 @@ The recommended way of running is to pull the image from [Docker Hub](https://hu
#### Environment Variables
| Environment Variable | Description | Default |
|---|---|---|
| API_SECRET_KEY | Used to sign API tokens. | Will be generated automatically if not passed in. |
| API_SECRET_KEY | Used to sign API tokens. | Will be generated automatically if not passed in. |
| DATABASE_URI | Connection string for DB. | Will create and use a SQLite DB if not passed in. |
| DB_ENCRYPTION_KEY | Secret key for encrypting data. Length must be a multiple of 16.<br><br>*Warning*: If changed data will not be able to be decrypted! | Will be generated automatically if not passed in. |
| PREVENT_SIGNUPS | Disable signup form? Anything in this variable will prevent signups. | |


#### Volumes
Expand Down
3 changes: 3 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

@app.route('/api/sign-up', methods=['POST'])
def sign_up():
if app.config['PREVENT_SIGNUPS']:
abort(400)

req = request.get_json()
username = req.get('username')
password = req.get('password')
Expand Down
47 changes: 33 additions & 14 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@types/codemirror": "0.0.82",
"@types/jest": "^24.0.19",
"@types/lodash": "^4.14.149",
"@types/node": "^14.11.1",
"@vue/cli-plugin-eslint": "^4.1.0",
"@vue/cli-plugin-router": "^4.1.0",
"@vue/cli-plugin-typescript": "^4.1.0",
Expand Down
7 changes: 5 additions & 2 deletions client/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<b-input placeholder="Password" type="password" password-reveal size="is-medium" icon="key" v-model="password" @keyup.native.enter="login"></b-input>
</b-field>
<b-button type="is-primary" size="is-medium" expanded class="mt-20" @click="login" :loading="isLoading">Login</b-button>
<h1 class="mt-20 alt-button" @click="signup">Sign Up</h1>
<h1 class="mt-20 alt-button" @click="signup" v-if="!hideSignup">Sign Up</h1>
</div>
</div>
</template>
Expand All @@ -21,6 +21,7 @@ import Component from 'vue-class-component';
import {Requests} from '../services/requests';
import {setToken} from '../services/user';
declare var process: any;
@Component({
metaInfo: {
Expand All @@ -38,6 +39,8 @@ export default class Login extends Vue {
public isLoading: boolean = false;
public hideSignup = process.env.VUE_APP_PREVENT_SIGNUPS ? true : false;
public signup() {
this.$router.push({name: 'Sign Up'});
}
Expand Down Expand Up @@ -91,4 +94,4 @@ export default class Login extends Vue {
this.isLoading = false;
}
}
</script>
</script>
9 changes: 9 additions & 0 deletions client/src/views/Signup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Component from 'vue-class-component';
import {Requests} from '../services/requests';
import {setToken} from '../services/user';
declare var process: any;
@Component({
metaInfo: {
Expand All @@ -44,6 +45,14 @@ export default class Signup extends Vue {
public isLoading: boolean = false;
public hideSignup = process.env.VUE_APP_PREVENT_SIGNUPS ? true : false;
mounted() {
if (this.hideSignup) {
this.$router.push({name: 'Login'});
}
}
public login() {
this.$router.push({name: 'Login'});
}
Expand Down
2 changes: 2 additions & 0 deletions client/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var webpack = require('webpack');
var path = require('path');

process.env.VUE_APP_PREVENT_SIGNUPS = process.env.PREVENT_SIGNUPS ? true : '';

module.exports = {
lintOnSave: false,
outputDir: path.resolve(__dirname, '../dist'),
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class Config(object):
JWT_SECRET_KEY = os.environ.get('API_SECRET_KEY')
DB_ENCRYPTION_KEY = os.environ.get('DB_ENCRYPTION_KEY')
PREVENT_SIGNUPS = os.environ.get('PREVENT_SIGNUPS', False)
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI') or 'sqlite:///' + os.path.join(basedir + '/config', 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(days=7)

0 comments on commit cec1569

Please sign in to comment.