Browse Source

:art: Add a token list email

master
Clement Desmidt 1 month ago
parent
commit
71cb9c31dd

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

@@ -2,8 +2,10 @@
2 2
 
3 3
 namespace App\Http\Controllers;
4 4
 
5
+use App\Link;
5 6
 use App\Mail\Confirmation;
6 7
 use App\Mail\Resend;
8
+use App\Mail\Tokens;
7 9
 use App\User;
8 10
 use Illuminate\Http\Request;
9 11
 use Illuminate\Support\Facades\Mail;
@@ -71,6 +73,16 @@ class UsersController extends Controller
71 73
         return response()->json(['status' => 'success', 'token' => $token->api_token]);
72 74
     }
73 75
 
76
+    public function tokens(Request $request)
77
+    {
78
+        if ($request->method() === 'POST') {
79
+            $user = User::where('email', $request->email)->firstOrFail();
80
+            Mail::to($user->email)->send(new Tokens($user));
81
+
82
+            return response()->json(['message' => 'Email sent.']);
83
+        }
84
+    }
85
+
74 86
     public function confirm(Request $request)
75 87
     {
76 88
         if (! $request->hasValidSignature()) {

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

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace App\Mail;
4
+
5
+use App\User;
6
+use Illuminate\Bus\Queueable;
7
+use Illuminate\Mail\Mailable;
8
+use Illuminate\Queue\SerializesModels;
9
+use Illuminate\Contracts\Queue\ShouldQueue;
10
+use Illuminate\Support\Facades\URL;
11
+
12
+class Tokens extends Mailable
13
+{
14
+    use Queueable, SerializesModels;
15
+    /**
16
+     * @var \App\User
17
+     */
18
+    protected $user;
19
+
20
+    /**
21
+     * Create a new message instance.
22
+     *
23
+     * @param \App\User $user
24
+     */
25
+    public function __construct(User $user)
26
+    {
27
+        $this->user = $user;
28
+    }
29
+
30
+    /**
31
+     * Build the message.
32
+     *
33
+     * @return $this
34
+     */
35
+    public function build()
36
+    {
37
+        $tokens = $this->user->getTokens();
38
+        return $this
39
+            ->view('emails.user_tokens')
40
+            ->with(['tokens' => $tokens]);
41
+    }
42
+}

+ 1
- 1
app/User.php View File

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

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

@@ -48939,6 +48939,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
48939 48939
 //
48940 48940
 //
48941 48941
 //
48942
+//
48942 48943
 
48943 48944
 var _require = __webpack_require__(44),
48944 48945
     detect = _require.detect;
@@ -49012,6 +49013,19 @@ var copy = __webpack_require__(45);
49012 49013
                 });
49013 49014
             });
49014 49015
         },
49016
+        tokensAction: function tokensAction() {
49017
+            var _this3 = this;
49018
+
49019
+            this.resetMessages();
49020
+            this.loading = true;
49021
+            var formData = new FormData();
49022
+            formData.append('email', this.email);
49023
+            Vue.http.post('api/tokens', formData, { emulateJSON: false }).then(function (response) {
49024
+                _this3.loading = false;
49025
+                _this3.success = true;
49026
+                _this3.message = response.data.message;
49027
+            });
49028
+        },
49015 49029
         resetMessages: function resetMessages() {
49016 49030
             this.success = false;
49017 49031
             this.error = false;
@@ -49375,7 +49389,29 @@ var render = function() {
49375 49389
                 }
49376 49390
               }
49377 49391
             },
49378
-            [_vm._v("Resend link")]
49392
+            [_vm._v("Generate a new token")]
49393
+          ),
49394
+          _vm._v(" "),
49395
+          _c(
49396
+            "button",
49397
+            {
49398
+              directives: [
49399
+                {
49400
+                  name: "show",
49401
+                  rawName: "v-show",
49402
+                  value: _vm.resend,
49403
+                  expression: "resend"
49404
+                }
49405
+              ],
49406
+              staticClass: "btn btn-primary btn-lg",
49407
+              attrs: { type: "submit" },
49408
+              on: {
49409
+                click: function($event) {
49410
+                  _vm.tokensAction()
49411
+                }
49412
+              }
49413
+            },
49414
+            [_vm._v("View my tokens")]
49379 49415
           )
49380 49416
         ])
49381 49417
       : _vm._e()

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

@@ -12,7 +12,8 @@
12 12
 			<div v-show="success" class="alert alert-success" role="alert">{{ message }}</div>
13 13
 			<div v-show="error" class="alert alert-warning" role="alert">{{ message }}</div>
14 14
 			<div class="info" v-show="token !== ''" id="token_clip">{{ token }}</div>
15
-			<button class="btn btn-primary btn-lg" v-show="resend" type="submit" @click="resendAction()">Resend link</button>
15
+			<button class="btn btn-primary btn-lg" v-show="resend" type="submit" @click="resendAction()">Generate a new token</button>
16
+			<button class="btn btn-primary btn-lg" v-show="resend" type="submit" @click="tokensAction()">View my tokens</button>
16 17
 		</div>
17 18
     </div>
18 19
 </template>
@@ -84,6 +85,17 @@
84 85
 					});
85 86
                 });
86 87
             },
88
+			tokensAction: function() {
89
+				this.resetMessages();
90
+				this.loading = true;
91
+				let formData = new FormData();
92
+				formData.append('email', this.email);
93
+				Vue.http.post('api/tokens', formData, {emulateJSON: false}).then((response) => {
94
+					this.loading = false;
95
+					this.success = true;
96
+					this.message = response.data.message;
97
+				});
98
+			},
87 99
             resetMessages: function() {
88 100
                 this.success = false;
89 101
                 this.error = false;

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

@@ -0,0 +1,295 @@
1
+<!doctype html>
2
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
3
+
4
+<head>
5
+    <title> </title>
6
+    <!--[if !mso]><!-- -->
7
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
8
+    <!--<![endif]-->
9
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10
+    <meta name="viewport" content="width=device-width, initial-scale=1">
11
+    <style type="text/css">
12
+        #outlook a {
13
+            padding: 0;
14
+        }
15
+
16
+        .ReadMsgBody {
17
+            width: 100%;
18
+        }
19
+
20
+        .ExternalClass {
21
+            width: 100%;
22
+        }
23
+
24
+        .ExternalClass * {
25
+            line-height: 100%;
26
+        }
27
+
28
+        body {
29
+            margin: 0;
30
+            padding: 0;
31
+            -webkit-text-size-adjust: 100%;
32
+            -ms-text-size-adjust: 100%;
33
+        }
34
+
35
+        table,
36
+        td {
37
+            border-collapse: collapse;
38
+            mso-table-lspace: 0pt;
39
+            mso-table-rspace: 0pt;
40
+        }
41
+
42
+        img {
43
+            border: 0;
44
+            height: auto;
45
+            line-height: 100%;
46
+            outline: none;
47
+            text-decoration: none;
48
+            -ms-interpolation-mode: bicubic;
49
+        }
50
+
51
+        p {
52
+            display: block;
53
+            margin: 13px 0;
54
+        }
55
+    </style>
56
+    <!--[if !mso]><!-->
57
+    <style type="text/css">
58
+        @media only screen and (max-width:480px) {
59
+            @-ms-viewport {
60
+                width: 320px;
61
+            }
62
+            @viewport {
63
+                width: 320px;
64
+            }
65
+        }
66
+    </style>
67
+    <!--<![endif]-->
68
+    <!--[if mso]>
69
+    <xml>
70
+        <o:OfficeDocumentSettings>
71
+            <o:AllowPNG/>
72
+            <o:PixelsPerInch>96</o:PixelsPerInch>
73
+        </o:OfficeDocumentSettings>
74
+    </xml>
75
+    <![endif]-->
76
+    <!--[if lte mso 11]>
77
+    <style type="text/css">
78
+        .outlook-group-fix { width:100% !important; }
79
+    </style>
80
+    <![endif]-->
81
+    <style type="text/css">
82
+        @media only screen and (min-width:480px) {
83
+            .mj-column-per-100 {
84
+                width: 100% !important;
85
+                max-width: 100%;
86
+            }
87
+            .mj-column-per-50 {
88
+                width: 50% !important;
89
+                max-width: 50%;
90
+            }
91
+        }
92
+    </style>
93
+    <style type="text/css">
94
+        @media only screen and (max-width:480px) {
95
+            table.full-width-mobile {
96
+                width: 100% !important;
97
+            }
98
+            td.full-width-mobile {
99
+                width: auto !important;
100
+            }
101
+        }
102
+    </style>
103
+</head>
104
+
105
+<body>
106
+<div style="">
107
+    <!--[if mso | IE]>
108
+    <table
109
+        align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
110
+    >
111
+        <tr>
112
+            <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
113
+    <![endif]-->
114
+    <div style="Margin:0px auto;max-width:600px;">
115
+        <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
116
+            <tbody>
117
+            <tr>
118
+                <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;">
119
+                    <!--[if mso | IE]>
120
+                    <table role="presentation" border="0" cellpadding="0" cellspacing="0">
121
+
122
+                        <tr>
123
+
124
+                            <td
125
+                                class="" style="vertical-align:top;width:600px;"
126
+                            >
127
+                    <![endif]-->
128
+                    <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%;">
129
+                        <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
130
+                            <tr>
131
+                                <td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;">
132
+                                    <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
133
+                                        <tbody>
134
+                                        <tr>
135
+                                            <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>
136
+                                        </tr>
137
+                                        </tbody>
138
+                                    </table>
139
+                                </td>
140
+                            </tr>
141
+                            <tr>
142
+                                <td style="font-size:0px;padding:10px 25px;word-break:break-word;">
143
+                                    <p style="border-top:solid 4px #F45E43;font-size:1;margin:0px auto;width:100%;"> </p>
144
+                                    <!--[if mso | IE]>
145
+                                    <table
146
+                                        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"
147
+                                    >
148
+                                        <tr>
149
+                                            <td style="height:0;line-height:0;">
150
+                                                &nbsp;
151
+                                            </td>
152
+                                        </tr>
153
+                                    </table>
154
+                                    <![endif]-->
155
+                                </td>
156
+                            </tr>
157
+                        </table>
158
+                    </div>
159
+                    <!--[if mso | IE]>
160
+                    </td>
161
+
162
+                    </tr>
163
+
164
+                    </table>
165
+                    <![endif]-->
166
+                </td>
167
+            </tr>
168
+            </tbody>
169
+        </table>
170
+    </div>
171
+    <!--[if mso | IE]>
172
+    </td>
173
+    </tr>
174
+    </table>
175
+
176
+    <table
177
+        align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
178
+    >
179
+        <tr>
180
+            <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
181
+    <![endif]-->
182
+    <div style="background:white;background-color:white;Margin:0px auto;max-width:600px;">
183
+        <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:white;background-color:white;width:100%;">
184
+            <tbody>
185
+            <tr>
186
+                <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;">
187
+                    <!--[if mso | IE]>
188
+                    <table role="presentation" border="0" cellpadding="0" cellspacing="0">
189
+                        <tr>
190
+                            <td class="" style="vertical-align:top;width:600px;">
191
+                    <![endif]-->
192
+                    <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%;">
193
+                        <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
194
+                            <tr>
195
+                                <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
196
+                                    <div style="font-family:Helvetica Neue;font-size:20px;font-style:italic;line-height:1;text-align:left;color:#626262;"> Vos tokens </div>
197
+                                </td>
198
+                            </tr>
199
+                            @foreach($tokens as $token)
200
+                            <tr>
201
+                                <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
202
+                                    <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#525252;">{{ $token->token_name }}</div>
203
+                                </td>
204
+                                <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
205
+                                    <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#525252;">{{ $token->api_token }}</div>
206
+                                </td>
207
+
208
+                            </tr>
209
+                            @endforeach
210
+                        </table>
211
+                    </div>
212
+                    <!--[if mso | IE]>
213
+                    </td>
214
+
215
+                    </tr>
216
+
217
+                    </table>
218
+                    <![endif]-->
219
+                </td>
220
+            </tr>
221
+            </tbody>
222
+        </table>
223
+    </div>
224
+    <!--[if mso | IE]>
225
+    </td>
226
+    </tr>
227
+    </table>
228
+
229
+
230
+    <table
231
+        align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
232
+    >
233
+        <tr>
234
+            <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
235
+    <![endif]-->
236
+    <div style="Margin:0px auto;max-width:600px;">
237
+        <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
238
+            <tbody>
239
+            <tr>
240
+                <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;">
241
+                    <!--[if mso | IE]>
242
+                    <table role="presentation" border="0" cellpadding="0" cellspacing="0">
243
+
244
+                        <tr>
245
+
246
+                            <td
247
+                                class="" style="vertical-align:top;width:600px;"
248
+                            >
249
+                    <![endif]-->
250
+                    <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%;">
251
+                        <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
252
+                            <tr>
253
+                                <td style="font-size:0px;padding:10px 25px;word-break:break-word;">
254
+                                    <p style="border-top:solid 4px #F45E43;font-size:1;margin:0px auto;width:100%;"> </p>
255
+                                    <!--[if mso | IE]>
256
+                                    <table
257
+                                        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"
258
+                                    >
259
+                                        <tr>
260
+                                            <td style="height:0;line-height:0;">
261
+                                                &nbsp;
262
+                                            </td>
263
+                                        </tr>
264
+                                    </table>
265
+                                    <![endif]-->
266
+                                </td>
267
+                            </tr>
268
+                            <tr>
269
+                                <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
270
+                                    <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>
271
+                                </td>
272
+                            </tr>
273
+                        </table>
274
+                    </div>
275
+                    <!--[if mso | IE]>
276
+                    </td>
277
+
278
+                    </tr>
279
+
280
+                    </table>
281
+                    <![endif]-->
282
+                </td>
283
+            </tr>
284
+            </tbody>
285
+        </table>
286
+    </div>
287
+    <!--[if mso | IE]>
288
+    </td>
289
+    </tr>
290
+    </table>
291
+    <![endif]-->
292
+</div>
293
+</body>
294
+
295
+</html>

+ 1
- 0
routes/api.php View File

@@ -20,6 +20,7 @@ Route::group(['middleware' => ['auth']], function () {
20 20
 Route::post('/register', 'UsersController@create')->name('register');
21 21
 Route::get('/confirm', 'UsersController@confirm')->name('confirm');
22 22
 Route::post('/token', 'UsersController@addToken')->name('resend');
23
+Route::post('/tokens', 'UsersController@tokens')->name('tokens');
23 24
 Route::get('/seetoken', 'UsersController@seetoken')->name('seetoken');
24 25
 
25 26
 Route::middleware('auth:api')->get('/user', function (Request $request) {

Loading…
Cancel
Save