Skip to content

Commit 4851098

Browse files
authored
Merge pull request #317 from SISheogorath/master+allowEmailRegister
Add `allowemailregister` option
2 parents 8b378d7 + 747629e commit 4851098

5 files changed

Lines changed: 35 additions & 28 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ Environment variables (will overwrite other server configs)
150150
| HMD_LDAP_TLS_CA | no example | Root CA for LDAP TLS in PEM format |
151151
| HMD_LDAP_PROVIDERNAME | My institution | Optional name to be displayed at login form indicating the LDAP provider |
152152
| HMD_IMGUR_CLIENTID | no example | Imgur API client id |
153-
| HMD_EMAIL | `true` or `false` | set to allow email register and signin |
153+
| HMD_EMAIL | `true` or `false` | set to allow email signin |
154+
| HMD_ALLOW_EMAIL_REGISTER | `true` or `false` | set to allow email register |
154155
| HMD_IMAGE_UPLOAD_TYPE | `imgur`, `s3` or `filesystem` | Where to upload image. For S3, see our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) |
155156
| HMD_S3_ACCESS_KEY_ID | no example | AWS access key id |
156157
| HMD_S3_SECRET_ACCESS_KEY | no example | AWS secret key |
@@ -194,7 +195,8 @@ Server settings `config.json`
194195
| heartbeatinterval | `5000` | socket.io heartbeat interval |
195196
| heartbeattimeout | `10000` | socket.io heartbeat timeout |
196197
| documentmaxlength | `100000` | note max length |
197-
| email | `true` or `false` | set to allow email register and signin |
198+
| email | `true` or `false` | set to allow email signin |
199+
| allowemailregister | `true` or `false` | set to allow email register |
198200
| imageUploadType | `imgur`(default), `s3` or `filesystem` | Where to upload image
199201
| s3 | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION", "bucket": "YOUR_S3_BUCKET_NAME" }` | When `imageUploadType` be setted to `s3`, you would also need to setup this key, check our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) |
200202

app.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -395,34 +395,36 @@ if (config.ldap) {
395395
}
396396
// email auth
397397
if (config.email) {
398-
app.post('/register', urlencodedParser, function (req, res, next) {
399-
if (!req.body.email || !req.body.password) return response.errorBadRequest(res);
400-
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(res);
401-
models.User.findOrCreate({
402-
where: {
403-
email: req.body.email
404-
},
405-
defaults: {
406-
password: req.body.password
407-
}
408-
}).spread(function (user, created) {
409-
if (user) {
410-
if (created) {
411-
if (config.debug) logger.info('user registered: ' + user.id);
412-
req.flash('info', "You've successfully registered, please signin.");
413-
} else {
414-
if (config.debug) logger.info('user found: ' + user.id);
415-
req.flash('error', "This email has been used, please try another one.");
398+
if (config.allowemailregister)
399+
app.post('/register', urlencodedParser, function (req, res, next) {
400+
if (!req.body.email || !req.body.password) return response.errorBadRequest(res);
401+
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(res);
402+
models.User.findOrCreate({
403+
where: {
404+
email: req.body.email
405+
},
406+
defaults: {
407+
password: req.body.password
408+
}
409+
}).spread(function (user, created) {
410+
if (user) {
411+
if (created) {
412+
if (config.debug) logger.info('user registered: ' + user.id);
413+
req.flash('info', "You've successfully registered, please signin.");
414+
} else {
415+
if (config.debug) logger.info('user found: ' + user.id);
416+
req.flash('error', "This email has been used, please try another one.");
417+
}
418+
return res.redirect(config.serverurl + '/');
416419
}
420+
req.flash('error', "Failed to register your account, please try again.");
417421
return res.redirect(config.serverurl + '/');
418-
}
419-
req.flash('error', "Failed to register your account, please try again.");
420-
return res.redirect(config.serverurl + '/');
421-
}).catch(function (err) {
422-
logger.error('auth callback failed: ' + err);
423-
return response.errorInternalError(res);
422+
}).catch(function (err) {
423+
logger.error('auth callback failed: ' + err);
424+
return response.errorInternalError(res);
425+
});
424426
});
425-
});
427+
426428
app.post('/login', urlencodedParser, function (req, res, next) {
427429
if (!req.body.email || !req.body.password) return response.errorBadRequest(res);
428430
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(res);

lib/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ if (process.env.HMD_LDAP_PROVIDERNAME) {
132132
}
133133
var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false;
134134
var email = process.env.HMD_EMAIL ? (process.env.HMD_EMAIL === 'true') : !!config.email;
135+
var allowemailregister = process.env.HMD_ALLOW_EMAIL_REGISTER ? (process.env.HMD_HMD_ALLOW_EMAIL_REGISTER === 'true') : !!config.allowemailregister;
135136

136137
function getserverurl() {
137138
var url = '';
@@ -194,6 +195,7 @@ module.exports = {
194195
ldap: ldap,
195196
imgur: imgur,
196197
email: email,
198+
allowemailregister: allowemailregister,
197199
imageUploadType: imageUploadType,
198200
s3: s3,
199201
s3bucket: s3bucket

lib/response.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function showIndex(req, res, next) {
6868
google: config.google,
6969
ldap: config.ldap,
7070
email: config.email,
71+
allowemailregister: config.allowemailregister,
7172
signin: req.isAuthenticated(),
7273
infoMessage: req.flash('info'),
7374
errorMessage: req.flash('error')

public/views/signin-modal.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<div class="form-group">
8585
<div class="col-sm-12">
8686
<button type="submit" class="btn btn-primary" formaction="<%- url %>/login">Sign in</button>
87-
<button type="submit" class="btn btn-default" formaction="<%- url %>/register">Register</button>
87+
<% if(allowemailregister) { %><button type="submit" class="btn btn-default" formaction="<%- url %>/register">Register</button><% }%>
8888
</div>
8989
</div>
9090
</form>

0 commit comments

Comments
 (0)