summaryrefslogtreecommitdiffstats
path: root/models/settings.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/settings.js')
-rw-r--r--models/settings.js126
1 files changed, 116 insertions, 10 deletions
diff --git a/models/settings.js b/models/settings.js
index 34f693d9..e0f94fca 100644
--- a/models/settings.js
+++ b/models/settings.js
@@ -28,6 +28,30 @@ Settings.attachSchema(new SimpleSchema({
type: String,
optional: true,
},
+ productName: {
+ type: String,
+ optional: true,
+ },
+ customHTMLafterBodyStart: {
+ type: String,
+ optional: true,
+ },
+ customHTMLbeforeBodyEnd: {
+ type: String,
+ optional: true,
+ },
+ displayAuthenticationMethod: {
+ type: Boolean,
+ optional: true,
+ },
+ defaultAuthenticationMethod: {
+ type: String,
+ optional: false,
+ },
+ hideLogo: {
+ type: Boolean,
+ optional: true,
+ },
createdAt: {
type: Date,
denyUpdate: true,
@@ -66,10 +90,11 @@ if (Meteor.isServer) {
if(!setting){
const now = new Date();
const domain = process.env.ROOT_URL.match(/\/\/(?:www\.)?(.*)?(?:\/)?/)[1];
- const from = `Wekan <wekan@${domain}>`;
+ const from = `Boards Support <support@${domain}>`;
const defaultSetting = {disableRegistration: false, mailServer: {
username: '', password: '', host: '', port: '', enableTLS: false, from,
- }, createdAt: now, modifiedAt: now};
+ }, createdAt: now, modifiedAt: now, displayAuthenticationMethod: true,
+ defaultAuthenticationMethod: 'password'};
Settings.insert(defaultSetting);
}
const newSetting = Settings.findOne();
@@ -96,6 +121,14 @@ if (Meteor.isServer) {
return (min + Math.round(rand * range));
}
+ function getEnvVar(name){
+ const value = process.env[name];
+ if (value){
+ return value;
+ }
+ throw new Meteor.Error(['var-not-exist', `The environment variable ${name} does not exist`]);
+ }
+
function sendInvitationEmail (_id){
const icode = InvitationCodes.findOne(_id);
const author = Users.findOne(Meteor.userId());
@@ -108,6 +141,7 @@ if (Meteor.isServer) {
url: FlowRouter.url('sign-up'),
};
const lang = author.getLanguage();
+
Email.send({
to: icode.email,
from: Accounts.emailTemplates.from,
@@ -120,24 +154,49 @@ if (Meteor.isServer) {
}
}
+ function isLdapEnabled() {
+ return process.env.LDAP_ENABLE === 'true';
+ }
+
+ function isOauth2Enabled() {
+ return process.env.OAUTH2_ENABLED === 'true';
+ }
+
+ function isCasEnabled() {
+ return process.env.CAS_ENABLED === 'true';
+ }
+
Meteor.methods({
sendInvitation(emails, boards) {
check(emails, [String]);
check(boards, [String]);
+
const user = Users.findOne(Meteor.userId());
if(!user.isAdmin){
throw new Meteor.Error('not-allowed');
}
emails.forEach((email) => {
if (email && SimpleSchema.RegEx.Email.test(email)) {
- const code = getRandomNum(100000, 999999);
- InvitationCodes.insert({code, email, boardsToBeInvited: boards, createdAt: new Date(), authorId: Meteor.userId()}, function(err, _id){
- if (!err && _id) {
- sendInvitationEmail(_id);
- } else {
- throw new Meteor.Error('invitation-generated-fail', err.message);
- }
- });
+ // Checks if the email is already link to an account.
+ const userExist = Users.findOne({email});
+ if (userExist){
+ throw new Meteor.Error('user-exist', `The user with the email ${email} has already an account.`);
+ }
+ // Checks if the email is already link to an invitation.
+ const invitation = InvitationCodes.findOne({email});
+ if (invitation){
+ InvitationCodes.update(invitation, {$set : {boardsToBeInvited: boards}});
+ sendInvitationEmail(invitation._id);
+ }else {
+ const code = getRandomNum(100000, 999999);
+ InvitationCodes.insert({code, email, boardsToBeInvited: boards, createdAt: new Date(), authorId: Meteor.userId()}, function(err, _id){
+ if (!err && _id) {
+ sendInvitationEmail(_id);
+ } else {
+ throw new Meteor.Error('invitation-generated-fail', err.message);
+ }
+ });
+ }
}
});
},
@@ -167,5 +226,52 @@ if (Meteor.isServer) {
email: user.emails[0].address,
};
},
+
+ getCustomUI(){
+ const setting = Settings.findOne({});
+ if (!setting.productName) {
+ return {
+ productName: '',
+ };
+ } else {
+ return {
+ productName: `${setting.productName}`,
+ };
+ }
+ },
+
+ getMatomoConf(){
+ return {
+ address: getEnvVar('MATOMO_ADDRESS'),
+ siteId: getEnvVar('MATOMO_SITE_ID'),
+ doNotTrack: process.env.MATOMO_DO_NOT_TRACK || false,
+ withUserName: process.env.MATOMO_WITH_USERNAME || false,
+ };
+ },
+
+ _isLdapEnabled() {
+ return isLdapEnabled();
+ },
+
+ _isOauth2Enabled() {
+ return isOauth2Enabled();
+ },
+
+ _isCasEnabled() {
+ return isCasEnabled();
+ },
+
+ // Gets all connection methods to use it in the Template
+ getAuthenticationsEnabled() {
+ return {
+ ldap: isLdapEnabled(),
+ oauth2: isOauth2Enabled(),
+ cas: isCasEnabled(),
+ };
+ },
+
+ getDefaultAuthenticationMethod() {
+ return process.env.DEFAULT_AUTHENTICATION_METHOD;
+ },
});
}