-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
434 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ APP_URL=http://localhost | |
SEED_ADMIN_EMAIL=[email protected] | ||
SEED_ADMIN_PASSWORD=admin_user | ||
|
||
SEED_NEWS_EDITOR_EMAIL="[email protected]" | ||
SEED_NEWS_EDITOR_EMAIL="user+[email protected]" | ||
SEED_NEWS_EDITOR_PASSWORD="news_editor" | ||
|
||
SEED_EVENT_EDITOR_EMAIL="[email protected]" | ||
SEED_EVENT_EDITOR_EMAIL="user+[email protected]" | ||
SEED_EVENT_EDITOR_PASSWORD="events_editor" | ||
|
||
SEED_USER_EMAIL=[email protected] | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Laravel Push Test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
laravel-tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e | ||
with: | ||
php-version: '8.0' | ||
- uses: actions/checkout@v2 | ||
- name: Copy .env | ||
run: php -r "file_exists('.env') || copy('.env.example', '.env');" | ||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
- name: Generate key | ||
run: php artisan key:generate | ||
- name: Directory Permissions | ||
run: chmod -R 777 storage bootstrap/cache | ||
- name: Create Database | ||
run: | | ||
mkdir -p database | ||
touch database/database.sqlite | ||
- name: Execute tests (Unit and Feature tests) via PHPUnit | ||
env: | ||
DB_CONNECTION: sqlite | ||
DB_DATABASE: database/database.sqlite | ||
run: | | ||
php artisan test -p --colors --debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Auth\Middleware\RequirePassword; | ||
|
||
class CustomRequirePassword extends RequirePassword | ||
{ | ||
|
||
|
||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @param string|null $redirectToRoute | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next, $redirectToRoute = null) | ||
{ | ||
// Skip password confirmation in the test environment | ||
if (app()->environment('testing')) { | ||
return $next($request); | ||
} | ||
|
||
// Should ask only if user has password = not signed in with providers | ||
$hasPassword = $this->hasPassword($request); | ||
if ($hasPassword) { | ||
return parent::handle($request, $next, $redirectToRoute); | ||
} | ||
return $next($request); | ||
} | ||
|
||
protected function hasPassword($request) | ||
{ | ||
return (!in_array($request->user()->provider, ['google'])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Rules; | ||
|
||
use Illuminate\Contracts\Validation\Rule; | ||
use App\Services\DepartmentDataService; | ||
|
||
class ValidateAsInternalEmail implements Rule | ||
{ | ||
/** | ||
* Create a new rule instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
// Skip email validator in unit testing, to save time | ||
if (app()->environment() == 'testing') return true; | ||
$api = new DepartmentDataService(); | ||
return $api->isInternalEmail($value); | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
return "Only Department of Computer Engineering students/staff are allowed to register by themselves."; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class DepartmentDataService | ||
{ | ||
public function isInternalEmail($userEmail) | ||
{ | ||
$emails = Cache::remember( | ||
'dept_service_user_emails', | ||
config('constants.department_data.cache_duration'), | ||
function () { | ||
|
||
// Students | ||
$students = $this->getData('/people/v1/students/all/'); | ||
$student_emails = collect($students)->map(function ($user) { | ||
$faculty_name = $user['emails']['faculty']['name']; | ||
$faculty_domain = $user['emails']['faculty']['domain']; | ||
|
||
$personal_name = $user['emails']['faculty']['name']; | ||
$personal_domain = $user['emails']['faculty']['domain']; | ||
|
||
if ($faculty_domain == 'eng.pdn.ac.lk' && $faculty_name != '' && $faculty_domain != '') { | ||
// Faculty Email | ||
return "$faculty_name@$faculty_domain"; | ||
} else if ($personal_domain == 'eng.pdn.ac.lk') { | ||
// Personal Email | ||
return "$personal_name@$personal_domain"; | ||
} | ||
return null; | ||
}); | ||
|
||
// Staff | ||
$staff = $this->getData('/people/v1/staff/all/'); | ||
$staff_emails = collect($staff)->map(function ($user) { | ||
return $user['email']; | ||
}); | ||
|
||
return $student_emails->union($staff_emails)->filter()->values()->toArray(); | ||
} | ||
); | ||
return in_array($userEmail, $emails); | ||
} | ||
|
||
private function getData($endpoint) | ||
{ | ||
$url = config('constants.department_data.base_url') . $endpoint; | ||
$response = Http::get($url); | ||
|
||
if ($response->successful()) { | ||
return $response->json(); | ||
} else { | ||
$statusCode = $response->status(); | ||
$errorMessage = $response->body(); | ||
|
||
Log::error('Error in getData: ' . $errorMessage); | ||
return []; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,4 +162,4 @@ | |
| | ||
*/ | ||
'testing' => env('APP_TESTING', false), | ||
]; | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.