001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.settings.childSections;
019
020import io.stallion.exceptions.ConfigException;
021import io.stallion.settings.SettingMeta;
022import io.stallion.settings.Settings;
023import io.stallion.users.Role;
024
025import static io.stallion.utils.Literals.*;
026
027public class UserSettings implements SettingsSection {
028    @SettingMeta(val = "/st-users/login")
029    private String loginPage;
030    @SettingMeta(val = "/st-users/reset-password")
031    private String passwordResetPage;
032    @SettingMeta(val = "/st-users/verify-email")
033    private String verifyEmailPage;
034
035    @SettingMeta(valBoolean = true)
036    private Boolean syncAllUsersToMemory;
037
038    @SettingMeta(valInt = 10000)
039    private Integer limitSyncUsersToMemoryToCount;
040
041
042    public String getFullLoginUrl() {
043        String url = getLoginPage();
044        if (url.contains("//")) {
045            url = Settings.instance().getSiteUrl() + url;
046        }
047        return url;
048    }
049
050
051    @SettingMeta(valBoolean = true)
052    private Boolean newAccountsAutoApprove;
053    @SettingMeta(valBoolean = true)
054    private Boolean passwordResetEnabled;
055    @SettingMeta(valBoolean = true)
056    private Boolean enableDefaultEndpoints;
057    @SettingMeta(valBoolean = false)
058    private Boolean newAccountsAllowCreation;
059    @SettingMeta(valBoolean = true)
060    private Boolean newAccountsRequireValidEmail;
061    @SettingMeta(val="MEMBER")
062    private String newAccountsRole;
063    @SettingMeta(val="ANON")
064    private String defaultEndpointRole;
065    @SettingMeta(valBoolean = false)
066    private Boolean allowValetMode;
067
068    @SettingMeta(valBoolean = false)
069    private Boolean disableStLoginParam;
070
071    @SettingMeta(val = "")
072    private String newAccountsDomainRestricted;
073
074    public void postLoad() {
075        if (Role.valueOf(newAccountsRole.toUpperCase())  == null) {
076            throw new ConfigException("Invalid role for stallion.toml settings users.newAccountsRole: " + newAccountsRole);
077        }
078        if (Role.valueOf(defaultEndpointRole.toUpperCase())  == null) {
079            throw new ConfigException("Invalid role for stallion.toml settings users.defaultEndpointRole: " + newAccountsRole);
080        }
081    }
082
083    public String getLoginPage() {
084        if (empty(loginPage)) {
085            return "/st-users/login";
086        }
087        return loginPage;
088    }
089
090    public void setLoginPage(String loginPage) {
091        this.loginPage = loginPage;
092    }
093
094    public Boolean getNewAccountsAutoApprove() {
095        return newAccountsAutoApprove;
096    }
097
098    public void setNewAccountsAutoApprove(Boolean newAccountsAutoApprove) {
099        this.newAccountsAutoApprove = newAccountsAutoApprove;
100    }
101
102    public Boolean getPasswordResetEnabled() {
103        return passwordResetEnabled;
104    }
105
106    public void setPasswordResetEnabled(Boolean passwordResetEnabled) {
107        this.passwordResetEnabled = passwordResetEnabled;
108    }
109
110    public Boolean getEnableDefaultEndpoints() {
111        return enableDefaultEndpoints;
112    }
113
114    public UserSettings setEnableDefaultEndpoints(Boolean enableDefaultEndpoints) {
115        this.enableDefaultEndpoints = enableDefaultEndpoints;
116        return this;
117    }
118
119    public Boolean getNewAccountsAllowCreation() {
120        return newAccountsAllowCreation;
121    }
122
123    public UserSettings setNewAccountsAllowCreation(Boolean newAccountsAllowCreation) {
124        this.newAccountsAllowCreation = newAccountsAllowCreation;
125        return this;
126    }
127
128    public Boolean getNewAccountsRequireValidEmail() {
129        return newAccountsRequireValidEmail;
130    }
131
132    public UserSettings setNewAccountsRequireValidEmail(Boolean newAccountsRequireValidEmail) {
133        this.newAccountsRequireValidEmail = newAccountsRequireValidEmail;
134        return this;
135    }
136
137    public String getNewAccountsRole() {
138        return newAccountsRole;
139    }
140
141    public UserSettings setNewAccountsRole(String newAccountsRole) {
142        this.newAccountsRole = newAccountsRole;
143        return this;
144    }
145
146    public String getNewAccountsDomainRestricted() {
147        return newAccountsDomainRestricted;
148    }
149
150    public UserSettings setNewAccountsDomainRestricted(String newAccountsDomainRestricted) {
151        this.newAccountsDomainRestricted = newAccountsDomainRestricted;
152        return this;
153    }
154
155    public String getPasswordResetPage() {
156        return passwordResetPage;
157    }
158
159    public UserSettings setPasswordResetPage(String passwordResetPage) {
160        this.passwordResetPage = passwordResetPage;
161        return this;
162    }
163
164    public String getVerifyEmailPage() {
165        return verifyEmailPage;
166    }
167
168    public UserSettings setVerifyEmailPage(String verifyEmailPage) {
169        this.verifyEmailPage = verifyEmailPage;
170        return this;
171    }
172
173    public Boolean getSyncAllUsersToMemory() {
174        return syncAllUsersToMemory;
175    }
176
177    public UserSettings setSyncAllUsersToMemory(Boolean syncAllUsersToMemory) {
178        this.syncAllUsersToMemory = syncAllUsersToMemory;
179        return this;
180    }
181
182    public Integer getLimitSyncUsersToMemoryToCount() {
183        return limitSyncUsersToMemoryToCount;
184    }
185
186    public UserSettings setLimitSyncUsersToMemoryToCount(Integer limitSyncUsersToMemoryToCount) {
187        this.limitSyncUsersToMemoryToCount = limitSyncUsersToMemoryToCount;
188        return this;
189    }
190
191
192    public Boolean getAllowValetMode() {
193        return allowValetMode;
194    }
195
196    public UserSettings setAllowValetMode(Boolean allowValetMode) {
197        this.allowValetMode = allowValetMode;
198        return this;
199    }
200
201    public String getDefaultEndpointRole() {
202        return defaultEndpointRole;
203    }
204    public Role getDefaultEndpointRoleObj() {
205        return Role.valueOf(defaultEndpointRole);
206    }
207
208
209    public UserSettings setDefaultEndpointRole(String defaultEndpointRole) {
210        this.defaultEndpointRole = defaultEndpointRole;
211        return this;
212    }
213
214    public Boolean getDisableStLoginParam() {
215        return disableStLoginParam;
216    }
217
218    public UserSettings setDisableStLoginParam(Boolean disableStLoginParam) {
219        this.disableStLoginParam = disableStLoginParam;
220        return this;
221    }
222}