Skip to content

Commit

Permalink
mailactive
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetserefoglu committed Jun 3, 2020
1 parent eb5ebb3 commit c83dd19
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 191 deletions.
39 changes: 33 additions & 6 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

use App\User;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\VerifiesEmails;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;

class AuthController extends Controller {

use VerifiesEmails;

//
/**
* Create a new AuthController instance.
Expand Down Expand Up @@ -46,10 +50,13 @@ public function register(Request $request) {
'name' => $request->name,
'email' => $request->email,
'password' => bcrypt($request->password),
'activation_token' => str_random(60),
]);

$user->save();

$user->sendApiConfirmAccount();

$message['success'] = 'Kullanıcı Başarıyla Oluşturuldu';

return response()->json(['message' => $message, 'code' => 201]);
Expand Down Expand Up @@ -87,10 +94,21 @@ public function login(Request $request) {
}

$user = $request->user();
$message['token'] = $user->createToken('MyApp')->accessToken;
$message['token_type'] = 'Bearer';
$message['experies_at'] = Carbon::parse(Carbon::now()->addWeeks(1))->toDateTimeString();
$message['success'] = 'Kullanıcı Girişi Başarılı';

if ($user->email_verified_at !== NULL) {

$message['token'] = $user->createToken('MyApp')->accessToken;
$message['token_type'] = 'Bearer';
$message['experies_at'] = Carbon::parse(Carbon::now()->addWeeks(1))->toDateTimeString();
$message['success'] = 'Kullanıcı Girişi Başarılı';

} else {

$message['error'] = 'Unauthorized';
$message['code'] = 401;

return response()->json(['message' => $message]);
}

return response()->json(['message' => $message, 'code' => 200]);
}
Expand Down Expand Up @@ -143,12 +161,21 @@ public function refresh() {
}

/**
* Response Token
* Verify User
*
*
* @return \Illuminate\Http\JsonResponse
*/
protected function respondWithToken() {
protected function verify(Request $request) {

$user = User::findOrFail($request['id']);

$user->email_verified_at = now();

$user->save();

$message['success'] = 'Kullanıcı Email Doğrulandı';

return response()->json(['message' => $message, 'code' => 200]);
}
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
25 changes: 25 additions & 0 deletions app/Notifications/AccountVerify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Notifications;

use Illuminate\Auth\Notifications\VerifyEmail as AccountVerifyBase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;

/**
* Account Verify
*/
class AccountVerify extends AccountVerifyBase {

/**
* Get The verification URL for
*
* @param mixed $notifiable
*
*/
protected function verificationUrl($notifiable) {
return URL::temporarySignedRoute('verification.verify',
Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]
);
}
}
61 changes: 61 additions & 0 deletions app/Notifications/AccountVerifyUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class AccountVerifyUser extends Notification
{
use Queueable;

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

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
5 changes: 5 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use App\Notifications\AccountVerify;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
Expand Down Expand Up @@ -40,4 +41,8 @@ public function products() {
return $this->hasMany(Product::class);
}

public function sendApiConfirmAccount() {
$this->notify(new AccountVerify);
}

}
Loading

0 comments on commit c83dd19

Please sign in to comment.