Skip to content

Commit

Permalink
Implemented option to disable registration
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidblue committed Nov 19, 2017
1 parent f0a9fa8 commit 125e7c3
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions INSTALL.md
Expand Up @@ -56,6 +56,8 @@ Save your configuration to a file, e.g. config.json:
"mail": "noreply@example.com",
"domain": "www.example.com",

"registrationEnabled": true,

"verbose": false
}

Expand Down
8 changes: 8 additions & 0 deletions src/css/front/frontpage.scss
Expand Up @@ -56,6 +56,14 @@
text-align: justify;
}

#register
{
.registrationClosed
{
text-align: center;
}
}

#frontpage
{
.logo
Expand Down
2 changes: 2 additions & 0 deletions src/html/pages/front/tabs/register.htm
Expand Up @@ -30,4 +30,6 @@
<button type="submit" id="registerButton" class="btn btn-success btnWide pull-right">Register</button>

<button type="submit" id="resetButton" class="btn btn-danger btnWide pull-right hide">Reset</button>

<div class="registrationClosed hide"></div>
</form>
3 changes: 3 additions & 0 deletions src/html/text.htm
Expand Up @@ -166,4 +166,7 @@
<div class="inactivity">
You have been logged out, because you were inactive for %1 minutes.
</div>
<div class="registrationClosed">
The registration is currently closed.
</div>
</div>
7 changes: 7 additions & 0 deletions src/js/client/core/user.coffee
Expand Up @@ -17,6 +17,12 @@ credentials =
session: null
password: null

features = (callback) ->
# Send command to server
command.send
cmd: "user.features"
callback: callback

create = (email, password, passwordHint, callback) ->
# Create key from password and email address as salt.
# This key is salted and hashed again on the server, using a random salt.
Expand Down Expand Up @@ -153,6 +159,7 @@ getPassword = ->

return credentials.password

module.exports.features = features
module.exports.create = create
module.exports.updateEmail = updateEmail
module.exports.updatePassword = updatePassword
Expand Down
12 changes: 12 additions & 0 deletions src/js/client/gui/front/register.coffee
Expand Up @@ -125,5 +125,17 @@ init = ->
register()
return

core.user.features (response) ->
if response.status == "success"
if !response.registration
# Disable registration
$("#register > .itemField").hide()
$("#register > .btn").hide()

# Show registration closed message
infoBox = $("#register > .registrationClosed")
infoBox.text global.text.get("registrationClosed")
infoBox.removeClass("hide")

module.exports.init = init
module.exports.validate = validate
2 changes: 1 addition & 1 deletion src/js/client/index.coffee
Expand Up @@ -20,6 +20,6 @@ core = require "./core"

# Initialize GUI when DOM is ready
$(document).ready ->
gui.init()
core.init()
gui.init()
return
2 changes: 2 additions & 0 deletions src/js/server/command.coffee
Expand Up @@ -21,6 +21,8 @@ process = (clientID, params, callback) ->
callback(result)

switch params.cmd
when "user.features"
user.features(callback)
when "user.create"
user.create(params.data.email, params.data.key, params.data.passwordHint, callback)
when "user.login"
Expand Down
2 changes: 2 additions & 0 deletions src/js/server/config.coffee
Expand Up @@ -30,6 +30,8 @@ defaultConfig =
mail: "noreply@example.com"
domain: "www.example.com"

registrationEnabled: true

verbose: false

get = ->
Expand Down
13 changes: 13 additions & 0 deletions src/js/server/user.coffee
Expand Up @@ -13,7 +13,19 @@ log = require "./log"
item = require "./item"
shared = require "./shared"

features = (callback) ->
callback
status: "success"
registration: config.get().registrationEnabled

create = (email, key, passwordHint, callback) ->
# Check if registration is enabled on the server
if !config.get().registrationEnabled
callback
status: "invalidcommand"

return

# Validate email and passwordHint
if !shared.validation.email(email) || !shared.validation.passwordHint(passwordHint)
callback
Expand Down Expand Up @@ -402,6 +414,7 @@ sendPasswordHint = (email, callback) ->
callback
status: "success"

module.exports.features = features
module.exports.create = create
module.exports.update = update
module.exports.reset = reset
Expand Down

0 comments on commit 125e7c3

Please sign in to comment.