Browse Source

:art: Add a token list email

master
Clement Desmidt 4 months ago
parent
commit
71cb9c31dd

+ 12
- 0
app/Http/Controllers/UsersController.php View File

@@ -2,8 +2,10 @@

namespace App\Http\Controllers;

use App\Link;
use App\Mail\Confirmation;
use App\Mail\Resend;
use App\Mail\Tokens;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
@@ -71,6 +73,16 @@ class UsersController extends Controller
return response()->json(['status' => 'success', 'token' => $token->api_token]);
}

public function tokens(Request $request)
{
if ($request->method() === 'POST') {
$user = User::where('email', $request->email)->firstOrFail();
Mail::to($user->email)->send(new Tokens($user));

return response()->json(['message' => 'Email sent.']);
}
}

public function confirm(Request $request)
{
if (! $request->hasValidSignature()) {

+ 42
- 0
app/Mail/Tokens.php View File

@@ -0,0 +1,42 @@
<?php

namespace App\Mail;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\URL;

class Tokens extends Mailable
{
use Queueable, SerializesModels;
/**
* @var \App\User
*/
protected $user;

/**
* Create a new message instance.
*
* @param \App\User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$tokens = $this->user->getTokens();
return $this
->view('emails.user_tokens')
->with(['tokens' => $tokens]);
}
}

+ 1
- 1
app/User.php View File

@@ -24,7 +24,7 @@ class User extends Model
*/
public function getTokens()
{
return Token::where('user_id', $this->id)->all();
return Token::where('user_id', $this->id)->get();
}

/**

+ 37
- 1
public/js/app.js View File

@@ -48939,6 +48939,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
//
//
//
//

var _require = __webpack_require__(44),
detect = _require.detect;
@@ -49012,6 +49013,19 @@ var copy = __webpack_require__(45);
});
});
},
tokensAction: function tokensAction() {
var _this3 = this;

this.resetMessages();
this.loading = true;
var formData = new FormData();
formData.append('email', this.email);
Vue.http.post('api/tokens', formData, { emulateJSON: false }).then(function (response) {
_this3.loading = false;
_this3.success = true;
_this3.message = response.data.message;
});
},
resetMessages: function resetMessages() {
this.success = false;
this.error = false;
@@ -49375,7 +49389,29 @@ var render = function() {
}
}
},
[_vm._v("Resend link")]
[_vm._v("Generate a new token")]
),
_vm._v(" "),
_c(
"button",
{
directives: [
{
name: "show",
rawName: "v-show",
value: _vm.resend,
expression: "resend"
}
],
staticClass: "btn btn-primary btn-lg",
attrs: { type: "submit" },
on: {
click: function($event) {
_vm.tokensAction()
}
}
},
[_vm._v("View my tokens")]
)
])
: _vm._e()

+ 13
- 1
resources/js/components/App.vue View File

@@ -12,7 +12,8 @@
<div v-show="success" class="alert alert-success" role="alert">{{ message }}</div>
<div v-show="error" class="alert alert-warning" role="alert">{{ message }}</div>
<div class="info" v-show="token !== ''" id="token_clip">{{ token }}</div>
<button class="btn btn-primary btn-lg" v-show="resend" type="submit" @click="resendAction()">Resend link</button>
<button class="btn btn-primary btn-lg" v-show="resend" type="submit" @click="resendAction()">Generate a new token</button>
<button class="btn btn-primary btn-lg" v-show="resend" type="submit" @click="tokensAction()">View my tokens</button>
</div>
</div>
</template>
@@ -84,6 +85,17 @@
});
});
},
tokensAction: function() {
this.resetMessages();
this.loading = true;
let formData = new FormData();
formData.append('email', this.email);
Vue.http.post('api/tokens', formData, {emulateJSON: false}).then((response) => {
this.loading = false;
this.success = true;
this.message = response.data.message;
});
},
resetMessages: function() {
this.success = false;
this.error = false;

+ 295
- 0
resources/views/emails/user_tokens.blade.php View File

@@ -0,0 +1,295 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
<title> </title>
<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#outlook a {
padding: 0;
}

.ReadMsgBody {
width: 100%;
}

.ExternalClass {
width: 100%;
}

.ExternalClass * {
line-height: 100%;
}

body {
margin: 0;
padding: 0;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}

table,
td {
border-collapse: collapse;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
}

img {
border: 0;
height: auto;
line-height: 100%;
outline: none;
text-decoration: none;
-ms-interpolation-mode: bicubic;
}

p {
display: block;
margin: 13px 0;
}
</style>
<!--[if !mso]><!-->
<style type="text/css">
@media only screen and (max-width:480px) {
@-ms-viewport {
width: 320px;
}
@viewport {
width: 320px;
}
}
</style>
<!--<![endif]-->
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.outlook-group-fix { width:100% !important; }
</style>
<![endif]-->
<style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100 {
width: 100% !important;
max-width: 100%;
}
.mj-column-per-50 {
width: 50% !important;
max-width: 50%;
}
}
</style>
<style type="text/css">
@media only screen and (max-width:480px) {
table.full-width-mobile {
width: 100% !important;
}
td.full-width-mobile {
width: auto !important;
}
}
</style>
</head>

<body>
<div style="">
<!--[if mso | IE]>
<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="Margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">

<tr>

<td
class="" style="vertical-align:top;width:600px;"
>
<![endif]-->
<div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
<tr>
<td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
<tbody>
<tr>
<td style="width:100px;"> <img height="auto" src="{{ asset('images/logo.png') }}" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;" width="100" /> </td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size:0px;padding:10px 25px;word-break:break-word;">
<p style="border-top:solid 4px #F45E43;font-size:1;margin:0px auto;width:100%;"> </p>
<!--[if mso | IE]>
<table
align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 4px #F45E43;font-size:1;margin:0px auto;width:550px;" role="presentation" width="550px"
>
<tr>
<td style="height:0;line-height:0;">
&nbsp;
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>

</tr>

</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>

<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="background:white;background-color:white;Margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:white;background-color:white;width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="" style="vertical-align:top;width:600px;">
<![endif]-->
<div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Helvetica Neue;font-size:20px;font-style:italic;line-height:1;text-align:left;color:#626262;"> Vos tokens </div>
</td>
</tr>
@foreach($tokens as $token)
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#525252;">{{ $token->token_name }}</div>
</td>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#525252;">{{ $token->api_token }}</div>
</td>

</tr>
@endforeach
</table>
</div>
<!--[if mso | IE]>
</td>

</tr>

</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>


<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="Margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">

<tr>

<td
class="" style="vertical-align:top;width:600px;"
>
<![endif]-->
<div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
<tr>
<td style="font-size:0px;padding:10px 25px;word-break:break-word;">
<p style="border-top:solid 4px #F45E43;font-size:1;margin:0px auto;width:100%;"> </p>
<!--[if mso | IE]>
<table
align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 4px #F45E43;font-size:1;margin:0px auto;width:550px;" role="presentation" width="550px"
>
<tr>
<td style="height:0;line-height:0;">
&nbsp;
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#525252;"> © <a href="https://shikiryu.com">Shikiryu</a> </div>
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>

</tr>

</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</div>
</body>

</html>

+ 1
- 0
routes/api.php View File

@@ -20,6 +20,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('/register', 'UsersController@create')->name('register');
Route::get('/confirm', 'UsersController@confirm')->name('confirm');
Route::post('/token', 'UsersController@addToken')->name('resend');
Route::post('/tokens', 'UsersController@tokens')->name('tokens');
Route::get('/seetoken', 'UsersController@seetoken')->name('seetoken');

Route::middleware('auth:api')->get('/user', function (Request $request) {

Loading…
Cancel
Save