Skip to content
This repository was archived by the owner on Jul 26, 2019. It is now read-only.

Commit

Permalink
Add send email activation
Browse files Browse the repository at this point in the history
  • Loading branch information
Thabet-Do committed Apr 27, 2019
1 parent 454c24c commit cada7ef
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 176 deletions.
288 changes: 172 additions & 116 deletions .idea/workspace.xml

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions app/Http/Controllers/MailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class MailController extends Controller {

public function basic_email($request) {
$id = $request->id;
$email = $request->email;
$subject = 'Active Your Account In Yes Soft';
$first_name = $request->first_name;

$data = array('name'=>$first_name,'id'=>$id);

Mail::send('mail', $data, function($message) use($email , $subject, $first_name) {
$message
->subject($subject)
->from('[email protected]','Yes Soft')
->to($email, $first_name);
});
echo "Activate Email Sent. Check your inbox.";
}
}
/*class MailController extends Controller {
public function send_active_email() {
// $id = $user->id;
// $first_name = $user->first_name;
$data = array('name'=>'$first_name','id'=> 4);
Mail::send(['text'=>'mail'], $data, function($message) {
// $first_name = $user->first_name;
// $email = $user->email;
$subject = 'Active Your Account';
$message->from(env('MAIL_USERNAME') , 'Yes Soft');
$message->to('$email', '$first_name')->subject($subject);
});
echo "Activate Email Sent. Check your inbox.";
}
}*/
60 changes: 21 additions & 39 deletions app/Http/Controllers/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@

namespace App\Http\Controllers;

use App\Jobs\sendEmailJob;
use App\Mail\sendEmail;
use App\User;
use Cartalyst\Sentinel\Laravel\Facades\Activation;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\MailController;
use Sentinel;
//use Swift;
use Illuminate\Http\Request;

class RegistrationController extends Controller
{
public function register(Request $request)
{
$user = Sentinel::registerAndActivate($request->all());
$this->sendEmail($request->id);
dd($user);
$user = $request->all();


Sentinel::register($request->all());
$email = $user['email'];
$pass = $user['password'];
$credentials = [
'email' => $email,
'password' => $pass
];

$user = Sentinel::findByCredentials($credentials);

(new MailController)->basic_email($user);
}

public function delete(User $user)
Expand All @@ -30,43 +43,12 @@ public function update(Request $request,User $user)
return response($user);
}

public function activate(User $user)
{
#open link with specific id
// return response($user);
}


public function sendEmail(User $user)
public function active(User $user)
{
// require_once 'autoload.php';
// require '../../../vendor/autoload.php';


$id = $user->id;

$email = $user->email;

$subject = 'Active Your Account';

$first_name = $user->first_name;

$msg = "
open link below to active your account
http:/localhost:8000/admin/user/$id/activate";

$headers = [env('MAIL_USERNAME') => 'Yes Soft'];
$user = Sentinel::findById($user->id);
$activation = Activation::create($user);
dd($activation);

/*
// Create the Transport
$transport = (new Swift_SmtpTransport(env('MAIL_USERNAME'), 25))->setUsername(env('MAIL_USERNAME'))->setPassword(env('MAIL_PASSWORD'));
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message($subject))->setFrom($headers)->setTo([$email => $first_name])->setBody($msg);
// Send the message
$result = $mailer->send($message);
*/
}


Expand Down
36 changes: 36 additions & 0 deletions app/Jobs/sendEmailJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Jobs;

use App\Mail\sendEmail;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;

class sendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::to('[email protected]')->send(new sendEmail());
}
}
11 changes: 3 additions & 8 deletions app/Mail/sendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ class sendEmail extends Mailable
*
* @return void
*/
public $sub;
public $mes;
public function __construct($subject, $message)
public function __construct()
{
$this->sub = $subject;
$this->mes = $message;
//
}

/**
Expand All @@ -31,8 +28,6 @@ public function __construct($subject, $message)
*/
public function build()
{
$e_subject = $this->sub;
$e_message = $this->mes;
return $this->view('mail.sendemail',compact("e_message"))->subject($e_subject);
return $this->view('welcome');
}
}
36 changes: 36 additions & 0 deletions database/migrations/2019_04_27_020124_create_jobs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}
21 changes: 17 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ Run `Without Docker`:\

$ cd blog

3 - run server:
3 - create database:\
create database "sentinel" and run the command

$ php artisan migrate

4 - run server:

$ php artisan serve

3 - open url and enjoy :
5 - open url and enjoy :

localhost:8000/




Run `With Docker`:

1 - clone git by command:
Expand All @@ -34,7 +38,16 @@ Run `With Docker`:
3 - run docker:

$ docker-compose up -d nginx mysql phpmyadmin redis workspace rabbitmq

4- open workspace in docker

4 - open url and enjoy :
$ docker-compose exec workspace bash

5 - create database:\
create database "sentinel" and run the command inside workspace

$ php artisan migrate
6 - open url and enjoy :

localhost/
5 changes: 5 additions & 0 deletions resources/views/mail.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Hi {{ $name }}</h1>
<p>Open link below to active your account.</p>
<a href="http://localhost:8000/admin/user/{{$id}}/activate">Click to Active Email</a>


19 changes: 10 additions & 9 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@
| contains the "web" middleware group. Now create something great!
|
*/
use Illuminate\Support\Facades\Route;//comment this line later
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

Route::GET('/', function () {
return view('welcome');
});


//Update User
Route::PUT('/admin/user/{user}','RegistrationController@update')->name('update');

Route::get('/admin/user/{user}/email','RegistrationController@sendEmail');

Auth::routes(['verify' => true]);


//////////////////////////////[------Working------]/////////////////////////////////

//Create User
Route::POST('/admin/user','RegistrationController@register')->name('register');

//Update User
Route::PUT('/admin/user/{user}','RegistrationController@update')->name('update');

//Delete User
Route::DELETE('/admin/user/{user}','RegistrationController@delete')->name('delete');

Expand All @@ -39,3 +37,6 @@

//Activate user
Route::GET('/admin/user/{user}/activate','RegistrationController@active')->name('user');

//send email
Route::get('/admin/user/{user}/email','RegistrationController@sendEmail');

0 comments on commit cada7ef

Please sign in to comment.