1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-12 21:22:28 +01:00

Implement email domain restriction option in env template and SetupController

This commit is contained in:
Chaoyi Zha 2017-03-25 15:59:42 -04:00
parent 44f69c3910
commit 7e0d404c72
6 changed files with 46 additions and 30 deletions

View File

@ -22,7 +22,7 @@ class SetupController extends Controller {
private static function setupAlreadyRan() {
return view('error', [
'message' => 'Sorry, but you have already ran the setup script previously.'
'message' => 'Sorry, but you have already completed the setup process.'
]);
}
@ -112,8 +112,8 @@ class SetupController extends Controller {
$st_index_redirect = $request->input('setting:index_redirect');
$st_redirect_404 = $request->input('setting:redirect_404');
$st_password_recov = $request->input('setting:password_recovery');
$st_specify_email = $request->input('setting:specify_email')
$st_allowed_email = $request->input('setting:allowed_email_domains')
$st_restrict_email_domain = $request->input('setting:restrict_email_domain');
$st_allowed_email_domains = $request->input('setting:allowed_email_domains');
$st_base = $request->input('setting:base');
$st_auto_api_key = $request->input('setting:auto_api_key');
@ -157,8 +157,8 @@ class SetupController extends Controller {
'ST_INDEX_REDIRECT' => $st_index_redirect,
'ST_REDIRECT_404' => $st_redirect_404,
'ST_PASSWORD_RECOV' => $st_password_recov,
'ST_SPECIFY_EMAIL' => $st_specify_email,
'ST_ALLOWED_EMAIL' => $st_allowed_email,
'ST_RESTRICT_EMAIL_DOMAIN' => $st_restrict_email_domain,
'ST_ALLOWED_EMAIL_DOMAINS' => $st_allowed_email_domains,
'MAIL_ENABLED' => $mail_enabled,
'MAIL_HOST' => $mail_host,

View File

@ -67,12 +67,13 @@ class UserController extends Controller {
$username = $request->input('username');
$password = $request->input('password');
$email = $request->input('email');
$email_domain = explode("@", $email)[1];
if (env('ST_RESTRICT_EMAIL_DOMAIN')) {
if ($email_domain != env('ST_RESTRICT_EMAIL_DOMAIN_NAME')) {
// ... throw an error
return redirect(route('signup'))->with('error', 'Sorry, your email domain is not allowed to register. Try again.');
if (env('SETTING_RESTRICT_EMAIL_DOMAIN')) {
$email_domain = explode('@', $email)[1];
$permitted_email_domains = explode(',', env('SETTING_ALLOWED_EMAIL_DOMAINS'));
if (!in_array($email_domain, $permitted_email_domains)) {
return redirect(route('signup'))->with('error', 'Sorry, your email\'s domain is not permitted to create new accounts.');
}
}

14
public/js/SetupCtrl.js Normal file
View File

@ -0,0 +1,14 @@
polr.controller('SetupCtrl', function($scope) {
$scope.settings = {
restrictEmailDomain: false
};
$scope.init = function () {
$('[data-toggle="popover"]').popover({
trigger: "hover",
placement: "right"
});
};
$scope.init();
});

View File

@ -1,6 +0,0 @@
$(function () {
$('[data-toggle="popover"]').popover({
trigger: "hover",
placement: "right"
});
});

View File

@ -77,6 +77,12 @@ SETTING_PSEUDORANDOM_ENDING={{$ST_PSEUDOR_ENDING}}
# Set to true to record advanced analytics
SETTING_ADV_ANALYTICS={{$ST_ADV_ANALYTICS}}
# Set to true to restrict registration to a specific email domain
SETTING_RESTRICT_EMAIL_DOMAIN={{$ST_RESTRICT_EMAIL_DOMAIN}}
# A comma-separated list of permitted email domains
SETTING_ALLOWED_EMAIL_DOMAINS={{$ST_ALLOWED_EMAIL_DOMAINS}}
# Set each to blank to disable mail
@if($MAIL_ENABLED)
MAIL_DRIVER=smtp

View File

@ -14,7 +14,7 @@ Setup
<a class="navbar-brand" href="/">Polr</a>
</div>
<div class='row'>
<div class="row" ng-controller="SetupCtrl" class="ng-root">
<div class='col-md-3'></div>
<div class='col-md-6 setup-body well'>
@ -175,21 +175,20 @@ Setup
</select>
<p>
Specify Email Domain:
<button data-content="Specifying the email will allow you to limit who is able to register." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
Restrict Registration Email Domains:
<button data-content="Restrict registration to certain email domains." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
</p>
<select name='setting:specify_email' class='form-control'>
<option value='false'>Specify email disabled</option>
<option value='true'>Specify email enabled</option>
<select name='setting:restrict_email_domain' class='form-control'>
<option value='false'>Allow any email domain to register</option>
<option value='true'>Restrict email domains allowed to register</option>
</select>
<p class='text-muted'>
Please ensure if you choose to limit to a specific email domain that the domain is properly setup.
</p>
<p>
Email Domain:
<button data-content="Enter the domain of the emails you'd like to be able to register." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
Permitted Email Domains:
<button data-content="A comma-separated list of emails permitted to register." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
</p>
<input type='text' class='form-control' name='setting:allowed_email_domains' placeholder='gmail.com'>
<input type='text' class='form-control' name='setting:allowed_email_domains' placeholder='company.com,company-corp.com'>
<p>
Password Recovery:
<button data-content="Password recovery allows users to reset their password through email." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
@ -252,5 +251,7 @@ Setup
@section('js')
<script src="/js/bootstrap.min.js"></script>
<script src='/js/setup.js'></script>
<script src='/js/angular.min.js'></script>
<script src='/js/base.js'></script>
<script src='/js/SetupCtrl.js'></script>
@endsection