Skip to content

Commit

Permalink
Merge pull request #17 from vickzkater/v2.0.3
Browse files Browse the repository at this point in the history
V2.0.3
  • Loading branch information
vickzkater authored Sep 16, 2020
2 parents f5067f7 + 7d55213 commit 6f9c070
Show file tree
Hide file tree
Showing 31 changed files with 1,245 additions and 603 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

MAIL_FROM_NAME="Lara-S-CMS (no-reply)"
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_ADDRESS=[email protected]

MAIL_REPLYTO_NAME="Lara-S-CMS (contact)"
MAIL_REPLYTO_ADDRESS="[email protected]"
MAIL_REPLYTO_ADDRESS=[email protected]

MAIL_CONTACT_NAME="Lara-S-CMS (contact)"
MAIL_CONTACT_ADDRESS="[email protected]"
MAIL_CONTACT_ADDRESS=[email protected]

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Developed by [@vickzkater](https://github.com/vickzkater/) (Powered by [KINIDI T
- [x] Support Session Driver Database (please check section `Session Driver Database`)
- [x] Security update: if password has been changed, then force user to re-login
- [x] Feature logout from all sessions
- [x] Sample function sending email & email template (HTML & Plain Text)

## Admin Panel

Expand All @@ -77,6 +78,8 @@ Developed by [@vickzkater](https://github.com/vickzkater/) (Powered by [KINIDI T

## Version

***Current Version: 2.0.3 (Laravel 7.28.2)**

Laravel | Lara-S-CMS
:---------|:----------
5.8.x | 1.0 ; 1.1.0
Expand Down
8 changes: 8 additions & 0 deletions VERSION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Version 2.0.3
### Changelog
- Update validation redirection URL after login in Admin (if AJAX DataTables, set URL to Admin Home page as default)
- Add Dev Function to test sending email
- Add email template & function sending email as sample
- Update migrations & seeders for add rules automatically
- Update the packages (Laravel Frameword 7.18.0 > 7.28.2)

## Version 2.0.2
### Changelog
- Update minor in MailchimpHelper
Expand Down
118 changes: 81 additions & 37 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,55 @@ public function __construct()
});
}

/**
* Guzzle GET Public Access (without token Authorization Bearer)
*
* @param String $url (Target API URL) required
* @param Array $auth (htaccess auth) optional
*
* @return Object (API Response)
*/
protected function guzzle_get_public($url, $auth = null)
{
$config = ['http_errors' => false];
if (env('APP_DEBUG')) {
$config['verify'] = false;
}
if ($auth) {
$config['auth'] = $auth;
}
$client = new Client($config);
$request = $client->request('GET', $url);
$response = $request->getBody();

return json_decode($response);
}

/**
* Guzzle POST Public Access (without token Authorization Bearer)
*
* @param String $url (Target API URL) required
* @param Array $parameter (Paramaters) required
* @param Array $auth (htaccess auth) optional
*
* @return Object (API Response)
*/
protected function guzzle_post_public($url, $parameter, $auth = null)
{
$config = ['http_errors' => false];
if (env('APP_DEBUG')) {
$config['verify'] = false;
}
if ($auth) {
$config['auth'] = $auth;
}
$client = new Client($config);
$request = $client->request('POST', $url, ['form_params' => $parameter]);
$response = $request->getBody()->getContents();

return json_decode($response);
}

/**
* Guzzle GET with token Authorization Bearer
*
Expand Down Expand Up @@ -204,51 +253,46 @@ protected function guzzle_post($url, $token, $parameter, $auth = null)
}

/**
* Guzzle GET Public Access (without token Authorization Bearer)
*
* @param String $url (Target API URL) required
* @param Array $auth (htaccess auth) optional
*
* @return Object (API Response)
*/
protected function guzzle_get_public($url, $auth = null)
{
$config = ['http_errors' => false];
if (env('APP_DEBUG')) {
$config['verify'] = false;
}
if ($auth) {
$config['auth'] = $auth;
}
$client = new Client($config);
$request = $client->request('GET', $url);
$response = $request->getBody();

return json_decode($response);
}

/**
* Guzzle POST Public Access (without token Authorization Bearer)
* Guzzle POST file with token Authorization Bearer
*
* @param String $url (Target API URL) required
* @param String $token (Token Authorization Bearer) required
* @param Array $parameter (Paramaters) required
* @param Array $auth (htaccess auth) optional
*
* @return Object (API Response)
*/
protected function guzzle_post_public($url, $parameter, $auth = null)
// *Sample:
// // Set params
// $params = [
// [
// 'name' => 'user_id',
// 'contents' => $user_id
// ],
// [
// 'name' => 'avatar',
// 'contents' => fopen($request->file('avatar')->getRealPath(), "r"),
// 'filename' => $request->file('avatar')->hashName()
// ]
// ];
protected function guzzle_post_multipart($url, $token, $parameter, $auth = null)
{
$config = ['http_errors' => false];
if (env('APP_DEBUG')) {
$config['verify'] = false;
}
if ($auth) {
$config['auth'] = $auth;
}
$client = new Client($config);
$request = $client->request('POST', $url, ['form_params' => $parameter]);
$response = $request->getBody()->getContents();
if (empty($token)) {
return 'Unauthorized';
} else {
$config = ['http_errors' => false];
if (env('APP_DEBUG')) {
$config['verify'] = false;
}
if ($auth) {
$config['auth'] = $auth;
}
$client = new Client($config);
$headers = array('Authorization' => 'bearer ' . $token);
$request = $client->request('POST', $url, ['headers' => $headers, 'multipart' => $parameter]);
$response = $request->getBody()->getContents();

return json_decode($response);
return json_decode($response);
}
}
}
33 changes: 21 additions & 12 deletions app/Http/Controllers/DevController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

// MAIL
use App\Mail\MailTester;

// USE LIBRARIES
use App\Libraries\GoSms;
use App\Libraries\MailchimpHelper;

// MODELS
use App\Models\system\SysUser;

class DevController extends Controller
{
/**
Expand Down Expand Up @@ -94,35 +101,37 @@ public function mailchimp_view_tags_in_contact(Request $request)
dd($result);
}

/**
* EMAIL
*/
/**
* EMAIL
*/
public function email_send(Request $request)
{
// GET THE DATA
$data = '';
// SET THE DATA
$data = SysUser::find(1);

// SET EMAIL SUBJECT
$subject_email = '';
$subject_email = 'Test Send Email';

$email_address = $request->email;
if (!$email_address) {
// rendering email in browser
// return (new SyllabusRequest($data, $subject_email))->render();
if ($request->send && !$email_address) {
return 'Must set email as recipient in param email';
}

try {
// SEND EMAIL
// Mail::to($email_address)->send(new SyllabusRequest($data, $subject_email));
if ($request->send) {
// send email using SMTP
Mail::to($email_address)->send(new MailTester($data, $subject_email));
} else {
// rendering email in browser
return (new MailTester($data, $subject_email))->render();
}
} catch (\Exception $e) {
// Debug via $e->getMessage();
dd($e->getMessage());
return "We've got errors!";
// return "We've got errors!";
}

dd('Successfully sent email to ' . $email_address);
return 'Successfully sent email to ' . $email_address;
}
}
6 changes: 6 additions & 0 deletions app/Http/Middleware/CheckAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public function handle($request, Closure $next)
return $next($request);
} else {
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if (strpos($actual_link, '/get-data') !== false) {
// FOUND
$actual_link = route('admin.home');
}

Session::put('redirect_uri', $actual_link);

if ($actual_link == route('admin.home')) {
Expand Down
8 changes: 6 additions & 2 deletions app/Libraries/TheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public static function validate_input_text($string, $htmlspecialchars = false, $
if ($string == '' || !$string) {
return null;
}
$val = filter_var($string, FILTER_SANITIZE_ADD_SLASHES);
if (version_compare(PHP_VERSION, '7.4.0') >= 0) {
$val = filter_var($string, FILTER_SANITIZE_ADD_SLASHES);
} else {
$val = filter_var($string, FILTER_SANITIZE_MAGIC_QUOTES);
}
if ($no_backslash) {
$val = stripslashes($val);
}
Expand Down Expand Up @@ -640,7 +644,7 @@ public static function get_family_name($fullname, $default_lastname = null)
$arr_names = explode(' ', $fullname);
if (count($arr_names) == 1) {
$lastname = $arr_names[0];
if($default_lastname){
if ($default_lastname) {
$lastname = $default_lastname;
}
$firstname = $arr_names[0];
Expand Down
53 changes: 53 additions & 0 deletions app/Mail/MailTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

// Model
use App\Models\system\SysUser;

class MailTester extends Mailable
{
use Queueable, SerializesModels;

/**
* The user instance.
*
* @var User
*/
public $user;

public $subject;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(SysUser $sys_user, $subject)
{
$this->user = $sys_user;
$this->subject = $subject;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject($this->subject)
->view('emails.tester')
->text('emails.tester_plain')
->with([
'subject' => $this->subject,
'name' => $this->user->name,
'action_url' => route('web.home')
]);
}
}
Loading

0 comments on commit 6f9c070

Please sign in to comment.