-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
695 lines (633 loc) ยท 262 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>freeseamew`s blog</title>
<link href="/atom.xml" rel="self"/>
<link href="http://freeseamew.github.io/"/>
<updated>2017-12-02T15:16:25.000Z</updated>
<id>http://freeseamew.github.io/</id>
<author>
<name>freeseamew</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>๋ฌดํ ์คํฌ๋กค ๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ํด๊ฒฐ 1</title>
<link href="http://freeseamew.github.io/2017/12/02/meteor-Infinite-scroll-1/"/>
<id>http://freeseamew.github.io/2017/12/02/meteor-Infinite-scroll-1/</id>
<published>2017-12-01T15:40:32.000Z</published>
<updated>2017-12-02T15:16:25.000Z</updated>
<content type="html"><![CDATA[<h3 id="0-๊ฐ์ข-์๊ฐ"><a href="#0-๊ฐ์ข-์๊ฐ" class="headerlink" title="0. ๊ฐ์ข ์๊ฐ"></a>0. ๊ฐ์ข ์๊ฐ</h3><p>๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํ๋ค ๋ณด๋ฉด ์์ฐ์ค๋ฝ๊ฒ ๋ง๋๊ฒ ๋๋ ๋ฌธ์ ๊ฐ ์๋๋ฐ ๊ทธ๊ฒ์ ๋ธ๋ผ์ฐ์ ๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ์
๋๋ค. ์ค์ ๋ก ์ด ๋ฌธ์ ๋๋ฌธ์ ๋ฌดํ ์คํฌ๋กค์ ๋ํ ๋ถ์ ์ ์ธ ์๊ฒฌ์ ๋ณด์ธ ๊ฐ๋ฐ์๋ค๋ ์๊ณ , ์ด๋ค์ ์ํด ๋ฌดํ์คํฌ๋กค์ ๋ํ ๋๋ฆ ์๋ฏธ ์๋ ๋นํ๋ ์์์ต๋๋ค. ํ์ง๋ง ์๊ฐ์ด ์ง๋๊ณ , <code>www.discourse.org</code>์ ๊ฐ์ด ์ด ๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์๋น์ค๊ฐ ํ๋๋์ฉ ๋ํ๋๊ฒ ๋๊ณ , ๋ชจ๋ฐ์ผ ํ๊ฒฝ์์ ์ฌ์ฉ์ ๋ค์ด ๋๋ผ๋ ์ง๊ด์ฑ ๋๋ฌธ์ ๋ฌดํ์คํฌ๋กค์ ๊ฐ์ฅ ๋ณดํธ์ ์ธ ํ์ด์ง ๊ธฐ๋ฒ์ผ๋ก ์๋ฆฌ๋งค๊น ํ๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. </p>
<p>Meteor๋ฅผ ๋ณธ๊ฒฉ์ ์ผ๋ก ์ฌ์ฉํด๋ณผ ์๊ฐ์ ํ๋ฉด์ ์ ์ญ์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด์ผ๋ง ํ์ต๋๋ค.<br>ํ์ง๋ง ๊ตญ๋ด ๋ฌธ์๋ฅผ ์ด๋ฆฌ์ ๋ฆฌ ๋ค์ ธ๋ดค์ง๋ง ์ด ๋ฌธ์ ๋ฅผ ๊น๋ํ๊ฒ ํด๊ฒฐํ ๋ต์ ์์ง ์ฐพ์ง ๋ชปํ์ต๋๋ค. ๊ทธ๋๋ Meteor ์ปค๋ฎค๋ํฐ๋, ํน์ Stack Overflow ๋ฑ์ ์ฌ๋ผ์จ ์ฌ๋ฌ ๋ด์ฉ๋ค์ ์กฐํฉํ๊ณ , ์์ฉํด์ ๋๋ฆ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ๊ฒฐ๊ณผ๋ฌผ์ ๋ง๋ค๊ฒ ๋์์ต๋๋ค. ์ด ๊ฐ์ข๋ ์ด ๋ฌดํ์คํฌ๋กค์ ๋ํ ์ ์ ์ฝ์ง๊ธฐ๊ฐ ๋๊ฒ ์ต๋๋ค. 1~4๋ฒ๊น์ง๋ ๋ฌดํ์คํฌ๋กค์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๊ดํ ๋ด์ฉ์
๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ง์ง๋ง 5๋ฒ์ ๋ฌดํ์คํฌ๋กค์ ๋ฌธ์ ์ ๊ณผ ์ด ํด๊ฒฐ๋ฐฉ๋ฒ์ ๊ดํ ๋ด์ฉ์
๋๋ค. ์ด๋ฏธ ๋ฌดํ์คํฌ๋กค์ ์ฌ์ฉํ์๋ ๋ถ์ 5๋ฒ๋ง ๋ณด์
๋ ์๊ด ์์ ๊ฒ ๊ฐ์ต๋๋ค. </p>
<hr>
<h3 id="1-ํ๊ฒฐ-์ค์ "><a href="#1-ํ๊ฒฐ-์ค์ " class="headerlink" title="1. ํ๊ฒฐ ์ค์ "></a>1. ํ๊ฒฐ ์ค์ </h3><h4 id="1-1-ํด๋-๊ตฌ์กฐ"><a href="#1-1-ํด๋-๊ตฌ์กฐ" class="headerlink" title="1.1 ํด๋ ๊ตฌ์กฐ"></a>1.1 ํด๋ ๊ตฌ์กฐ</h4><p>์ ๊ทธ๋ผ ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ฐ์ข๋ฅผ ์์ํด ๋ณด๊ฒ ์ต๋๋ค. </p>
<p>์ผ๋จ Meteor์ ๋ํ ๊ธฐ๋ณธ ์ค์น๋ ๋ค์ ๊ฐ์ข๋ฅผ ์ฐธ๊ณ ํด ์ฃผ์๊ธฐ ๋ฐ๋๋๋ค. ์๋ ๊ฐ์ข์์ ์ค์น์ ๋ํ ๋ถ๋ถ๋ง ์ฐธ๊ณ ํ์๋ฉด ๋๊ฒ ์ต๋๋ค.<br><a href="https://freeseamew.github.io/2017/07/02/meteor-account-tutorial-1/">https://freeseamew.github.io/2017/07/02/meteor-account-tutorial-1/</a></p>
<p>์ค์นํ์ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ๋ก ํ์ผ๋ค์ ๋ง๋ค์ด ์ฃผ์ธ์.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">meteorAccount</div><div class="line">โโโ .meteor</div><div class="line">โโโ client</div><div class="line">โ โโโ styles </div><div class="line">โ โ โโโ main.css </div><div class="line">โ โโโ contents</div><div class="line">โ โ โโโ post-lists.html</div><div class="line">โ โ โโโ post-lists.js</div><div class="line">โ โ โโโ post-view.html</div><div class="line">โ โ โโโ post-view.js</div><div class="line">โ โโโ autoscroll.js</div><div class="line">โ โโโ main-layout.html</div><div class="line">โ โโโ main-layout.js </div><div class="line">โโโ lib</div><div class="line">โ โโโ methods</div><div class="line">โ โ โโโ postMethods.js</div><div class="line">โ โโโ collections.js</div><div class="line">โ โโโ routes.js </div><div class="line">โโโ node_module</div><div class="line">โโโ public</div><div class="line">โโโ server</div><div class="line"> โโโ fixture.js </div><div class="line"> โโโ pubs.js</div></pre></td></tr></table></figure>
<h4 id="1-2-์ค์น-ํํค์ง"><a href="#1-2-์ค์น-ํํค์ง" class="headerlink" title="1.2 ์ค์น ํํค์ง"></a>1.2 ์ค์น ํํค์ง</h4><p>์ด๋ฒ ์์ ์ ์ฌ์ฉํ ํํค์ง๋ค์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.<br>์ฐ์ ๋ผ์ฐํฐ ๊ด๋ จ ํํค์ง๋ฅผ ์ค์นํด ์ฃผ์ธ์.</p>
<blockquote>
<p>์ค์น ํจํค์ง : ๋ผ์ฐํฐ ๊ด๋ จ</p>
<ul>
<li>meteor add kadira:flow-router</li>
<li>meteor add arillo:flow-router-helpers</li>
<li>meteor add kadira:blaze-layout</li>
</ul>
</blockquote>
<p>๋ค์์ Subscription ์บ์ฌ ์
๋๋ค. ์ด๋ถ๋ถ์ ๋ํด์๋ ๊ฐ์ข์ค์ ์ค๋ช
๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง : Subscription ์บ์ฌ</p>
<ul>
<li>meteor add meteorhacks:subs-manager</li>
<li>meteor add msavin:mongol</li>
</ul>
</blockquote>
<p>๋ง์ง๋ง์ผ๋ก ํ
ํ๋ฆฟ์ ์ฌ์ฉํ bootstrap ๊ด๋ จ ํจํค์ง๋ฅผ ์ค์นํ๋ฉด ๊ธฐ๋ณธ ์ค์ ์ ๋์
๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง : ๊ธฐํ</p>
<ul>
<li>meteor add twbs:bootstrap@=3.3.6</li>
</ul>
</blockquote>
<hr>
<h3 id="2-๊ธฐ๋ณธ-์๋ฒ-์์
"><a href="#2-๊ธฐ๋ณธ-์๋ฒ-์์
" class="headerlink" title="2. ๊ธฐ๋ณธ ์๋ฒ ์์
"></a>2. ๊ธฐ๋ณธ ์๋ฒ ์์
</h3><h4 id="2-1-collection-์์ฑ"><a href="#2-1-collection-์์ฑ" class="headerlink" title="2.1 collection ์์ฑ"></a>2.1 collection ์์ฑ</h4><p>์ด๋ฒ ์์ ์ ์ฌ์ฉํ ์ฝ๋์
์ posts๋ผ๋ ๋จ์ผ ์ฝ๋์
์ ์ฌ์ฉํ ๊ฒ์
๋๋ค. ๋ค์์ ์ฐธ๊ณ ๋ก ํด๋น ์ฝ๋์
์ ๋ง๋ค์ด ์ฃผ์ธ์. ์ฐธ๊ณ ๋ก Meteor์์์ ์ฝ๋์
์ ์ผ์ข
์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์์ ํ
์ด๋ธ์ ํด๋นํ๋ ๋ถ๋ถ์
๋๋ค. Meteor์์๋ collection์ค์ ์ ํตํด ์๋ฒ์ ๋ชฝ๊ณ ๋๋น์ ํด๋ผ์ด์ธํธ์ ๋ฏธ๋๋ชฝ๊ณ ๋ฅผ ์ฐ๋ํด์ค๋๋ค. ์ด๋ถ๋ถ์ ๋ค๋ฅธ ๊ฐ์ข์์ ์ข๋ ๊น์ด์๊ฒ ๋ค๋ฃจ๋๋ก ํ๊ฒ ์ต๋๋ค. ๊ฐ๋จํ๊ฒ๋ ์ผ์ข
์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ค์ ? ์ ๋๋ก ์ดํดํด ์ฃผ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p><code>lib/collections.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Posts = new Mongo.Collection('posts');</div></pre></td></tr></table></figure></p>
<h4 id="2-2-pubs-์์ฑ"><a href="#2-2-pubs-์์ฑ" class="headerlink" title="2.2 pubs ์์ฑ"></a>2.2 pubs ์์ฑ</h4><p>pubs๋ Meteor์์ ๋ฐ์ดํฐ ๋ฒ ์ด์ค์ ๋ด์ฉ์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ค์ ํ๋์
๋๋ค. pub(๋ฐํ)/sub(๊ตฌ๋
)์ด๋ผ๋ ๋ฉ์ปค๋์ฆ์ ํตํด์ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ๋ชฝ๊ณ ๋๋น์์ ๋ฏธ๋๋ชฝ๊ณ ๋ก ๋ฐ์์ค๋ ๊ตฌ์กฐ์
๋๋ค. ์ด๋ถ๋ถ๋ ๋์ค์ ๋ค๋ฅธ ๊ฐ์ข๋ฅผ ํตํด์ ์กฐ๊ธ๋ ์์ธํ ๋ค๋ฃจ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>์ฐ์ <code>posts</code>๋ ๋ฆฌ์คํธ๋ฅผ ๋ฟ๋ ค์ฃผ๋ ์ผ์ข
์ ์ฟผ๋ฆฌ๋ถ๋ถ์ด ๋๊ฒ ์ต๋๋ค. ์ผ๋ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์๋ค๋ฉด <code>select ์ปฌ๋ผ๋ค from ํ
์ด๋ธ limit ๋ณด์ฌ์ค ๊ฐ์</code> ์ ๋์ ์ฟผ๋ฆฌ๋ฅผ ํธ์ถํ๋ค๊ณ ์๊ฐํ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p>๋ค์์ผ๋ก <code>postDetail</code>์ ๋ฆฌ์คํธ์์ ์ ํ๋ post์ ๋ด์ฉ์ ๋ณด์ฌ์ฃผ๋ ๋ถ๋ถ์
๋๋ค.<br><code>select ์ปฌ๋ผ๋ค from ํ
์ด๋ธ๋ช
where id=id</code> ์ด๋ฐ ์์ ์ฟผ๋ฆฌ์ ํด๋นํ๋ ๋ด์ฉ์
๋๋ค. </p>
<p>์ด์ ์๋ ์ฝ๋๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.</p>
<p><code>server/pubs.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">Meteor.publish('posts', function (postCnt) {</div><div class="line"> return Posts.find({}, {limit: postCnt, sort: {postDate: -1}});</div><div class="line">});</div><div class="line"></div><div class="line">Meteor.publish('postDetail', function (id) {</div><div class="line"> return Posts.find({_id: id}); // ์ฌ๊ธฐ์ findOne๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ฒ ๋ฆฌํด๋๋ ๋ฌธ์ ๋ฐ์</div><div class="line">});</div></pre></td></tr></table></figure>
<h4 id="2-3-methods-์์ฑ"><a href="#2-3-methods-์์ฑ" class="headerlink" title="2.3 methods ์์ฑ"></a>2.3 methods ์์ฑ</h4><p>method๋ pub/sub๊ณผ ํจ๊ป ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ค๋ฃจ๋ ๋ฐฉ๋ฒ์
๋๋ค. pub/sub์ด ๋ฆฌ์คํธ ํ์์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋๋ฐ ์ฃผ๋ก ์ฌ์ฉ๋๋ค๋ฉด, method๋ ์ฐ๊ธฐ, ์์ , ์ญ์ ์ ์ฃผ๋ก ์ฌ์ฉ๋ฉ๋๋ค.<br>์ฌ๊ธฐ์๋ <code>select count(id) from ํ
์ด๋ธ</code>์ ํด๋นํ๋ ์ฟผ๋ฆฌ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด ์ฌ์ฉํ์ต๋๋ค. </p>
<p><code>lib/methods/postMethods.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">Meteor.methods({</div><div class="line"></div><div class="line"> getPostCountAll: function () {</div><div class="line"> return Posts.find().count();</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<hr>
<h3 id="3-๋ผ์ฐํ
-์ธํ
"><a href="#3-๋ผ์ฐํ
-์ธํ
" class="headerlink" title="3. ๋ผ์ฐํ
์ธํ
"></a>3. ๋ผ์ฐํ
์ธํ
</h3><p>๋ผ์ฐํ
์ ๋ํด ๊ฐ๋จํ ์ค๋ช
๋๋ฆฌ๋ฉด <code>http://localhost:3000/postList</code> ์ฃผ์๋ก url์ ์
๋ ฅํ๋ฉด <code>postList</code>๋ผ๋ template์ด <code>mainLayout</code>์ด๋ผ๋ ๊ณณ์ ๋ณด์ฌ ์ง๋ค๋ ์๋ฏธ๋ฅผ ๊ฐ์ง๋๋ค. ๋ค์ ์ค๋ช
ํ์๋ฉด, url์ฃผ์์ ๋ฐ๋ผ postList, postView ๋ฑ์ ํ์ด์ง๋ก ์ด๋ํ๊ฒ ํ๋ ๊ธฐ๋ฅ์ด ๋๊ฒ ์ต๋๋ค. </p>
<p>๋ผ์ฐํ
๋ ํ์ด์ง๋ ์ด 2๊ฐ์ ํ์ด์ง๊ฐ ๋๊ฒ ์ต๋๋ค. <code>/postList</code>๋ ๋ฌดํ์คํฌ๋กค ํ์ด์ง๊ฐ ๋๊ฒ ๊ณ , <code>/postView</code>๋ ๋ฆฌ์คํธ์์ ์ ํ๋ ๋ชฉ๋ก์ ๋ด์ฉ์ ๋ณด๋ ํ์ด์ง๊ฐ ๋๊ฒ ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ <code>/</code> ์ ๊ฒฝ์ฐ๋ ์์ดํผ ์ฃผ์๋ก ์ฒ์ ์ ๊ทผํ ์ฌ์ฉ์๋ฅผ ๋ฆฌ์คํธ ํ์ด์ง๋ก ๋ณด๋ด์ฃผ๋๋ก ํ๋ ๊ธฐ๋ฅ์
๋๋ค. </p>
<p>postView์ ๊ฒฝ์ฐ <code>:id</code>๋ก ํ์๋๋ ๋ถ๋ถ์ด ์๋๋ฐ์. ์ด๋ถ๋ถ์ ์์ธ๋ณด๊ธฐ ํ์ด์ง์ id ๊ฐ์ด ๋๊ฒ ์ต๋๋ค. ๋ฆฌ์คํธ์์ <code>a href</code>๋ก ๋งํฌ๋ฅผ ๊ฑธ์ด์ค๋ <code>http://localhost:3000/postView/iFcDNXidApCtyCFRt</code> ์ด๋ฐ ํํ์ ์ฃผ์๊ฐ ๋ ํ
๋ฐ์. ์ฌ๊ธฐ์ <code>postView/</code> ๋ค์ ์๋ ๊ฐ์ด ID๊ฐ์ด๋ผ๊ณ ์ธ์์์ผ ์ฃผ๋ ๋ฐฉ๋ฒ์
๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ํค ๊ฐ์ <code>var id = FlowRouter.getParam('id');</code> ์ด๋ฐ ์์ผ๋ก ๋ณ์์ ๋ด์ ์ฌ์ฉ ํ ์ ์์ต๋๋ค. </p>
<p>์ด์ routes.js๋ฅผ ์ด๊ณ ๋ค์์ ์
๋ ฅํด ์ฃผ์ธ์. </p>
<p><code>lib/routes.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">FlowRouter.route('/', {</div><div class="line"> name: 'main',</div><div class="line"> action: function() {</div><div class="line"></div><div class="line"> FlowRouter.go('/postList');</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">FlowRouter.route('/postList', {</div><div class="line"> name: 'main',</div><div class="line"> action: function() {</div><div class="line"></div><div class="line"> BlazeLayout.render('mainLayout', {</div><div class="line"> content:'postList'</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">FlowRouter.route('/postView/:id', {</div><div class="line"> name: 'postView',</div><div class="line"> action: function () {</div><div class="line"></div><div class="line"> var id = FlowRouter.getParam('id');</div><div class="line"></div><div class="line"> BlazeLayout.render('mainLayout', {</div><div class="line"> content: 'postView'</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>๋ค์์ ์์ ์ ์ ์ค๋ช
ํ ์ฃผ์์ ๋ฐ๋ผ ํ
ํ๋ฆฟ์ ๋ฟ๋ ค์ค ์ผ์ข
์ ๋ถ๋ชจ ํ
ํ๋ฆฟ์ ์ค์ ํ๋ ํ์ผ์ด ๋๊ฒ ์ต๋๋ค. client/main-layout.js ์ ํ์ผ์ ๋ง๋ค๊ณ ๋ด์ฉ์ ์
๋ ฅํด ์ฃผ์ธ์.</p>
<p><code>client/main-layout.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><template name="mainLayout"></div><div class="line"> <header class="navbar navbar-default navbar-fixed-top table-header-bg" ></div><div class="line"> <div class="container "></div><div class="line"></div><div class="line"> <div class="navbar-header"></div><div class="line"> <a href="/" class="navbar-brand" name="btn-home">Infinite Scroll</a></div><div class="line"> </div></div><div class="line"></div><div class="line"> <div class="collapse navbar-collapse navbar-right navbar-ex1-collapse"></div><div class="line"> <div class="navbar-form navbar-right" ng-controller="authCtrl as auth "></div><div class="line"></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></div><div class="line"> </header></div><div class="line"> <div class="container"></div><div class="line"> {{> Template.dynamic template=content }}</div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<hr>
<h3 id="4-๋ฆฌ์คํธ-๋ฐ-๋ด์ฉ๋ณด๊ธฐ-ํ์ด์ง-์์ฑ"><a href="#4-๋ฆฌ์คํธ-๋ฐ-๋ด์ฉ๋ณด๊ธฐ-ํ์ด์ง-์์ฑ" class="headerlink" title="4. ๋ฆฌ์คํธ ๋ฐ ๋ด์ฉ๋ณด๊ธฐ ํ์ด์ง ์์ฑ"></a>4. ๋ฆฌ์คํธ ๋ฐ ๋ด์ฉ๋ณด๊ธฐ ํ์ด์ง ์์ฑ</h3><h4 id="4-1-ํฌ์คํธ-๋ฆฌ์คํธ"><a href="#4-1-ํฌ์คํธ-๋ฆฌ์คํธ" class="headerlink" title="4.1 ํฌ์คํธ ๋ฆฌ์คํธ"></a>4.1 ํฌ์คํธ ๋ฆฌ์คํธ</h4><p>์ด์ ๋ฆฌ์คํธ ํ์ด์ง๋ฅผ ์์ฑํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.<br>์ฐ์ ์ด๋ฒํ๋ก์ ํธ์ ์ฌ์ฉํ css ํ์ผ์ ์์ฑํ๋๋ก ํ๊ฒ ์ต๋๋ค. ๋ค์ ๋งํฌ์ cssํ์ผ์ ๋ด์ฉ์ ๋ณต์ฌํด ์ฃผ์ธ์.</p>
<p><code>client/styles/main.css</code></p>
<blockquote>
<p><a href="https://github.com/freeseamew/meteor-infinit-scroll/blob/master/client/styles/main.css" target="_blank" rel="noopener">https://github.com/freeseamew/meteor-infinit-scroll/blob/master/client/styles/main.css</a></p>
</blockquote>
<p>๋ค์์ผ๋ก ์๋๋ฅผ ์ฐธ๊ณ ๋ก <code>post-list.html</code> ํ์ผ์ ๋ง๋ค๊ฒ ์ต๋๋ค. ์ด ํ์ผ์๋ postList, postListItem, postLoadingItem ์ 3๊ฐ์ง template์ ์ฌ์ฉํ ์์ ์
๋๋ค. ์ฐธ๊ณ ๋ก Meteor๋ ๊ธฐ๋ณธ์ ์ผ๋ก blaze๋ผ๋ ํ๋ก ํธ์๋ ์์ง์ ์ฌ์ฉํ๋๋ฐ, <code>post-list.html, post-list.js</code> ์ด๋ฐ ์์ผ๋ก ๋์ผ ํ
ํ๋ฆฟ์ ํด๋นํ๋ html๊ณผ ์ด ํ
ํ๋ฆฟ์ ๋์ํ๋ js ํ์ผ๋ก ์ด๋ฃจ์ด ์ง๋ ๊ตฌ์กฐ์
๋๋ค. </p>
<p>์ฝ๋๋ฅผ ์ค๋ช
๋๋ฆฌ๋ฉด <code>#each list</code> ์ ํด๋นํ๋ ๋ถ๋ถ์ list๋ผ๋ ๋ฐ์ดํฐ๋ฅผ each๋ฌธ์ ์ฌ์ฉํด์ <code>>postListItem</code> ์ด ํ
ํ๋ฆฟ์ ๋ฐ๋ณต์์ผ ์ฃผ๋ ๊ธฐ๋ฅ์ ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ <code>#if endOfData</code> ์์๋ ๋ง์ฝ ๋ฟ๋ ค์ค ๋ฆฌ์คํธ๊ฐ ๋์ด์ ์์ ๊ฒฝ์ฐ ๋ง์ง๋ง ํ์ด์ง๋ผ๋ ๊ฒ์ ํ์ํด์ค๋๋ค. ๋ <code>#if postLoadingEffect</code> ์ <code>#unless Template.subscriptionsReady</code>๋ ๋ฐ์ดํฐ๊ฐ ๋ก๋ฉ์ค์ด๊ฑฐ๋, ํ
ํ๋ฆฟ์ด ์ค๋น๊ฐ ์๋ฃ๋์ง ์์ ๊ฒฝ์ฐ ๋ก๋ฉ ํจ๊ณผ๋ฅผ ๋ถ๋ฌ์ค๋ ์ญํ ์ ํฉ๋๋ค. </p>
<p><code>client/contents/post-lists.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line"><template name="postList"></div><div class="line"></div><div class="line"> <div class="row margin-top-20"></div><div class="line"> <div class="col-xs-12 col-md-12 table-border tableHeight padding-0 " ></div><div class="line"></div><div class="line"> <table class="table" ></div><div class="line"> <thead class=" table-header-bg"></div><div class="line"> <tr></div><div class="line"> <th class="tb-title">์ ๋ชฉ</th></div><div class="line"> <th class="align-center tb-user">์ฌ์ฉ์</th></div><div class="line"> <th class="align-center tb-view">์กฐํ</th></div><div class="line"> <th class="align-center tb-comment">๋๊ธ</th></div><div class="line"> <th class="align-centr tb-recommend">์ถ์ฒ</th></div><div class="line"> <th class="align-right tb-date">๋ ์ง</th></div><div class="line"> </tr></div><div class="line"> </thead></div><div class="line"> <tbody id="tableBoardList" ss></div><div class="line"> {{#each list}}</div><div class="line"> {{>postListItem}}</div><div class="line"> {{/each}}</div><div class="line"></div><div class="line"> {{#if endOfData}}</div><div class="line"> <p>๋์ด์ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.</p></div><div class="line"> {{/if}}</div><div class="line"></div><div class="line"> </tbody></div><div class="line"> </table></div><div class="line"> {{#if postLoadingEffect}}</div><div class="line"> {{>postLoadingItem}}</div><div class="line"> {{/if}}</div><div class="line"></div><div class="line"> {{#unless Template.subscriptionsReady}}</div><div class="line"> {{>postLoadingItem}}</div><div class="line"> {{/unless}}</div><div class="line"> </div></div><div class="line"></div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๋ค์์ ๊ฐ์ ํ์ผ์ ๋ฆฌ์คํธ ๋ด์ฉ์ ํด๋นํ๋ ํ
ํ๋ฆฟ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค. ์์์ ์ค๋ช
๋๋ฆฐ each๋ฅผ ํตํด ๋ฐ๋ณต๋๋ฉด์ ํ์๋๋ ๋ฆฌ์คํธ์ ๋ด์ฉ์ด๋ผ๊ณ ๋ณด์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ ์๋ต]</div><div class="line"></div><div class="line"><template name="postListItem"></div><div class="line"> <tr id="my-infinite-scrolling-list" pageCnt="{{pageCnt}}" ></div><div class="line"> <td class="tb-title"><p><a href="{{pathFor '/postView/:id' id=_id}}" name="#{{_id}}" class="goView" >{{postTitle}}</a></p></td></div><div class="line"> <td class="align-center tb-user"><p><a href="{{pathFor '/postView/:id' id=_id}}" class="goView">{{postUserName}}</a></p></td></div><div class="line"> <td class="align-center tb-view"><p><a href="{{pathFor '/postView/:id' id=_id}}" class="goView">{{postViewCount}}</a></p></td></div><div class="line"> <td class="align-center tb-comment"><p><a href="{{pathFor '/postView/:id' id=_id}}" class="goView">{{postCommentCount}}</a></p></td></div><div class="line"> <td class="align-center tb-recommend"><p><a href="{{pathFor '/postView/:id' id=_id}}" class="goView">{{postLikeCount}}</a></p></td></div><div class="line"> <td class="align-right tb-date"><p><a href="{{pathFor '/countTest'}}" class="goView">{{postDate}}</a></p></td></div><div class="line"> </tr></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๋ง์ง๋ง ํ
ํ๋ฆฟ์ ๋ก๋ฉํจ๊ณผ๋ฅผ ํ์ํด์ค ํ
ํ๋ฆฟ ์
๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ ์๋ต]</div><div class="line"></div><div class="line"><template name="postLoadingItem"></div><div class="line"> <div class="loading-bar"></div><div class="line"> <div class="loader"></div></div><div class="line"> </div></div><div class="line"></template></div><div class="line"></div><div class="line"></div><div class="line">`client/contents/post-lists.html`</div></pre></td></tr></table></figure>
<p>์ด์ ํ
ํ๋ฆฟ์ ์ ์ดํ js ํ์ผ์ ๋ง๋ค์ด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฐ์ <code>Template.postList.onCreated(function () {</code> ์์ ๋ด์ฉ์ ์์ฑํ๊ฒ ์ต๋๋ค. ๊ฐ ๋ด์ฉ์ ํ์ํ ๋ถ๋ถ๋ค์ ์ฃผ์์ ํตํด ์ค๋ช
ํด ๋์์ต๋๋ค. ์ฌ์ค ReactiveVar๋ pub/sub์ ๊ดํ ์์ธํ ๋ด์ฉ์ ๋์ค์ ๋ฐ๋ก ๊ฐ์ข๋ฅผ ๋ง๋ค์ด ์ค๋ช
ํด ๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. ํ์ง๋ง ์๋ ์๋ฆฌ์ ๋ํ ์๋๋ฆฌ์ค๋ ๊ฐ๋จํ ์ค๋ช
๋๋ฆฌ๊ฒ ์ต๋๋ค. </p>
<p> <code>self.autorun(function () {}</code>์์ ์ ์๋ <code>self.subscribe('posts', postCnt.get());</code>๊ฐ ์ด ์์คํ
์ ๊ฐ์ฅ ํต์ฌ์ ์ธ ๋ถ๋ถ์
๋๋ค. Meteor๋ ์ ์ฐจ์ ์ธ ๋ฐฉ์๊ณผ ํจ๊ป ์ ์ธ์ ์ธ ๋ฐฉ์์ ํจ๊ป ์ง์ํ๋ ํ๋ซํผ ์
๋๋ค. ์ฌ๊ธฐ์์ pub/sub ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ ์ธ์ ์ธ ๋ฐฉ์์ ์ด์ฉํด ํ์ด์ง์ ๊ตฌํํ ๋ถ๋ถ์
๋๋ค. ๋ง์ฝ ์ผ๋ฐ์ ์ธ ์ ์ฐจ์ ์ธ ๋ฐฉ์์ผ๋ก ๊ฒ์๊ธ์ ๋ฆฌ์คํธ๋ฅผ ๋ถ๋ฌ์จ๋ค๋ฉด ํ์ด์ง๋ฅผ ์ถ๊ฐ๋ก ๋ถ๋ฌ์ฌ ๋ถ๋ถ์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ํธ์ถํ function์ ํธ์ถํ๋ ๋ฐฉ๋ฒ์ผ๋ก ์๋์ด ๋ ๊ฒ์
๋๋ค. ํ์ง๋ง, ์ฌ๊ธฐ์๋ <code>self.subscribe('posts', postCnt.get());</code> ์ด๋ ๊ฒ ์ ์ธ์ ํด์ฃผ๊ณ ํ์ด์ง๋ฅผ ๋๋ ค์ผ ํ๋ ๊ฒฝ์ฐ <code>postCnt.set(postCnt.get() + 10);</code> ์ด๋ฐ์์ผ๋ก postCnt๋ง ์กฐ์ ํด์ฃผ๋ฉด ์๋ฒ์์ ํ์ํ ๋ถ๋ถ๋ง ์ถ๊ฐ๋๋ ์์ผ๋ก ์๋ํฉ๋๋ค. ์ฆ subscribe๋ฅผ ์ ์ธํด๋๊ณ Reactivar๋ก ์ ์๋ ๋ถ๋ถ๋ง ๋ณ๊ฒฝํด ์ฃผ๋ฉด ์์น์ ์๊ด์์ด ๋ฆฌ์คํธ์ ๋ฐ์ดํฐ๊ฐ ๋ณํ๋๋ค๊ณ ์๊ฐํ์๋ฉด ๋๊ฒ ์ต๋๋ค. ์ผ๋จ ์ด๋ถ๋ถ์ ๋ํ ์ ๊ฐ์ข๊ฐ ์์ผ๋ฏ๋ก ๋ค์ ๋งํฌ๋ฅผ ํตํด ๊ฐ๋จํ๊ฒ ๋๋ง ์๋ฆฌ๋ฅผ ๋ณด์ค ์ ์์ ๊ฒ์
๋๋ค. </p>
<blockquote>
<p>๋งํฌ : <a href="http://kr.discovermeteor.com/chapters/publications-and-subscriptions/" target="_blank" rel="noopener">pub/sub ์ค๋ช
</a></p>
</blockquote>
<p><code>client/contents/post-lists.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">Template.postList.onCreated(function () {</div><div class="line"></div><div class="line"> window.postCountAll = new ReactiveVar(0); // post์ ์ด ๊ฐ์๋ฅผ ์ ์ฅํ ์ ์ฅ์</div><div class="line"> window.postLoadingEffect = new ReactiveVar(false); // ๋ก๋ฉ ํจ๊ณผ๋ฅผ ๋ํ๋ผ์ง ๋ง์ง๋ฅผ ๊ฒฐ์ ํ ์ ์ฅ์</div><div class="line"> window.scrollRock = new ReactiveVar(false); // ์คํฌ๋กค๋ฐ๊ฐ ๋ก๋ฉ์ค์๋ ๋์ด์ ์ถ๊ฐ๋ก๋ฉ์ ํ์ง ์๋๋ก ํ ์ ์ฅ์</div><div class="line"> window.postCnt = new ReactiveVar(20); // ๋ถ๋ฌ์ฌ ํฌ์คํธ ๊ฐ์ ์ธํ
</div><div class="line"></div><div class="line"> var self = this;</div><div class="line"></div><div class="line"> Meteor.call('getPostCountAll', function (err, result) {</div><div class="line"> if(err) {</div><div class="line"> console.log(err.message);</div><div class="line"> }</div><div class="line"> else {</div><div class="line"> return postCountAll.set(result); // ํฌ์คํธ ๊ฐ์๋ฅผ method์์ ๋ถ๋ฌ์ postCountAll์ ์ ์ฅ.</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line"> self.autorun(function () {</div><div class="line"> self.subscribe('posts', postCnt.get()); // posts ๋ฆฌ์คํธ๋ฅผ ๋ถ๋ก์ฌ posts pub๋ฅผ ํธ์ถ</div><div class="line"> });</div><div class="line"></div><div class="line"> window.onscroll = function (ev) {</div><div class="line"> if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { // ์คํฌ๋กค์ด ๋ฐ๋ฅ์ ๋ฟ์ผ๋ฉด ๋ค์ ํ์ด์ง ์งํ</div><div class="line"></div><div class="line"> if(!(postCountAll.get() < postCnt.get()) && scrollRock.get() === false ) { // ํ์ด์ง๊ฐ ๋๋์ง ์์๊ฑฐ๋ ๋ก๋ฉ์ค์ด ์๋๋์๋ง ํ์ด์ง์๋ฅผ ์ฆ๊ฐํ๋ ์ด๋ฒคํธ ๋ฐ์</div><div class="line"></div><div class="line"> scrollRock.set(true); // ํ์ด์ง ์ฆ๊ฐ ์ ์ scrollRock์ true๋ก ํด์ ์ ๊ธ.</div><div class="line"></div><div class="line"> postLoadingEffect.set(true);</div><div class="line"> Meteor.setTimeout(function () {</div><div class="line"> postLoadingEffect.set(false);</div><div class="line"> scrollRock.set(false);</div><div class="line"> }, 1000);</div><div class="line"></div><div class="line"> postCnt.set(postCnt.get() + 10); // ํจ์์๋ฃฐ 10๊ฐ ์ฆ๊ฐ ์์ผ ์ค.</div><div class="line"> console.log('postCnt: ' + postCnt.get()); // ํ์ด์ง์ ๋ํ ๋ก๊ทธ</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure>
<p>๋ค์์ <code>Template.postList.helpers({})</code> ๋ก ํ
ํ๋ฆฟ์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ๋ ๋ถ๋ถ์
๋๋ค. </p>
<p><code>list</code>๋ ๋ฆฌ์คํธ์ ๋ฟ๋ ค์ง ํฌ์คํธ ๋ชฉ๋ก ๋ฐ์ดํฐ ์
๋๋ค. <code>endOfData</code>๋ ํ์ฌ ๋ถ๋ฌ์จ ํฌ์คํธ ๊ฐ์๊ฐ ์ ์ฒด ํฌ์คํธ ๊ฐ์๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ผ๋ฉด false๋ฅผ ๋ฆฌํดํด ๋์ด์ ํ์ด์ง ์ฆ๊ฐ ์ด๋ฒคํธ๊ฐ ์๋ํ์ง ์๋๋ก ํ๋ ์ญํ ์ ํฉ๋๋ค. <code>postLoadingEffect</code>๋ true์ผ ๊ฒฝ์ฐ ๋ก๋ฉ์ ๋ณด์ฌ์ค์ง ๋ง์ง์ ๋ํ true, false๋ฅผ ๋ํ๋ด๋ ์ญํ ์ ํฉ๋๋ค. </p>
<p><code>client/contents/post-lists.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">Template.postList.helpers({</div><div class="line"> list: function () {</div><div class="line"> return Posts.find({}, {sort: {postDate: -1}});</div><div class="line"> },</div><div class="line"> endOfData : function () {</div><div class="line"> return postCountAll.get() < postCnt.get() ? true : false;</div><div class="line"> },</div><div class="line"> postLoadingEffect: function () {</div><div class="line"> return postLoadingEffect.get();</div><div class="line"> }</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure>
<h4 id="4-2-ํฌ์คํธ-๋ด์ฉ๋ณด๊ธฐ"><a href="#4-2-ํฌ์คํธ-๋ด์ฉ๋ณด๊ธฐ" class="headerlink" title="4.2 ํฌ์คํธ ๋ด์ฉ๋ณด๊ธฐ"></a>4.2 ํฌ์คํธ ๋ด์ฉ๋ณด๊ธฐ</h4><p>๋ค์์ ๋ด์ฉ๋ณด๊ธฐ ์
๋๋ค. ๋ฆฌ์คํธ์ ๋งํฌ๋ฅผ ํด๋ฆญํ๋ฉด ์ ํ๋ ๋ฆฌ์คํธ์ ๋ด์ฉ์ ๋ณด์ฌ์ฃผ๋ ํ์ด์ง๊ฐ ๋๊ฒ ์ต๋๋ค.<br>์ฐ์ ํ
ํ๋ฆฟ๋ถํฐ ์์ฑํ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p><code>client/contents/post-view.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><template name="postView"></div><div class="line"> {{#with contentView }}</div><div class="line"> <div class="row margin-top-20"></div><div class="line"> <div class="col-xs-12 col-md-12 " ></div><div class="line"></div><div class="line"> <div class="content-wrap"></div><div class="line"> <div class="post-content-top"></div><div class="line"> <h1>{{postTitle}}</h1></div><div class="line"> </div></div><div class="line"> <div class="post-content-top"></div><div class="line"> <p>{{postUserName}}</p></div><div class="line"> <p class="post-date">{{postDate}}</p></div><div class="line"> </div></div><div class="line"> <div class="post-content-middle"></div><div class="line"> {{{postContent}}}</div><div class="line"> </div></div><div class="line"></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></div><div class="line"> {{/with}}</div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๊ทธ๋ฆฌ๊ณ ๋์ํ๋ js ํ์ผ์ ์์ฑํฉ๋๋ค. post-list๋ณด๋ค๋ ๋จ์ํ์ง๋ง ๊ตฌ์กฐ๋ ๋น์ทํฉ๋๋ค. <code>self.subscribe('postDetail', postIdSet.get());</code>๋ฅผ ์ ์ธํ๊ณ postIdSet์ ๋ฐ์ ๋ด์ฉ์ ์ ๋ฌํ๋ ๊ฒ์ด ์ ๋ถ์
๋๋ค. ์ฐธ๊ณ ๋ก postIdSet์ route์์ ์ ๋ฌ๋ฐ๊ณ ์์ต๋๋ค. (์์ ๋ผ์ฐํ
๋ถ๋ถ ์ฐธ๊ณ )</p>
<p><code>client/contents/post-view.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.postView.onCreated(function () {</div><div class="line"></div><div class="line"> var self = this;</div><div class="line"></div><div class="line"> self.autorun(function ()</div><div class="line"> {</div><div class="line"> self.subscribe('postDetail', postIdSet.get());</div><div class="line"> });</div><div class="line"></div><div class="line">});</div><div class="line"></div><div class="line">Template.postView.helpers({</div><div class="line"></div><div class="line"> contentView: function()</div><div class="line"> {</div><div class="line"> var postOne = Posts.findOne({_id: postIdSet.get()});</div><div class="line"> return postOne;</div><div class="line"> }</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure>
<h4 id="4-3-๋ฐ์ดํฐ-์ฃผ์
"><a href="#4-3-๋ฐ์ดํฐ-์ฃผ์
" class="headerlink" title="4.3 ๋ฐ์ดํฐ ์ฃผ์
"></a>4.3 ๋ฐ์ดํฐ ์ฃผ์
</h4><p>์ด์ ๊ธฐ๋ณธ์ ์ธ ํ์ด์ง๋ค์ ๋ชจ๋ ๋ง๋ค์์ต๋๋ค. ๋ค์์ผ๋ก ํด์ผํ ์ผ์ ๋ฆฌ์คํธ๋ก ์ฌ์ฉํ ๋ฐ์ดํฐ๋ฅผ ์ฃผ์
ํ๋ ์ผ์
๋๋ค.<br>์ฝ๋๋ฅผ ์ค๋ช
๋๋ฆฌ๋ฉด Meteor๊ฐ ์์๋ ๋ ๋๋น์ ๋ฐ์ดํฐ๊ฐ ์์ผ๋ฉด fixture๋ฅผ for ๋ฌธ์ผ๋ก ๋๋ฉด์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ฃผ์
ํ๋ ์์ค์
๋๋ค. ๋ค์ ๋งํฌ์์ ์์ค๋ฅผ ๋ณต์ฌํด ์ฌ์ฉํ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>๋งํฌ : <a href="https://github.com/freeseamew/meteor-infinit-scroll/blob/master/server/fixture.js" target="_blank" rel="noopener">fixture.js</a></p>
</blockquote>
<p><code>server/fixture.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">var fixture = [</div><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">๋ฐ์ดํฐ</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line">]</div><div class="line"></div><div class="line">Meteor.startup(() => {</div><div class="line"> if(Posts.find().count() === 0) {</div><div class="line"> console.log('๋ฐ์ดํฐ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค fixture ๋ฐ์ดํฐ๋ฅผ ์
๋ ฅํฉ๋๋ค.');</div><div class="line"></div><div class="line"> for(var i=0, len=250; i<len; i++) {</div><div class="line"> Posts.insert((fixture[i]));</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure>
<p>์ด์ ํฐ๋ฏธ๋ ์ฐฝ์์ ๋ค์ ๋ช
๋ น์ ์คํํด ์๋ฒ๋ฅผ ์คํํด ๋ณด๊ฒ ์ต๋๋ค. ์ ์์ ์ผ๋ก ์๋ํ๋ค๋ฉด, <code>http://localhost:3000</code> ๋ก ํ์ด์ง์ ์ ์ํ ์ ์์ ๊ฒ์
๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">meteor run</div></pre></td></tr></table></figure>
<p>์ฌ๊ธฐ๊น์ง๋ ๋ฌดํ์คํฌ๋กค์ ๊ตฌ์ฑํ๋ ๊ฐ์ข์์ต๋๋ค. ์ด์ด์ ๋ฐ๋ก ๋ค์ ๊ฐ์ข์์๋ ๋ฌดํ์คํฌ๋กค์ ๋ฌธ์ ์ ๊ณผ ๊ทธ ํด๊ฒฐ๋ฐฉ์์ ๋ํด์ ๋ค๋ฃจ์ด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>์์ค์ฝ๋ ๋งํฌ<br><a href="https://github.com/freeseamew/meteor-infinit-scroll" target="_blank" rel="noopener">https://github.com/freeseamew/meteor-infinit-scroll</a></p>
</blockquote>
]]></content>
<summary type="html">
<h3 id="0-๊ฐ์ข-์๊ฐ"><a href="#0-๊ฐ์ข-์๊ฐ" class="headerlink" title="0. ๊ฐ์ข ์๊ฐ"></a>0. ๊ฐ์ข ์๊ฐ</h3><p>๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํ๋ค ๋ณด๋ฉด ์์ฐ์ค๋ฝ๊ฒ ๋ง๋๊ฒ ๋๋ ๋ฌธ์ ๊ฐ ์๋๋ฐ ๊ทธ๊ฒ์ ๋ธ๋ผ์ฐ์ ๋ค๋ก
</summary>
<category term="meteor, inifinit scroll, history back" scheme="http://freeseamew.github.io/tags/meteor-inifinit-scroll-history-back/"/>
</entry>
<entry>
<title>๋ฌดํ ์คํฌ๋กค ๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ํด๊ฒฐ 2</title>
<link href="http://freeseamew.github.io/2017/12/02/meteor-Infinite-scroll-2/"/>
<id>http://freeseamew.github.io/2017/12/02/meteor-Infinite-scroll-2/</id>
<published>2017-12-01T15:40:32.000Z</published>
<updated>2017-12-03T05:38:39.000Z</updated>
<content type="html"><![CDATA[<h3 id="5-๋ฌดํ์คํฌ๋กค์-๋ฌธ์ ์ -๋ฐ-ํด๊ฒฐ๋ฐฉ๋ฒ"><a href="#5-๋ฌดํ์คํฌ๋กค์-๋ฌธ์ ์ -๋ฐ-ํด๊ฒฐ๋ฐฉ๋ฒ" class="headerlink" title="5. ๋ฌดํ์คํฌ๋กค์ ๋ฌธ์ ์ ๋ฐ ํด๊ฒฐ๋ฐฉ๋ฒ"></a>5. ๋ฌดํ์คํฌ๋กค์ ๋ฌธ์ ์ ๋ฐ ํด๊ฒฐ๋ฐฉ๋ฒ</h3><h4 id="5-1-๋ฌดํ์คํฌ๋กค-๋ฌธ์ ์ "><a href="#5-1-๋ฌดํ์คํฌ๋กค-๋ฌธ์ ์ " class="headerlink" title="5.1 ๋ฌดํ์คํฌ๋กค ๋ฌธ์ ์ "></a>5.1 ๋ฌดํ์คํฌ๋กค ๋ฌธ์ ์ </h4><p>์ ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ์ด๋ ๊ฒ ๋ง๋ค์ด์ง ๋ฌดํ ์คํฌ๋กค์ ๋ฌธ์ ์ ์ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ผ๋จ ์๋ฒ๋ฅผ ์คํ์ํค๋ก ์คํํ ์ฃผ์๋ก ์ ์ํด ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๋ฌผ์ ๋ณผ ์ ์์ ๊ฒ์
๋๋ค.<br>ํ๋ฉด์ ๋ณด์๋ฉด ์คํฌ๋กค์ ์ด์์์ด ์ ์๋ํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ํ์ง๋ง ๋ชฉ๋ก ์ค์์ ํ๋๋ฅผ ํด๋ฆญํด ๋ด์ฉ๋ณด๊ธฐ๋ก ๊ฐ๋ค๊ฐ ๋ธ๋ผ์ฐ์ ์ ๋ค๋ก๊ฐ๊ธฐ๋ฅผ ํด๋ฆญํด ๋ค์ ๋ฆฌ์คํธ๋ก ๋์์ค๋ฉด ๋ชจ๋ ๋ฆฌ์คํธ๊ฐ ์ด๊ธฐํ ๋์ด ์ฒ์ ํ์ด์ง๊ฐ ๋ณด์ฌ์ง๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ด ๋ง์ ๋ฆฌ์คํธ๋ฅผ ์ด์ฉํด ์๋ง์ ํ์ด์ง๋ฅผ ๋๊ธฐ๋ค๊ฐ ๋ณผ๋งํ ๋ด์ฉ์ด ์์ด ํด๋น ๋ถ๋ถ์ ํด๋ฆญํ๊ณ ๋ค์ ๋์์ค๋ฉฐ ๊ทธ ์์น๊น์ง ๋ ๋ค์ ๋ด๋ ค๊ฐ์ผ ๋ค์ ๋ด์ฉ์ ๋ณผ ์ ์๋ ์น๋ช
์ ์ธ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ณ ์๋ ๊ฒ์
๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/8Cs9Tt60K7RjcQKYZHlb_p0oYJC6Sb_HEKhzomBjf1WEyKfl1RCwnIumWSRDzBwUc7BiM3ZSeqTwX9pz81GMmcQKG6Vjk3K6o7AuUaiEC8DUJUZMHA0ePa1AGsqOPB77BDd4GYM0d9hUyRsL6ZsGiPlPGvcfl1sbEjugA_dyCBhsdANd8uVUFBKdnO2GR0DpzHsysFtCYF7qp2dmmjhG3vAgnGB-TMr1Pw03qTGwgY8NF4rv8UT4Zpu-DQMQZcq8i2Sa_jPtROWKG4GCVLVLSQfqmq8TH_JKJogoatuDbdd2DZBFpsED9szX2BxvSx-AYDf3MhnrgWPFqOijFJq7FpCuVc2zjNQScgjqO04ZRgSUmxhQs3lKd7xDn2q-k6KkFUhb4xrsXVvSX6zEx9IMJIXUsXfCWBrWFjmJH-cMpO9bkvHjOm_QLVs6-DebG_z0LxLbFlknvpOwZe8y_TAvFawzwi9SUIeS1SS39vN67uQXoNzRluWYt4rRo3Y4j4Lb9cVqd3TWCNiBR0xYT7eI4k2B_dFAwcDjubmgkNjTe0KKZdWA7m2Nl8Jj56qmOLq3QBaAE5gcnqZJcZx1chgeEv2Wfb277L8OgKFI_EjXj6I=w1338-h874-no"></p>
<p></p><p>[๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ํ๋ฉด]</p><p></p>
<h4 id="5-2-ํด๊ฒฐ๋ฐฉ๋ฒ"><a href="#5-2-ํด๊ฒฐ๋ฐฉ๋ฒ" class="headerlink" title="5.2 ํด๊ฒฐ๋ฐฉ๋ฒ"></a>5.2 ํด๊ฒฐ๋ฐฉ๋ฒ</h4><p>์ ๊ทธ๋ผ ์ด ๋ฌธ์ ๋ฅผ ํ๋จ๊ณ์ฉ ํด๊ฒฐํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฐ์ <code>pub/sub</code>์ ์ด์ฉํด ๋ฆฌ์คํธ๋ก ๋ฟ๋ ค์ง ๊ฒฐ๊ณผ๊ฐ ์ด๊ธฐํ ๋์ง ์๊ฒ ํ๋ ๋ถ๋ถ๋ถํฐ ์ฒ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค. ์์์ ์ค์น ํจํค์ง ์ค์ <code>meteorhacks:subs-manager</code> ๋ผ๋ ํจํค์ง๋ฅผ ์ค์นํ๋๋ฐ์. ์ด๋
์์ด ๋ฐ๋ก ์ผ์ข
์ subscriptions(๊ตฌ๋
)์ ๋ํ ์บ์ฌ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํํค์ง๊ฐ ๋๊ฒ ์ต๋๋ค. </p>
<p>์ฌ์ฉ๋ฒ์ ์์ฃผ ๊ฐ๋จํฉ๋๋ค. ๋ค์ํ์ผ์ ์ด๊ณ ์ฃผ์์ผ๋ก ์ฒ๋ฆฌ๋ ๋ถ๋ถ์ ์ถ๊ฐ ๋๋ ์์ ํ์๋ฉด ๋ฉ๋๋ค. </p>
<p><code>client/contents/post-lists.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">Template.postList.onCreated(function () {</div><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line"> window.postCnt = new ReactiveVar(20);</div><div class="line"></div><div class="line"> var self = this;</div><div class="line"> var subs = new SubsManager(); // ์ถ๊ฐ ๋ด์ฉ</div><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line"></div><div class="line"> self.autorun(function () {</div><div class="line"> subs.subscribe('posts', postCnt.get()); // self๋ฅผ subs๋ก ๋ณ๊ฒฝ</div><div class="line"> });</div></pre></td></tr></table></figure>
<p>์ ์ด์ ๊ฒฐ๊ณผ๋ฅผ ๋ณผํ
๋ฐ์. ํ์ฌ subscriptions(๊ตฌ๋
) ๋๊ณ ์๋ ๋ด์ฉ์ ๋ณด๊ธฐ ์ํด์ ํจํค์ <code>msavin:mongol</code> ๋ฅผ ์ค์นํด์ ๊ตฌ๋
๋ด์ฉ์ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฐธ๊ณ ๋ก <code>msavin:mongol</code> ํจํค์ง๋ meteor๋๋ฒ๊ทธ ํด๋ก์ ํ์ฌ ํ๋ฉด์์ pub/sub ์ด ์ ์์ ์ผ๋ก ์ผ์ด๋๊ณ ์๋์ง collection์ ๋ชจ๋ํฐ๋ง ํ ์ ์๋ ํด์
๋๋ค. ๊ฒ์ํด๋ณด์๋ฉด ์ด ํด์ ๋ํ ์์ธํ ๋ด์ฉ๋ค์ ์ฝ๊ฒ ์ ์ ์์ ๊ฒ ์
๋๋ค. ์ฌ์ฉ๋ฒ์ ๋ธ๋ผ์ฐ์ ์์ ์๋์ฐ๋ <code>ctrl + m</code> ๋งฅ์ <code>control + m</code> ๋ฅผ ์
๋ ฅํ๋ฉด ๋ฉ๋๋ค. </p>
<p>์ ์ด์ ๋ค์ ์คํํด ๋ณด๊ฒ ์ต๋๋ค. ๋ณด์๋ ๋ฐ์ ๊ฐ์ด ๋ด์ฉ์ ๋ณธ ํ ๋ค๋ก ๊ฐ๊ธฐ๋ฅผ ํด๋ ๊ธฐ์กด์ ๊ตฌ๋
๋ subscriptions์ด ์ด๊ธฐํ ๋์ง ์๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค .</p>
<p><img src="https://lh3.googleusercontent.com/19Yt1pkvdJnFloj1IflNbYIut1krn0oNPTPJZflvyG_7GmaN-vqHf9eJk0ApAEoQMTUmLc6NV5saQwoUjbLjifx2QADAJPRC0XCZ-6Ed00RbRwBQ6AJjqXnxpgBKBMl7u2iWEBxgPvKUpTPXI3tA0kLVcoW9fNpv_-ZEYN-AxbkfSVquDcaPDn7dajHJj5wdhhu_SXw1uR7XV9aE-5WU9xqdE_r45qVQqA1GbQzirHpRWq7ZU3N--rr-nL5ieu8NNA5elqmWZdp-fLCuV-sydlSU5via7IAAODC6YQM33OlaY4MM4PzmSyCC5KpOy_TeJ8YSyVtiz-QNUKXdStOwGI2dUcUf1kcewTFBGpvvTanrzDrA-cAWDPhaomkQ8EfszmRzGg1Z3LmTAiB6ylhw8Jk966gXhr9tlpyqDdE7ItIRNRfEkeCsyZC7DppHo3OykQZQL7_3panX8loT6OmFvH2JCHvE6zszvIrHqKjdXEfTPwMesx6i22k8WyJjIC6rbj6Cz3dFb23kP2tZ4psJ2MJaE7AqPCU4iWsyvn_bg50qZFFKxRO3B1Syx5D7UXTW-bl45kQl1gTSnsX_QVjiWLFgFE3yw2fK1-cK9E73Zw0=w1143-h747-no"></p>
<p></p><p>[subs-manager ์ ์ฉ ํ๋ฉด]</p><p></p>
<p>๋ค์์ผ๋ก ํด๊ฒฐํด์ผํ ๋ฌธ์ ๋ ์คํฌ๋กค์ ์์น๋ฅผ ๊ธฐ์ตํ๋ ๊ฒ์
๋๋ค. ์ด ๋ฌธ์ ์ญ์๋ ํด๊ฒฐํด์ค ํจํค์ง๊ฐ ์๋๋ฐ <code>tomwasd:flow-router-autoscroll</code> ๋ผ๋ ํจํค์ง๊ฐ ๋๊ฒ ์ต๋๋ค. ๋ค์์ ์ฐธ๊ณ ๋ก ํจํค์ง๋ง ์ค์นํ๋ฉด ์๋ํฉ๋๋ค. </p>
<blockquote>
<p>meteor add tomwasd:flow-router-autoscroll</p>
</blockquote>
<p>์ค์น ํ ์คํ์ ์์ผ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๋ค๋ก๊ฐ๊ธฐ๋ก ๋์์๋ ์ด์ ์ ์์น๋ก ์คํฌ๋กค์ด ๋์์จ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/lsTs5dk6_tNnSvEKNsLCCFCFn2eM32WhNpXG3peMvodTebRMPWqRFWtxB6OATnhjzYjGgaJaHZ0uVZJ0oJytHFlmODtLiDwx9BDf0xEWIsqvoRngGvQus31r-5esHYjNorjhnKwaViJyGRaSgh6ZL69TQiH24QJBTWUzL8Sy7c_k5zAbVF-IVhavpuqbZy626c3E12Mmbk3HIIJ8VmAa3nF_0Elh7vIFFCmn84rpK7fZkUTgQFNNKbilyGUz7p413x_UHzq2odAviCVeq2PJHnxukYSkb5Hc1EJeBkH0W_XzM8nPZndBE6HYaW_57VOdP16EPHcb2saxPzIJKGTV841PzXoy8c-txdEXeWcpc8oaam8tn540ppqx1xzpaOsRynwtkCMrWTVFq_2BIi1osDj6a7E7I1OnwqwXA5hpJDtxJ3WX3b79MmOzj5mVe4IE07ldZMxZjuEueHkCDCx7nkrR0adqEZELaueWUT4B1BrkYDycZE35PI_yb7C8o3__mKdPZ5N8Y_eN2jDYrtsWFx9zmsfhdzGwbNYjkZuE429zbVXwUQ4CGbnb1bwONGs8CyL07u3Kc3lqbq6ir7KSc49LdzdTujwfphA-tb-dhpA=w1143-h748-no"></p>
<p></p><p>[subs-manager ์ ์ฉ ํ๋ฉด]</p><p></p>
<p>ํ์ง๋ง ์ฌ๊ธฐ์ ๋์ ์๋๋๋ค. ์์ง ๋ฌธ์ ๊ฐ ์์ ํ ํด๊ฒฐ๋์ง ์์๋๋ฐ์. ๋ฐ๋ก <code>postCnt</code>๋ฌธ์ ์
๋๋ค. ํ์ฌ ์บ์ฌ๋ฅผ ์ด์ฉํด subscriptions(๊ตฌ๋
) ๋ ๋ด์ฉ์ ์บ์๋๊ณ ์์ง๋ง, ๋ฌธ์ ๋ ์ด ์ํ์์ ๋ค์ ๋ค์ํ์ด์ง๋ฅผ ๋ถ๋ฌ๋ณด๋ฉด <code>postCnt</code> ๊ฐ ์ด๊ธฐํ ๋์ด ์์ด postCnt๊ฐ ์ฒ์ ๋ก๋ฉ๋๋ 20๋ถํฐ ~ ๋ค์ํ์ด์ง ๊น์ง ์์ฐจ์ ์ผ๋ก ๋ค์ ๋ก๋ฉ์ ํ๋ ์ฌ๊ฐํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.</p>
<p>์ด๋ถ๋ถ์ ํด๊ฒฐํ๊ธฐ ์์ฑ ์ฒ์ ์๊ฐํ ๋ฐฉ๋ฒ์ ํ์ด์ง๊ฐ ๋ณ๊ฒฝ๋๋ฉด url์ ํ์ฌ post๊ฐ์๋ฅผ ๋ฃ์ด์ค ๋ค์ ๊ทธ๊ฒ์ ๋ฐ์์ ์ฌ์ฉํ๋ฉด ๋์ง ์์๊น ํ๊ณ ์๊ฐํ์ต๋๋ค. ํ์ง๋ง ์ด๋ ๊ฒ ๋๋ฉด ํ์ด์ง๊ฐ ๋์ด๊ฐ ๋๋ง๋ค url์ด ๋ณ๊ฒฝ๋์ด authscroll์ ์ํด ๊ณ์ํด์ ๋งจ ์ ํ์ด์ง๋ก ๊ฐ๋ฒ๋ฆฌ๋ ํ์์ด ๋ฐ์ํ์ต๋๋ค. ๊ทธ๋์ ์ด ๋ฐฉ๋ฒ์ ์๋๋ ๊ฒฐ๋ก ์ด ๋ค์ด ๊ณ ๋ฏผํ๋ค ๋ฐ๊ฒฌํ ํด๊ฒฐ๋ฐฉ๋ฒ์ autoscroll ํจํค์ง๋ฅผ ์์ ํด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ด ์ข๊ฒ ๋ค๋ ๊ฒฐ๋ก ์ ๋ด๋ ธ์ต๋๋ค. ์ค์ ๋ก autoscroll ํจํค์ง์ ๊ตฌ์กฐ๋ ๋งค์ฐ ๋จ์ํ ํํ์
๋๋ค.<br>๊ทธ๋ผ ์ด์ ๋ถํฐ ์ด๋ป๊ฒ autoscroll์ ์์ ํ ์ง ์์๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฐ์ autoscroll์ ์ดํจํค์ง๋ฅผ ์ญ์ ํด ์ฃผ์ธ์. </p>
<blockquote>
<p>meteor remove tomwasd:flow-router-autoscroll</p>
</blockquote>
<p>๊ทธํ์ ๋ค์ ์์ค๋ฅผ autoscroll.js ์ ์
๋ ฅํด์ฃผ์ธ์. ์๋ ์์ค๋ ์กฐ๊ธ ์ ์ญ์ ํ low-router-autoscroll ๋ด์ฉ์ด ๋๊ฒ ์ต๋๋ค. ์ด ์์ค์ ํต์ฌ์ ์ธ ๊ธฐ๋ฅ์ <code>saveScrollPosition</code>, <code>scrollToTop</code> ๋๊ฐ์ง ํจ์๊ฐ ๋๊ฒ ์ต๋๋ค. <code>saveScrollPosition</code>์ ์คํฌ๋กค์ ์์น (<code>$(window).scrollTop();</code>)๋ฅผ ์ ์ฅํ๋ ํจ์์ด๊ณ <code>scrollToTop</code>๋ ๋ฆฌ์คํธ ํ์ด์ง๋ก ๋์์์ ๋ ์ ๋น๋ ์คํฌ๋กค์ ์์น๋ก ๋ณด๋ด์ฃผ๋ ์ญํ ์ ํ๋ ํจ์์
๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ๋์ Flowrouter์์ ์ ๊ณต๋๋ ๊ธฐ๋ฅ์ ํตํด ํ์ํ ๋์ ์๋์ ํฉ๋๋ค. <code>FlowRouter.triggers.exit</code>๋ ํ์ด์ง๋ฅผ ๋๊ฐ ๋ ๊ทธ๋ฆฌ๊ณ <code>FlowRouter.triggers.enter</code> ๋ ํ์ด์ง๋ก ๋ค์ด์ฌ ๋ ๊ฐ๊ฐ ํจ์๋ค์ ์คํ์์ผ ์ฃผ๋ ์ญํ ์ ํ๋ค๊ณ ์๊ฐํ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p><code>client/autoscroll.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div></pre></td><td class="code"><pre><div class="line">(function () {</div><div class="line"></div><div class="line"> FlowRouterAutoscroll = {</div><div class="line"> animationDuration: 200,</div><div class="line"> };</div><div class="line"> </div><div class="line"> var scrollPositions = {};</div><div class="line"> var backToPosition;</div><div class="line"> </div><div class="line"> // Keep track of the last position for every page in case we return to it</div><div class="line"> // via the back button or history.</div><div class="line"> var saveScrollPosition = function () {</div><div class="line"> scrollPositions[window.location] = $(window).scrollTop();</div><div class="line"> };</div><div class="line"> </div><div class="line"> window.onpopstate = function(event) {</div><div class="line"> // We used the back button, find the position we were at on that page</div><div class="line"> // last time</div><div class="line"> backToPosition = scrollPositions[window.location];</div><div class="line"> };</div><div class="line"> </div><div class="line"> // Scroll to the right place after changing routes. "The right place" is:</div><div class="line"> // 1. The previous position if we're returning via the back button</div><div class="line"> // 2. The top of page otherwise</div><div class="line"> var scrollToTop = function () {</div><div class="line"> // defer until after the DOM update so that the position can be correct</div><div class="line"> Tracker.afterFlush(function () {</div><div class="line"> var position;</div><div class="line"> </div><div class="line"> if (backToPosition) {</div><div class="line"> position = backToPosition;</div><div class="line"> backToPosition = null;</div><div class="line"> }</div><div class="line"> else {</div><div class="line"> position = 0;</div><div class="line"> }</div><div class="line"> </div><div class="line"> $('body,html').animate({</div><div class="line"> scrollTop: position</div><div class="line"> }, FlowRouterAutoscroll.animationDuration);</div><div class="line"> });</div><div class="line"> };</div><div class="line"> </div><div class="line"> FlowRouter.triggers.exit([saveScrollPosition]);</div><div class="line"> FlowRouter.triggers.enter([scrollToTop]);</div><div class="line"> </div><div class="line">}).call(this);</div></pre></td></tr></table></figure>
<p>์ด์ ์์ ์์ค๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํด ๋ณด๊ฒ ์ต๋๋ค. ์ฐ์ postCnt์ ๋ํ ReactiveVar ์ ์ธ์ autoscroll.js์์ ํด์ค๋๋ค. ๊ทธ๋ฆฌ๊ณ post-lists.js ์ ์๋ <code>window.postCnt = new ReactiveVar(20);</code> ์ด๋ถ๋ถ์ ์ญ์ ํด ์ฃผ๊ฒ ์ต๋๋ค. ํ์ด์ง๋ฅผ ๋๊ฐ ๋ <code>FlowRouter.triggers.exit([saveScrollPosition]);</code> ์ ๊ธฐ์กด์๋ ์คํฌ๋กค์ ์์น๋ง ์ ์ฅํ๋ ํํ์ด์ง๋ง ์ด์ postCnt๋ ํจ๊ป ์ ์ฅํ๋๋ก ์์ค๋ฅผ ๋ณ๊ฒฝํ์ต๋๋ค. ์ด์ <code>saveScrollPosition</code> ํจ์๋ฅผ ํธ์ถํ๋ฉด scrollPosion๊ณผ postCnt(๋ก๋๋ ํฌ์คํธ ์) ๋๊ฐ์ง๊ฐ ์ ์ฅ๋๊ฒ ๋ฉ๋๋ค. ๋ง์ฐฌ๊ฐ์ง๋ก <code>scrollToTop</code> ํจ์๊ฐ ์คํ๋ ๋๋ ์คํฌ๋กค ์์น๋ฅผ ๋ถ๋ฌ ์ด๋์์ผ ์ฃผ๋ ๊ฒ๊ณผ ๋์์ <code>postCnt(๋ก๋๋ ํฌ์คํธ ์)</code> ๋ ๊ทธ๋๋ก ์ธํ
๋๊ฒ ๋ฉ๋๋ค. ์๋๋ฅผ ์ฐธ๊ณ ๋ก ์ด์ ์์ค๋ฅผ ์์ ํด ์ฃผ์ธ์.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">(function () {</div><div class="line"></div><div class="line"> window.postCnt = new ReactiveVar(); </div><div class="line"></div><div class="line"> var scrollPositions;</div><div class="line"> var backToPosition; </div><div class="line"></div><div class="line"> var postCntGet; </div><div class="line"> var backToPage; </div><div class="line"></div><div class="line"> var saveScrollPosition = function () {</div><div class="line"></div><div class="line"> scrollPositions = $(window).scrollTop(); </div><div class="line"> postCntGet = postCnt.get(); </div><div class="line"> };</div><div class="line"></div><div class="line"> window.onpopstate = function(event) {</div><div class="line"> backToPosition = scrollPositions;</div><div class="line"> backToPage = postCntGet; </div><div class="line"> };</div><div class="line"></div><div class="line"> var scrollToTop = function () {</div><div class="line"></div><div class="line"> Tracker.afterFlush(function () {</div><div class="line"> var position;</div><div class="line"></div><div class="line"> if (backToPosition) {</div><div class="line"> position = backToPosition;</div><div class="line"> backToPosition = null;</div><div class="line"> }</div><div class="line"> else {</div><div class="line"> position = 0;</div><div class="line"> }</div><div class="line"></div><div class="line"> if(postCntGet)</div><div class="line"> {</div><div class="line"> postCnt.set(postCntGet);</div><div class="line"> }</div><div class="line"> else {</div><div class="line"> postCnt.set(20);</div><div class="line"> }</div><div class="line"></div><div class="line"> $('body,html').animate({</div><div class="line"> scrollTop: position</div><div class="line"> }, 1);</div><div class="line"> });</div><div class="line"> };</div><div class="line"></div><div class="line"> FlowRouter.triggers.exit([saveScrollPosition]);</div><div class="line"> FlowRouter.triggers.enter([scrollToTop]);</div><div class="line"></div><div class="line">}).call(this);</div></pre></td></tr></table></figure>
<p>์ ์ด์ ๊ฒฐ๊ณผ๋ฅผ ์คํํด ๋ณด๊ฒ ์ต๋๋ค. ๊ทธ๋ฌ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์คํฌ๋กค์ ์ด์ฉํด ํ์ด์ง๋ฅผ ๋ด๋ฆฌ๋ค, ๋ด์ฉ์ ๋ณด๊ณ ๋ค์ ๋์์๋ ์ด์ ๊น์ง์ ๋ฐ์ดํฐ๋ ๋ฌผ๋ก ์คํฌ๋กค ์์น๋ ๊ธฐ์ตํด ์ด๋์์ผ ์ค ๊ฒ์ ๋ณผ ์ ์์ ๊ฒ์
๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/uJ7ivOgvakCJ8dCXQaKRIZ9PGsp7r71-Dl7JUV-DFAyt9KN9We3Bf4Yd8WPIlFKNJumNa6vOqU4CHTIvA4mvRYFplOdMUcBX6EeEa6R0L6LeRn3cntDJrJ85wPAXOhlKPstykYr-XVahCXliqNQxq9h9olCHeuUI6WIlS2t4dBvJivnfTNYhXxsvxuqWkqSuOgAHKBheQjETJ-wMwG0vkVnzVRC990XR8J_LqKGHZkRy4wkHUYMkiSQdNE_wi8ROXUSOkN7L071M22W43k54-XUfku7XdiELLGAFwCsufG-mXCvipWl4nBUomXGyjIFkNEZCVlofjeed8itzBhPzyVNI5e_VnsWpAcavgqv6x8_GpQJ67aP6UliYfsiu9LxDiu8vgUBKjfie7z1z9gcj6RGc8bEvFDErEmQ85geamnBqy4zaNgjTUt9SZ50HkaKDrM9HzbsEZAPiQPgQwcUCiER2Hjdb6jUcganxW2OToyW5FC4MTuseWcFAbA8HWCfQEQqwEPR-tugeNSzLg4AUgwf3rHHBaA01R6Yc-b81UC0ODVSyswT_soyw89H9IM4Vp7-zQI9XRdmIG4ovPtHMbM7bFDAxw_bAP9jRrFO4Uho=w1230-h803-no"></p>
<p>[์ต์ข
๊ฒฐ๊ณผ๋ฌผ]</p>
<p>์ฐธ ๋ณ๊ฑฐ ์๋๊ฒ ๊ฐ์ ๊ธฐ๋ฅ์ด์ง๋ง, ์ด ๊ธฐ๋ฅ์ ๋ํ ๊ตฌํ ์ ๋ณด๊ฐ ๋ง์ง ์์ ๊ฒ๋ ์ฌ์ค์ผ ๊ฒ์
๋๋ค. (ํน์ ์ ๊ฐ ๊ฒ์์ ์ง์ง๋ฆฌ๋ ๋ชปํ๊ฑฐ๋ ใ
ใ
) ํน์ ์ด๋ถ๋ถ์ ๋ํด์ ๊ณ ๋ฏผํ๋ ๋ถ์ด ์์ผ์๋ค๋ฉด ์กฐ๊ธ์ด๋๋ง ๋์์ด ๋์๋ฉด ์ข๊ฒ ๋ค์.</p>
<p>๋ค์ ๊ฐ์ข๋ ์ธ์ ๋ผ๊ณ ๋ง์๋๋ฆฌ๊ธด ๊ทธ๋ ์ง๋ง, ๊ทธ๋๋ ์กฐ๊ธ๋ ๊ธฐ๋ณธ๋ถํฐ ์ค์ฉ์์ ๊น์ง ์ฐจ๊ทผ์ฐจ๊ทผ ์์ฑํด๋ณผ๊น ์๊ฐ์ค์ ์์ต๋๋ค. ์๋ง๋ blaze๊ฐ ์๋ vue๋ฅผ ์ฌ์ฉํ ํ ๊ฒ ๊ฐ๊ธฐ๋ ํฉ๋๋ค. </p>
<p>๊ทธ๋ผ ๋ค์์ ๋ ๋ง๋์ ^^</p>
<blockquote>
<p>์์ค์ฝ๋ ๋งํฌ<br><a href="https://github.com/freeseamew/meteor-infinit-scroll" target="_blank" rel="noopener">https://github.com/freeseamew/meteor-infinit-scroll</a></p>
</blockquote>
]]></content>
<summary type="html">
<h3 id="5-๋ฌดํ์คํฌ๋กค์-๋ฌธ์ ์ -๋ฐ-ํด๊ฒฐ๋ฐฉ๋ฒ"><a href="#5-๋ฌดํ์คํฌ๋กค์-๋ฌธ์ ์ -๋ฐ-ํด๊ฒฐ๋ฐฉ๋ฒ" class="headerlink" title="5. ๋ฌดํ์คํฌ๋กค์ ๋ฌธ์ ์ ๋ฐ ํด๊ฒฐ๋ฐฉ๋ฒ"></a>5. ๋ฌดํ์คํฌ๋กค์ ๋ฌธ์ ์ ๋ฐ ํด๊ฒฐ๋ฐฉ๋ฒ</h3><h4
</summary>
<category term="meteor, inifinit scroll, history back" scheme="http://freeseamew.github.io/tags/meteor-inifinit-scroll-history-back/"/>
</entry>
<entry>
<title>Meteor custom account ๊ฐ์ข 5</title>
<link href="http://freeseamew.github.io/2017/07/04/meteor-account-tutorial-5/"/>
<id>http://freeseamew.github.io/2017/07/04/meteor-account-tutorial-5/</id>
<published>2017-07-03T15:45:03.000Z</published>
<updated>2017-07-05T02:47:37.000Z</updated>
<content type="html"><![CDATA[<h3 id="8-๋ค๋ฅธ-์๋น์ค-api๋ฅผ-ํตํ-๋ก๊ทธ์ธ-facebook-google-twitter-kakao"><a href="#8-๋ค๋ฅธ-์๋น์ค-api๋ฅผ-ํตํ-๋ก๊ทธ์ธ-facebook-google-twitter-kakao" class="headerlink" title="8. ๋ค๋ฅธ ์๋น์ค api๋ฅผ ํตํ ๋ก๊ทธ์ธ(facebook, google, twitter, kakao)"></a>8. ๋ค๋ฅธ ์๋น์ค api๋ฅผ ํตํ ๋ก๊ทธ์ธ(facebook, google, twitter, kakao)</h3><p>์ด์ meteor ์ฌ์ฉ์ ์ ์ ๊ณ์ (coustom account) ๊ฐ์ข์ ๋ง์ง๋ง ์ฑํฐ์ ๋ํด์ ์ค๋ช
๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. ์ด์ฑํฐ์์๋ ๊ฐ์ข
SNS ๋ฐ ์ธ๋ถ ์๋น์ค๋ฅผ ํตํ ๋ก๊ทธ์ธ ์ฐ๋์ ๊ตฌํํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ ๋ฒ ๊ฐ์ข์๋ ์กฐ๊ธ ๋ง์๋๋ ธ์ง๋ง ์ด ๊ฐ์ข๋ฅผ ํ๋ฒ ์จ๋ณผ๊น ๋ผ๊ณ ์๊ฐํ ๊ฒ์ด ์ด ์ธ๋ถ ์๋น์ค ์ฐ๋์ ํ
์คํธ ํด๋ณด๋ฉด์ ์์ต๋๋ค. ์ฒ์์ ์กฐ๊ธ ํค๋งค์ด๊ธฐ๋ ํ์ง๋ง, ๋ช๋ช ์ธํ
๋ง ์ตํ๋ฉด ์ด๋ฐ ์ธ๋ถ ์์
๋ก๊ทธ์ธ์ด ์ฒ์ฒ ๋ถ์ด์ ์๋ํ๋ ๋ชจ์ต์ ์ ๋ง Meteor๋ผ๋ ํ๋ซํผ์ด ์ฃผ๋ ์์ฐ์ฑ์ด ๋ฌด์์ธ์ง๋ฅผ ์ ๋ณด์ฌ์ค๋ค๊ณ ์๊ฐ๋ฉ๋๋ค. ์ผ๋จ facebook๋ถํฐ ์ฐ๋์ ํด๋ณผ ํ
๋ฐ์. ๋๋จธ์ง ๊ธฐ๋ฅ๋ค์ ์ด facebook API ์ธ์ฆ๊ณผ ๊ฑฐ์ ๊ฐ์ ๊ตฌ์กฐ๋ผ๊ณ ๋ณด์๋ฉด ๋๊ฒ ์ต๋๋ค.<br>๊ทธ๋ผ ์ด์ ์์ํด ๋ณด๊ฒ ์ต๋๋ค. ^^</p>
<h4 id="8-1-facebook-API-์ธ์ฆ"><a href="#8-1-facebook-API-์ธ์ฆ" class="headerlink" title="8.1. facebook API ์ธ์ฆ"></a>8.1. facebook API ์ธ์ฆ</h4><p>์ฒ์์ผ๋ก ์ฐ๋ํด๋ณผ API๋ facebook์ด ๋๊ฒ ์ต๋๋ค. ์ฐ์ ํ์ด์ค๋ถ ๊ฐ๋ฐ์์ผํฐ(developers.facebook.com/apps) ์ ์ฑ์ ๋ฑ๋กํด ์ฃผ์
์ผ ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ฌ๊ธฐ์ ์ฌ๊ธฐ์ <code>์ฑID, ์ฑ ์ํฌ๋ฆฟ ์ฝ๋</code>๋ฅผ ์ฌ์ฉํด ์งํ๋๋ ๋ฐ๋ก ๊ธฐ๋กํด ๋์๋ฉด ์ข์ต๋๋ค.</p>
<p><img src="https://lh3.googleusercontent.com/UM9PMs8UzOhmmvIKMLRIPu5mbF6NKUcvAwCy8KiimdTTfBjs_bUVM-_6yeNYIrb6HwmYpfDdjuxjwRjQomDUO9tRjy_fAYU-CiWIYrhKLLbIGKyCFQSjBXVFw1IyUOC0M0bKTDGHNr0gxstCkV6WrYiNGPJtCbvtOTowEFQwDFXVXCQf2HugCJCxdR5YjiwKIYh0dI26lrXbjguaNy6aJ-MSBAyBHujH0C1ZX4kb3sU4M5y9jop4zkobD1ytvGxcgBItHkUsSHA3LS-MC6_ThEnE-UQh5zLPEG3-QvRaC_vimsoeYEmBDxIETfY-LxgnMRU2TF39_wBGnA_4KV3gtlNCmQlYdwxWeBL6AY1Myo1nLbHnjzdYBseXx1D7Ng_99mP1MxJWmEu4uKJ26_3eYLqr79AoHELbuqHqD8Jtfg-vvWPPSkMwFWhdhT3LQjM4N0I6xgqVeLXD1SFI9JdZRv0HMFbFXv927EieesB5lKfqh6AMVD5VV2x-i1JSUxEGNupGO6RixjxbxXCUqlbJ3814xwIIJOX8uSpzcKso2UmEfpxySs8TQyuK_lzi1SfMsH1-b-Cwgd97s4EH4Ku6kJUysrciCjTr_ZQe1eW9OhojLgNx9vtcMJ-byhEH7FN4qbjrQjpNO1Hq8IsfgrnTk3lg3-sY21RH7mHjK4Do1nM=w1177-h554-no"></p>
<p>๋ค์์ผ๋ก ๋ค์ ํจํค์ง๋ฅผ ์ค์นํด์ผ ํฉ๋๋ค. <code>service-configuration</code>๋ ์์์ ๋ง์๋๋ฆฐ ์ฑID๋ ์ํฌ๋ฆฟํค ๋ฑ์ ๋ฑ๋กํ๋ ๊ฒ์ ์กฐ๊ธ ํธํ๊ฒ ํด์ฃผ๋ config๊ฐ ๋๊ฒ ์ต๋๋ค. ๋ค์์ผ๋ก <code>accounts-facebook</code>๋ facebook api๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ํจํค์ง๊ฐ ๋๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง </p>
<ul>
<li>meteor add service-configuration</li>
<li>meteor add accounts-facebook</li>
</ul>
</blockquote>
<p>์ฒ์์ผ๋ก ํ ์ผ์ ๋ค์์ ์ฐธ๊ณ ํ์ฌ ์ฌ์ฉํ ์๋น์ค์ ํค๋ฅผ ๋ฑ๋กํ๋ ๊ฒ์
๋๋ค. <code>Meteor.startup(function() {}</code> ๋ถ๋ถ์ <code>ํ์ด์ค๋ถ ์ต์
</code>์ ์์ฑํด์ฃผ์๋ฉด ๋๊ฒ ์ต๋๋ค. ์ฌ๊ธฐ์ <code>appId</code>๋ ๊ฐ๋ฐ์ ํ์ด์ง์ <code>์ฑ ID</code>๋ฅผ <code>secret</code>์ <code>์ฑ ์ํฌ๋ฆฟ ์ฝ๋</code> ๋ฅผ ์
๋ ฅํด ์ฃผ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p><code>server/main.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">// Set up login services</div><div class="line">Meteor.startup(function() {</div><div class="line"></div><div class="line"> // ํ์ด์ค๋ถ ์ต์
</div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "facebook"</div><div class="line"> });</div><div class="line"> ServiceConfiguration.configurations.insert({</div><div class="line"> service: "facebook",</div><div class="line"> appId: '๋ฐ๊ธ๋ฐ์ ์ฑ ID',</div><div class="line"> secret: '๋ฐ๊ธ๋ฐ์ ์ฑ ์ํฌ๋ฆฟ ์ฝ๋'</div><div class="line"> });</div><div class="line"></div><div class="line"></div><div class="line"> Accounts.config({</div><div class="line"> loginExpirationInDays: 1,</div><div class="line"></div><div class="line">[์๋ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure>
<p>์ด์ ์ค์ ์ก์
์ ํตํด์ ํ์ด์ค๋ถ ๋ก๊ทธ์ธ์ด ์ผ์ด๋๋๋ก ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค. <code>login.js</code>์ ์๋ ์์ค๋ฅผ ์ฐธ๊ณ ๋ก <code>'click button[name=facebook]' (evt, tmpl){}</code> ๋ถ๋ถ์ ๋ํ ๋ถ๋ถ์ ์
๋ ฅํด ์ฃผ์ธ์. ํด๋ฆญ์ ํ๋ฉด <code>Meteor.loginWithFacebook(function(err)</code> ์ ํธ์ถํ๊ฒ ๋ฉ๋๋ค. ๊ฐ๋จํ์ฃ ^^</p>
<p><code>client/login.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.login.events({</div><div class="line"> 'click button[name=btn-singIn]' (evt, tmpl)</div><div class="line"> {</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> return false;</div><div class="line"></div><div class="line"> },</div><div class="line"> 'click button[name=facebook]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"> Meteor.loginWithFacebook(function(err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> console.log(currentUser);</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"> Bert.alert( err , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div></pre></td></tr></table></figure>
<p>๋ง์ง๋ง์ ํ์ด์ค๋ถ์์ ๊ฐ์
์ ๋ณด๋ฅผ ๋ฐ์์ ๋ฃ์ด์ฃผ๋ ๊ฒ์
๋๋ค. ์ค์ ๋ก ๊ฐ์
์์ด๋(email) ๋ฑ์ ๊ธฐ๋ณธ user ๊ฐ์ฒด์ ์ ์ฅ๋์ง๋ง ๊ทธ ์ธ์ ์ ๋ณด(์ฑ, ์ด๋ฆ, ์ฑ๋ณ ๋ฑ๋ฑ)๊ณผ ๊ฐ์ ์ ๋ณด์ ๊ฒฝ์ฐ user.profile ๊ฐ์ฒด ์๋์ ์ ๋ฆฌํด ๋๋ฉด ๋ฉ๋๋ค. ์ฐธ๊ณ ๋ก ๊ฐ ์๋น์ค ๋ณ๋ก ๋๊ฒจ์ฃผ๋ ๊ฐ์
์ ์ ๋ณด๋ ๋ค๋ฆ
๋๋ค. ๊ทธ๋์ ์ฌ์ดํธ์ ๋ง๊ฒ ์ ๋ฆฌํด ์ฃผ์
์ผ๋ง ํฉ๋๋ค. facebook์ ๊ฒฝ์ฐ <code>first_name</code>์ผ๋ก ๋์ด์ค๋ ๊ฐ์ด google์ <code>given_name</code> ์ผ๋ก ๋์ด ์ค๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ๊ฐ๊ฐ์ ์๋น์ค์์ ์ ๊ณตํ๋ API๊ฐ ์ด๋ค ํํ๋ก ๊ฐ๋ฐ์ ๋ฌธ์ ๋ฑ์ ํตํด์ ๊ผญ ํ์ธํ์๊ณ ํ์ํ ๊ฐ๋ค์ ์ ์ํด ์ฌ์ฉํ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p><code>server/accounts.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">//๊ธฐํ์๋น์ค(facebook ๋ฑ) ์ผ๋ก ๋ก๊ทธ์ธ์ profile์ ๋ณด๋ฅผ ๋ฐ๋ก ์
๋ ฅํด์ค์ผ ํจ.</div><div class="line">Accounts.onCreateUser(function (options, user) {</div><div class="line"></div><div class="line"></div><div class="line"> user.profile = options.profile;// ์ด๋ ๊ฒ ์ํด์ฃผ๋ฉด profile์ด ์๋ ์ํ๋ก ๊ฐ์
๋จ...</div><div class="line"></div><div class="line"> // facebook profile ์ค์ </div><div class="line"> if(user.services.facebook)</div><div class="line"> {</div><div class="line"> user.username = user.services.facebook.email;</div><div class="line"> user.emails = [</div><div class="line"> {</div><div class="line"> address: user.services.facebook.email,</div><div class="line"> verified: true</div><div class="line"> }</div><div class="line"> ];</div><div class="line"> user.profile.serviceType = 'facebook';</div><div class="line"> user.profile.firstName = user.services.facebook.first_name;</div><div class="line"> user.profile.lastName = user.services.facebook.last_name;</div><div class="line"> user.profile.gender = user.services.facebook.gender;</div><div class="line"> }</div><div class="line"></div><div class="line"> </div><div class="line"> [์๋ ์๋ต]</div><div class="line"> Meteor.setTimeout(function() { </div><div class="line"> .</div><div class="line"> .</div><div class="line"> .</div></pre></td></tr></table></figure>
<blockquote>
<p>์ฐธ๊ณ ๋ก ๋ก๊ทธ์ธ ์ฑ๊ณต์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณต๋๋ ๊ฐ๋ค์ ๊ฐ ๋ก๊ทธ์ธ ์ฝ๋์
์ services ์๋์์ ํ์ธ์ด ๊ฐ๋ฅํฉ๋๋ค. ์ด ๋ถ๋ถ์ ๊ฐ๊ณตํด์ profile์ ์ ํํ ํด์ ์ ์ฅํ๋ ์์
์ด ์๋ ์ฝ๋ ์
๋๋ค. </p>
</blockquote>
<p><img src="https://lh3.googleusercontent.com/Ki2vXLqBrnp1ON6KkcSMQ5FZqwBDg9k3Ugq7JAh-UH-AckKI8VV6_bty6zlTSuUGyHF7sTApS5GX3-Tt8ZAu45OmRVpsdpPAVGiWPvKXyzwIOXlbXc6MuyXxR_ngfi__ZVnU3oO9sNMiLvz0f4SYVtIjMywr9-i8EgTD23222Mr_f5dfPv9R5Vk9pnQ_QKSx7rMco0e0omdT0tVUiDlylBv0BY36oLCFmX5cejLtbY_9mUUVmlukWK7w-29hynEbp45wYJVij85bdzCchCrxExnT_zM8n-gEE6w71h4s--9x2Nh3pbnKRpmP-BECDjmYutGUcLJQUQXNC7HvF0-U8puney9W3B5UQ0se_Cyb9GMg9C_ANGhNe6lEZ9NzG5djM3XhknduhpzxsTdqSvYF6_-KqIEl_9R-RhINQXfExyYBbCrlhxSy6vMmpxvqtq3pn1oTvt28gUBBJPmqNVhK_NGDjAS9hHrkt-z2jTbDuBdA-nDpLWRUyZ4KQIOm4S-0AxvA9MQgT-9YlLS5c_ytNUv1KPilcy5O1gc5P428wGJQf536xwRw1Uq2ugbfXyYM1ppXZxnr55S7lzP0_0HgPM3I8YSDvggIW7FGv1MQ-TiwO6A8190XtCPukxC7sK540_4yWSqznNdbgMJRzeQqsUIqFidWKSwyqFsKEWqDuvY=w1154-h721-no"></p>
<p>์ด์ ํ์ด์ค๋ถ๋ฒํผ์ ํด๋ฆญํด ๋ณด๊ฒ ์ต๋๋ค. ์ ์์ ์ผ๋ก <code>Meteor.loginWithFacebook</code>๊ฐ ์๋ํ์ฌ ํ์
์ฐฝ์ด ๋จ๊ณ ์ ํํ ์ ๋ณด๋ก ๋ก๊ทธ์ธ์ ํ๋ฉด ์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ ๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. </p>
<p>์ด ๊ณผ์ ์ ์์ฝํ๋ฉด ์๋์ ๊ฐ์ต๋๋ค. </p>
<blockquote>
<p>1๋จ๊ณ. ์ฐ๋ํ ์๋น์ค์ ๊ฐ๋ฐ์ ์ผํฐ์์ ์๋น์ค ๋ฑ๋ก ํ ํค๊ฐ ๋ฐ๊ธฐ<br>2๋จ๊ณ. ServiceConfiguration.configurations์ ํค ๋ฑ๋ก<br>3๋จ๊ณ. ์์
๋ฒํผ ํด๋ฆญ์ Meteor.loginWithFacebook() ํธ์ถ<br>4๋จ๊ณ. Accounts.onCreateUser()์ user.profile ์ ์ฌ์ฉ์ ์ ๋ณด ์
๋ ฅ</p>
</blockquote>
<p>๋๋จธ์ง๋ ์์ 4๊ฐ์ง ๊ณผ์ ์ ๋๊ฐ์ด ๋ฐ๋ณตํ๋ฉด ๋ฉ๋๋ค. ๊ทธ๋ผ ๋๋จธ์ง ์๋น์ค๋ ์ฐ๋ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<hr>
<h4 id="8-2-google-API-์ธ์ฆ"><a href="#8-2-google-API-์ธ์ฆ" class="headerlink" title="8.2. google API ์ธ์ฆ"></a>8.2. google API ์ธ์ฆ</h4><p>๊ตฌ๊ธ๋ ๊ฐ๋ฐ์ ์ผํฐ(<a href="https://console.cloud.google.com/)์" target="_blank" rel="noopener">https://console.cloud.google.com/)์</a> ๊ฐ์
ํ๊ณ ํ๋ก์ ํธ๋ฅผ ๋ง๋ ๋ค์ ํค ๊ฐ์ ๋ฐ์์ค๋ฉด ๋ฉ๋๋ค. <code>ํด๋ผ์ด์ธํธ ID</code>์ <code>ํด๋ผ์ด์ธํธ ๋ณด์ ๋น๋ฐ</code>์ด ์ฌ์ฉ๋ฉ๋๋ค. google์ ๊ฒฝ์ฐ <code>google cloud platform</code> ์์ <code>API ๊ด๋ฆฌ์</code>๋ก ๋ค์ด๊ฐ ๋ฐ๊ธ์ ํ ์ ์๋๋ฐ์. ๋จผ๊ฐ ์ข ๊ฒฝ๋ก๊ฐ ๋ณต์กํ๊ธด ํ๋ ์๋ ์ด๋ฏธ์ง๋ฅผ ์ฐธ๊ณ ๋ก ์์น๋ฅผ ์ฐพ์๊ฐ์๋ฉด ๋์์ด ๋์ค ๊ฒ ๊ฐ์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/23qwTQPXXLJChBYUiSiU61d6IYCwGz7GQy44IdHkusqsg79aCgmuIC0brIZAJQq2qCdJx8Q_0pfAVrcxjDT8I--ziNFiV6neFHqyNBKJ8HGSXajDYrUdQy_tsUvOVUJ2kLmGJ39fzoBvO6iCcbC9szhhs5VI7GSvKGzk1XuOYgpEA40yI6z-IjISy8CEvpVRBFXGsZV7TNtjijzhR4wfGK_v472qQSr2SMTccoe2RHLZyJcuiqK-BhHtv_3VghRwbx604ucj4RM9Nxo2dLcG-kAwDzmUOaxi_YHRrDLhyojZxzlc7MZ9woxtfeToYYEq6cnM9o6P0HempaE4cwAkyj1DLBIda67dJnvfGgWnsrPtADdXsMano39CyrNk88ZkT4U4ul7c-A7GQL-90qv5TsfK9PkCkrVHn1oTh-CxyJ5eV_TvsqcRDXfWVnVEcPbgQDKTl2FFkxTEssSR2g32PnQqlFQ1itIfy0q5ddJ2ZymxFhYlseIqzb-sQ7fUNDedGHMQB5A62QG2cJKNWRmf7_wdcX79-IHrcVpEND9rHwmAIp3HoNoo2p3QPVXTiIHZXhbWlgcSkeAjNjKmgXcjRnCMbNgapogxhiu9Ic4C0cayze2jJonz8Gx4f2R4sAlPldqTVpMUdlwTJudXRmTtHGuDQqBOj4080ptf8Mh-vyM=w1191-h766-no"></p>
<p>๋ค์ ํจํค์ง๋ฅผ ์ค์นํด์ฃผ์ธ์.</p>
<blockquote>
<p>์ค์น ํจํค์ง<br>meteor add accounts-google</p>
</blockquote>
<p>๋ค์์ <code>main.js</code> configuration์ ๊ฐ๋ฐ์ ์ผํฐ์์ ๋ฐ์ ํค ๊ฐ์ ๋ฑ๋ก ํฉ๋๋ค. </p>
<p><code>server/main.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line">// Set up login services</div><div class="line">Meteor.startup(function() {</div><div class="line"></div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "facebook"</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ ์๋ต]</div><div class="line"></div><div class="line"> // google ์ธ์ฆ API ์ค์ </div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "google"</div><div class="line"> });</div><div class="line"> ServiceConfiguration.configurations.insert({</div><div class="line"> service: "google",</div><div class="line"> clientId: "๋ฐ๊ธ๋ฐ์ ํด๋ผ์ด์ธํธ ID",</div><div class="line"> secret: '๋ฐ๊ธ๋ฐ์ ํด๋ผ์ด์ธํธ ๋ณด์ ๋น๋ฐ',</div><div class="line"> loginStyle: "popup"</div><div class="line"> });</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"> Accounts.config({</div><div class="line"> loginExpirationInDays: 1,</div><div class="line"></div><div class="line">[์๋ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div></pre></td></tr></table></figure>
<p>๋ก๊ทธ์ธ ํ์ด์ง์์ <code>google</code>๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ก๊ทธ์ธ์ด ์งํ๋๋๋ก ์๋ ์ฝ๋๋ฅผ ์
๋ ฅํฉ๋๋ค. </p>
<p><code>clinet/login.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.login.events({</div><div class="line"> 'click button[name=btn-singIn]' (evt, tmpl)</div><div class="line"> {</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> return false;</div><div class="line"></div><div class="line"> },</div><div class="line"> 'click button[name=facebook]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> ...[์ค๋ต]</div><div class="line"> },</div><div class="line"> // google ๋ก๊ทธ์ธ ํด๋ฆญ ์ถ๊ฐ </div><div class="line"> 'click button[name=google]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"> Meteor.loginWithGoogle(function(err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"> Bert.alert( err , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div></pre></td></tr></table></figure>
<p>google๋ก ๋ถํฐ ๋ฐ์์จ ๊ฐ์ profile์ ๋ฑ๋กํ๋ ์ค์ ์ ํด์ค๋๋ค. </p>
<p><code>server/accounts.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">//๊ธฐํ์๋น์ค(facebook) ์ผ๋ก ๋ก๊ธด์ profile์ ๋ณด๋ฅผ ๋ฐ๋ก ์
๋ ฅํด์ค์ผ ํ๋ค.</div><div class="line">Accounts.onCreateUser(function (options, user) {</div><div class="line"></div><div class="line"></div><div class="line"> user.profile = options.profile;// ์ด๋ ๊ฒ ์ํด์ฃผ๋ฉด profile์ด ์๋ ์ํ๋ก ๊ฐ์
๋จ...</div><div class="line"></div><div class="line"> // facebook profile ์ค์ </div><div class="line"> if(user.services.facebook)</div><div class="line"> {</div><div class="line"> ...[์ค๋ต]</div><div class="line"> }</div><div class="line"></div><div class="line"> // google profile ์ค์ </div><div class="line"> if(user.services.google)</div><div class="line"> {</div><div class="line"> user.emails = [</div><div class="line"> {</div><div class="line"> address: user.services.google.email,</div><div class="line"> verified: true</div><div class="line"> }</div><div class="line"> ];</div><div class="line"> user.profile.serviceType = 'google';</div><div class="line"> user.username = user.services.google.name;</div><div class="line"> user.profile.firstName = user.services.google.given_name;</div><div class="line"> user.profile.lastName = user.services.google.family_name;</div><div class="line"> user.profile.gender = user.services.google.gender;</div><div class="line"> }</div><div class="line"></div><div class="line"> </div><div class="line"> [์๋ ์๋ต]</div><div class="line"> Meteor.setTimeout(function() { </div><div class="line"> .</div><div class="line"> .</div><div class="line"> .</div></pre></td></tr></table></figure>
<p>์์ด์ google๋ก๋ ๋ก๊ทธ์ธ ํด๋ณด์ธ์. ๋ฌธ์ ๊ฐ ์๋ค๋ฉด ์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ ๋ก๊ทธ์ธ ๋๋ ๊ฒ์ ๋ณผ ์ ์์ ๊ฒ์
๋๋ค. </p>
<hr>
<h4 id="8-3-twitter-API-์ธ์ฆ"><a href="#8-3-twitter-API-์ธ์ฆ" class="headerlink" title="8.3. twitter API ์ธ์ฆ"></a>8.3. twitter API ์ธ์ฆ</h4><p>๋ค์์ twitter ์
๋๋ค. ๊ณผ์ ์ ์ญ์ ๋น์ทํฉ๋๋ค. </p>
<p>์ฒ์์ผ๋ก ํ ์ผ์ ๊ฐ๋ฐ์ ์ฌ์ดํธ์์ ํค ๊ฐ์ ๋ฐ๋๊ฒ ์
๋๋ค. ํธ์ํฐ์์ ์ฌ์ฉํ๋ ๊ฐ๋ค์ <code>Consumer Key(API Key)</code>์ <code>Consumer Secret(API Secret)</code>๊ฐ ๋๊ฒ ์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/6XwhCbtcCFEA3Uy0eYJBD9wt7cdxpnEmZSDZ4fGrrJa1mhD9SDGpNk1Hkxjxh1Qo0N0-3_EdR5g39Ib4fIwJCwEWIr_cpHOidoKYayXiC_5Mv-xBy_sqMSinmoQcHs2VNOHlYUytuDbO_naeMnKBFPLGyXBLAmGRD-2lRQhbmw4TiQ_ukBf3MXOERLVYj0KQ6ohDEwQ5_OCJ3DYOWKxbJ-5zILkeAy4FMdixm7ZStAqdg8Q6IODFznd_UJx2QnyLxp408P6KOdzLB4P3wcdVWNsqXW__A8yRu7kdLzQXupiIwDsisk_YbcXv4CpbGWjeYiW093-olxptPDX8TvxU0vY9Orm-reRaLZgeCHqAISI7txNoYqg4v-7FuwQS_20PqrCtu0CLs-wj_t4qchBSL8gDDUr9ANHDqFJGgu6dfiy3j12KlARwYHl0_4e4qCENbjZmlY5tNzwEf-vpZaiSljaN9wGD7ZYz-Gu_qCKIoVhPuB09hpwFbfxtsTdkxdZliOOQDLZulRn3LPyjW6Qh6AhWo28q7AGZC6XNwQCs-sDJVUIeeLDRJzSvcmTIs2jkTy9OfA_fPnwaqZa2pmMxnlsf90CQ-lsAdaS1K1byHeRXjkOAi9kVzxy6T3XoO5N3JOdp9lcopdUYvpECu2wp-Immz6dnNM1sxbVFORWPSqk=w621-h677-no"></p>
<p>๋ค์ ํจํค์ง๋ฅผ ์ค์นํด์ฃผ์ธ์.</p>
<blockquote>
<p>์ค์น ํจํค์ง<br>meteor add accounts-twitter</p>
</blockquote>
<p>๋ค์์ <code>main.js</code> configuration์ ๊ฐ๋ฐ์ ์ผํฐ์์ ๋ฐ์ ํค ๊ฐ์ ๋ฑ๋ก ํฉ๋๋ค. </p>
<p><code>server/main.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">// Set up login services</div><div class="line">Meteor.startup(function() {</div><div class="line"></div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "facebook"</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ ์๋ต]</div><div class="line"></div><div class="line"> // twitter ์ธ์ฆ API ์ค์ </div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "twitter"</div><div class="line"> });</div><div class="line"> ServiceConfiguration.configurations.insert({</div><div class="line"> service: "twitter",</div><div class="line"> consumerKey: "๋ฐ๊ธ๋ฐ์ consumer Key,</div><div class="line"> loginStyle: "popup",</div><div class="line"> secret: "๋ฐ๊ธ๋ฐ์ consumer secret"</div><div class="line"> });</div><div class="line"></div><div class="line"></div><div class="line">[์๋ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> Accounts.config({</div><div class="line"> loginExpirationInDays: 1,</div></pre></td></tr></table></figure>
<p>๋ก๊ทธ์ธ ํ์ด์ง์์ <code>twitter</code>๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ก๊ทธ์ธ์ด ์งํ๋๋๋ก ์๋ ์ฝ๋๋ฅผ ์
๋ ฅํฉ๋๋ค. </p>
<p><code>clinet/login.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.login.events({</div><div class="line"> 'click button[name=btn-singIn]' (evt, tmpl)</div><div class="line"> {</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> return false;</div><div class="line"></div><div class="line"> },</div><div class="line"> 'click button[name=facebook]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> ...[์ค๋ต]</div><div class="line"> },</div><div class="line"> // twitter ๋ก๊ทธ์ธ ํด๋ฆญ ์ถ๊ฐ </div><div class="line"> 'click button[name=twitter]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"> Meteor.loginWithTwitter(function(err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"> Bert.alert( err , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div></pre></td></tr></table></figure>
<p>twitter ๋ถํฐ ๋ฐ์์จ ๊ฐ์ profile์ ๋ฑ๋กํ๋ ์ค์ ์ ํด์ค๋๋ค. </p>
<p><code>server/accounts.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">//๊ธฐํ์๋น์ค(facebook) ์ผ๋ก ๋ก๊ธด์ profile์ ๋ณด๋ฅผ ๋ฐ๋ก ์
๋ ฅํด์ค์ผ ํ๋ค.</div><div class="line">Accounts.onCreateUser(function (options, user) {</div><div class="line"></div><div class="line"></div><div class="line"> user.profile = options.profile;// ์ด๋ ๊ฒ ์ํด์ฃผ๋ฉด profile์ด ์๋ ์ํ๋ก ๊ฐ์
๋จ...</div><div class="line"></div><div class="line"> // facebook profile ์ค์ </div><div class="line"> if(user.services.facebook)</div><div class="line"> {</div><div class="line"> ...[์ค๋ต]</div><div class="line"> }</div><div class="line"></div><div class="line"> // google profile ์ค์ </div><div class="line"> // twitter profile ์ค์ </div><div class="line"> if(user.services.twitter)</div><div class="line"> {</div><div class="line"> user.emails = [</div><div class="line"> {</div><div class="line"> address: 'none',</div><div class="line"> verified: true</div><div class="line"> }</div><div class="line"> ];</div><div class="line"> user.profile.serviceType = 'twitter';</div><div class="line"> user.username = user.services.twitter.screenName;</div><div class="line"> user.profile.firstName = user.services.twitter.screenName;</div><div class="line"> user.profile.lastName = 'none';</div><div class="line"> user.profile.gender = '';</div><div class="line"> }</div><div class="line"></div><div class="line"></div><div class="line"> [์๋ ์๋ต]</div><div class="line"> Meteor.setTimeout(function() { </div><div class="line"> .</div><div class="line"> .</div><div class="line"> .</div></pre></td></tr></table></figure>
<p>์์ด์ twitter๋ก๋ ๋ก๊ทธ์ธ ํด๋ณด์ธ์. ๋ฌธ์ ๊ฐ ์๋ค๋ฉด ์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ ๋ก๊ทธ์ธ ๋๋ ๊ฒ์ ๋ณผ ์ ์์ ๊ฒ์
๋๋ค. </p>
<hr>
<h4 id="8-4-kakao-API-์ธ์ฆ"><a href="#8-4-kakao-API-์ธ์ฆ" class="headerlink" title="8.4. kakao API ์ธ์ฆ"></a>8.4. kakao API ์ธ์ฆ</h4><p>์ด์ ๋ง์ง๋ง์ผ๋ก kakao API์ฐ๋์ ํด๋ณด๊ฒ ์ต๋๋ค. ํ๊ตญ์์ ๋ง์ด ์ฌ์ฉํ๋ kakao์ ๊ฒฝ์ฐ ํ๊ตญ ๊ฐ๋ฐ์ ๋ถ์ด ํจํค์ง๋ฅผ ๋ง๋ค์ด ๋ ์ํ์
๋๋ค. ๋๋ถ์ kakao๋ ์ฝ๊ฒ ์ฐ๋ํ ์ ์์ต๋๋ค. ^^</p>
<p>์ฒ์์ผ๋ก ํ ์ผ์ ๊ฐ๋ฐ์ ์ฌ์ดํธ์์ ํค ๊ฐ์ ๋ฐ๋๊ฒ ์
๋๋ค. kakao์์ ์ฌ์ฉํ๋ ๊ฐ๋ค์ <code>REST APIํค</code>๊ฐ ๋๊ฒ ์ต๋๋ค. ํ๊ฐ์ง ์์ฌ์ด ์ ์ ํ์ฌ ํจํค์ง์ ๊ฒฝ์ฐ Client Secret์ค์ ์ ํ์ฑํ ํ๋ฉด ์๋์ ์ํ๋ค๋ ์ ์
๋๋ค. ๊ทธ๋์ ๋ค๋ฅธ ์๋น์ค์ ๋ค๋ฅด๊ฒ secret์ ์์ง๊น์ง ์ฌ์ฉํ ์ ์์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/z-kvzGozLx5iekATs1eIHFocQAftXp4rIOelJGQqQSUlw_iz3w_wGq9Gdvfyb6koGIqvgO707d-akKyCZOc39-thoK-LPXmZPVDHy47w1oowsyEiv1N62C9aDWeHVaswmjXTz1jueNRebVgmsry0Dg_yPSZZw5Lk0JGjCMA6NHDiuSXi2NP5aFf57tm35zbjm_twhGA41k6wN0Ow68xaDoA6Vi7TnNp_ilpXatP2tcqqMB13k1nRBQT4HUk5MwJVPgRH4BNExejE9tx727G_j9YUX41jDnEIJmUjawJK7jTf7gkuF571ZlXYd8L53boLWr0gcSt6-9ivFPjwnEBgu81ViAbC0Ocprud63tGIe804VPFMO136_pjR5A3NEQL-9RVXIuYVl24x8V-jD4dgGYUCm0WoQ6tg44Ei-UJzfu7JmsxG0156mgtBMp0UhTrgkKr2TdLebUEboZWYivHiWJ82pi0f_2ob2nubDloyp2SvXAFPEBiIvBIG2QXt6xIKJ0JX32H2sIv-W5GuzX8FZY1bWUK42jaCQ34EG5z9yndxbP9a0dlY8CYWnNTr_VkbNQBTuv9e1jcS8q3DaEGoGBXnCkw3X5fPwKFHsCsg8SS6QZBJMDnp5Cj6Mwe5MaUAKBfwle0yszt9MeH7rEWJV8zCX-P5IQv1PurNkqV3WgM=w873-h721-no"></p>
<p>๋ค์ ํจํค์ง๋ฅผ ์ค์นํด์ฃผ์ธ์.</p>
<blockquote>
<p>์ค์น ํจํค์ง<br>meteor add spectrum:accounts-kakao</p>
</blockquote>
<p>๋ค์์ <code>main.js</code> configuration์ ๊ฐ๋ฐ์ ์ผํฐ์์ ๋ฐ์ ํค ๊ฐ์ ๋ฑ๋ก ํฉ๋๋ค. </p>
<p><code>server/main.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">// Set up login services</div><div class="line">Meteor.startup(function() {</div><div class="line"></div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "facebook"</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ ์๋ต]</div><div class="line"></div><div class="line"> // kakao ์ธ์ฆ API ์ค์ </div><div class="line"> ServiceConfiguration.configurations.remove({</div><div class="line"> service: "kakao"</div><div class="line"> });</div><div class="line"> ServiceConfiguration.configurations.insert({</div><div class="line"> service: "kakao",</div><div class="line"> clientId: "๋ฐ๊ธ๋ฐ์ REST API ํค",</div><div class="line"> loginStyle: "popup"</div><div class="line"> });</div><div class="line"></div><div class="line"></div><div class="line">[์๋ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> Accounts.config({</div><div class="line"> loginExpirationInDays: 1,</div></pre></td></tr></table></figure>
<p>๋ก๊ทธ์ธ ํ์ด์ง์์ <code>kakao</code>๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ก๊ทธ์ธ์ด ์งํ๋๋๋ก ์๋ ์ฝ๋๋ฅผ ์
๋ ฅํฉ๋๋ค. </p>
<p><code>clinet/login.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.login.events({</div><div class="line"> 'click button[name=btn-singIn]' (evt, tmpl)</div><div class="line"> {</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> return false;</div><div class="line"></div><div class="line"> },</div><div class="line"> 'click button[name=facebook]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> ...[์ค๋ต]</div><div class="line"> },</div><div class="line"> // kakao ๋ก๊ทธ์ธ ํด๋ฆญ ์ถ๊ฐ </div><div class="line"> 'click button[name=kakao]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"> Meteor.loginWithKakao(function(err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"> Bert.alert( err , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div></pre></td></tr></table></figure>
<p>kakao๋ก๋ถํฐ ๋ฐ์์จ ๊ฐ์ profile์ ๋ฑ๋กํ๋ ์ค์ ์ ํด์ค๋๋ค. </p>
<p><code>server/accounts.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">//๊ธฐํ์๋น์ค(facebook) ์ผ๋ก ๋ก๊ธด์ profile์ ๋ณด๋ฅผ ๋ฐ๋ก ์
๋ ฅํด์ค์ผ ํ๋ค.</div><div class="line">Accounts.onCreateUser(function (options, user) {</div><div class="line"></div><div class="line"></div><div class="line"> user.profile = options.profile;// ์ด๋ ๊ฒ ์ํด์ฃผ๋ฉด profile์ด ์๋ ์ํ๋ก ๊ฐ์
๋จ...</div><div class="line"></div><div class="line"> // facebook profile ์ค์ </div><div class="line"> if(user.services.facebook)</div><div class="line"> {</div><div class="line"> ...[์ค๋ต]</div><div class="line"> }</div><div class="line"></div><div class="line"> // kakap profile ์ค์ </div><div class="line"> if(user.services.kakao)</div><div class="line"> {</div><div class="line"> user.emails = [</div><div class="line"> {</div><div class="line"> address: 'none',</div><div class="line"> verified: true</div><div class="line"> }</div><div class="line"> ];</div><div class="line"> user.profile.serviceType = 'kakao';</div><div class="line"> user.username = user.profile.name;</div><div class="line"> user.profile.gender = '';</div><div class="line"> }</div><div class="line"></div><div class="line"></div><div class="line"> [์๋ ์๋ต]</div><div class="line"> Meteor.setTimeout(function() { </div><div class="line"> .</div><div class="line"> .</div><div class="line"> .</div></pre></td></tr></table></figure>
<p>์ด์ kakao๋ก๋ ๋ก๊ทธ์ธ ํด๋ณด์ธ์. ๋ฌธ์ ๊ฐ ์๋ค๋ฉด ์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ ๋ก๊ทธ์ธ ๋๋ ๊ฒ์ ๋ณผ ์ ์์ ๊ฒ์
๋๋ค. kakao์ ๊ฒฝ์ฐ api๋ก ๋ฐ์ ์ ์๋ ๋ถ๋ถ์ด ๋งค์ฐ ์ ํ์ ์ธ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ์ด๋ถ๋ถ์ ๊ฐ๋ฐ์ ํ์ด์ง์์ ๋ฐ๋ก ์ฌ์ฉ์๊ฐ ์ ์ ํ์ฌ ํญ๋ชฉ์ ๋๋ฆด ์ ์์ผ๋ ์ด๋ถ๋ถ์ kakao ๊ฐ๋ฐ์ ํ์ด์ง๋ฅผ ์ฐธ๊ณ ํ์ฌ ๊ฐ๋ฐํ์๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค. </p>
<hr>
<h3 id="9-๊ธฐํ-์ฌํญ"><a href="#9-๊ธฐํ-์ฌํญ" class="headerlink" title="9. ๊ธฐํ ์ฌํญ"></a>9. ๊ธฐํ ์ฌํญ</h3><p>์ฌ์ค Meteor๋ฅผ ์ด์ฉํด ๊ฐ๋ฐ์ ํ ๊ฒฝ์ฐ ๊ฐ์ข์์์ ๊ฐ์ด ๋ฒํผ ํ๋ํ๋๋ฅผ ๋ง๋ค์ด ์ฌ์ฉํ์ง ์์๋ ๋ฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๋ account๋ฅผ ์ด์ฉํ๋ฉด ๋ค์ ํจํค์ง๋ฅผ ์ถ๊ฐ ํ๋ ๊ฒ์ผ๋ก ํ์๊ฐ์
๋ก๊ทธ์ธ ๋ฑ์ ๋ง์ ๊ธฐ๋ฅ์ ๋ฐ๋ก ์ฌ์ฉํ ์๋ ์์ต๋๋ค. ํจํค์ง ์ถ๊ฐ ํ ํ
ํ๋ฆฟ์ ์๋์ ๊ฐ์ด <code>loginButtons</code> ๋ง ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">{{> loginButtons}}</div></pre></td></tr></table></figure>
<blockquote>
<p>์ค์น ํจํค์ง</p>
<ul>
<li>meteor add accounts-ui</li>
</ul>
</blockquote>
<p>์ด๋ถ๋ถ์ ๋ํ ๋ฌธ์๋ ์๋ ๋งํฌ ํ์ด์ง์ ๋์์์ผ๋ ์ฐธ๊ณ ํ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p><a href="https://guide.meteor.com/accounts.html" target="_blank" rel="noopener">https://guide.meteor.com/accounts.html</a></p>
<hr>
<p>์ด์์ผ๋ก Meteor custom account ๊ด๋ จ ๊ฐ์ข๋ฅผ ๋ง์น๊ฒ ์ต๋๋ค. Meteor ์ด๋ณด ๊ฐ๋ฐ์ ๋ถ๋ค์๊ฒ ์กฐ๊ธ์ด๋๋ง ๋์์ด ๋์์ผ๋ฉด ์ข๊ฒ ๋ค์. ๊ฐ์ธ์ ์ผ๋ก ๋๋ meteor์ ๊ฐ์ฅ ํฐ ๋งค๋ ฅ์ ์๋ง๋ ์์ฐ์ฑ์ด ์๋๊น ์๊ฐํฉ๋๋ค. ์ด๋ฏธ ๋ค์ํ ํจํค์ง(๊ฐ์ข์์๋ facebook, google ๋ฑ ๋ค์ํ ์๋น์ค์ ์ธ์ฆ ์ฐ๋)๋ฅผ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๊ณ , ๋ฐฑ์ค๋์ ํ๋ก ํธ์ค๋๋ฅผ ๋์์ ๊ฐ๋ฐ ํ ์ ์์ผ๋ฉฐ, ์ฌ์ง์ด ํ๋ก ํธ์๋์ ๋น๋๋จธ์ ? ์ผ๋ก ์ฌ์ฉํ์๋ ๋ถ๋ค๋ ์๋ ๊ฒ์ผ๋ก ์๊ณ ์์ต๋๋ค. ํ์ง๋ง ์์ง ๊ตญ๋ด์๋ meteor๋ฅผ ์ฌ์ฉํ๋ ์ฌ๋์ด ๊ทธ๋ฆฌ ๋ง์ง ์์ ์ฐธ ๋ง์ด ์์ฝ๋ค๋ ์๊ฐ์ด ๋ญ๋๋ค. ์ฌํผ ์ ๋ถ์กฑํ ๊ฐ์ข๊ฐ ์กฐ๊ธ์ด๋๋ง meteor์ ๋ํ ํธ๊ธฐ์ฌ์ ์๊ทนํ๋ค๋ฉด ๊ฐ์ธ์ ์ผ๋ก ๋ง์กฑํ ๊ฒ ๊ฐ์ต๋๋ค. ์กฐ๋ง๊ฐ ๋ค๋ฅธ ๊ฐ์ข๋ฅผ ํตํด์ ๋ ๋ต๊ฒ ์ต๋๋ค. ^^ </p>
<blockquote>
<p>์์ค์ฝ๋ ๋งํฌ<br><a href="https://github.com/freeseamew/meteorAccount-study" target="_blank" rel="noopener">https://github.com/freeseamew/meteorAccount-study</a></p>
</blockquote>
]]></content>
<summary type="html">
<h3 id="8-๋ค๋ฅธ-์๋น์ค-api๋ฅผ-ํตํ-๋ก๊ทธ์ธ-facebook-google-twitter-kakao"><a href="#8-๋ค๋ฅธ-์๋น์ค-api๋ฅผ-ํตํ-๋ก๊ทธ์ธ-facebook-google-twitter-kakao" class="headerlink"
</summary>
<category term="meteor, custom account, ๋ฏธํฐ์ด" scheme="http://freeseamew.github.io/tags/meteor-custom-account-%EB%AF%B8%ED%8B%B0%EC%96%B4/"/>
</entry>
<entry>
<title>Meteor custom account ๊ฐ์ข 4</title>
<link href="http://freeseamew.github.io/2017/07/04/meteor-account-tutorial-4/"/>
<id>http://freeseamew.github.io/2017/07/04/meteor-account-tutorial-4/</id>
<published>2017-07-03T15:44:53.000Z</published>
<updated>2017-07-04T02:49:28.000Z</updated>
<content type="html"><![CDATA[<h3 id="7-ํ๋ฉด์ ํ-ํจ๊ณผ"><a href="#7-ํ๋ฉด์ ํ-ํจ๊ณผ" class="headerlink" title="7. ํ๋ฉด์ ํ ํจ๊ณผ"></a>7. ํ๋ฉด์ ํ ํจ๊ณผ</h3><p>Meteor ์ธ์ฆ(account) ๊ด๋ จ ๊ฐ์ข๋ฅผ ๋ ์งํํ๊ธฐ ์ ์ ํ์ฌ๋ง๋ค์ด์ง ๊ธฐ๋ฅ์ ์กฐ๊ธ ๋ณด์ํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.<br>router๋ก ์ํ๋ ํ์ด์ง๋ก ์ด๋์ด ๋๊ณ ์์ง๋ง, ์ข ๋ ์์ด๋ณด์ด๊ฒ(?) ํ๋ฉด์ ํ ํจ๊ณผ๋ฅผ ๋ฃ์ด๋ณด๊ฒ ๊ณ , ๋ ๋ฉ์ผ๋ฐ์ก ๋ ํ๋ฉด์ด ์ ์งํ๊ฒ ์ฒ๋ผ ๋ช์ด๊ฐ ์๋ฌด๋ฐ ์ก์
์ด ์๋ ๋ถ๋ถ์ ๋ก๋ฉํจ๊ณผ๋ฅผ ๋ฃ์ด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฌ์ค ์ด๋ฐ ๋ถ๋ถ๋ค์ ๊ผญ ์์ด์ผ ํ๋ ๋ถ๋ถ์ ์๋์ง๋ง, ๋จผ๊ฐ ์ฑ์ ์์ฑ๋๋ฅผ ๋์ด๊ธฐ์ํด์๋ ์ ์ฉํด๋๋ ๊ฒ์ด ์ข์ ๊ฒ๋ ์ฌ์ค์ผ ๊ฒ์
๋๋ค.<br>๊ฐ์ข ์ค๊ฐ์ ์ด๋ฐ ํจ๊ณผ์ ์ธ ๋ถ๋ถ์ ๋ฃ๋ ์ด์ ๋ ์์ผ๋ก ๋จ์ ๋ถ๋ถ์๋ ์์ ํจ๊ณผ ๊ด๋ จ ๊ธฐ๋ฅ์ ๊ณ์ํด์ ๋ค์ด๊ฐ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ฌ๊ธฐ์ ๋ฏธ๋ฆฌ ์์ฑํ๋ ๊ฒ์ด ์์ค ์ฝ๋๋ฅผ 2๋ฒ ๊ณ ์น์ง ์๊ฒ ๋ ๊ฒ ๊ฐ์์ ์
๋๋ค. </p>
<hr>
<h4 id="7-1-์ ๋๋ฉ์ด์
-ํจ๊ณผ"><a href="#7-1-์ ๋๋ฉ์ด์
-ํจ๊ณผ" class="headerlink" title="7.1 ์ ๋๋ฉ์ด์
ํจ๊ณผ"></a>7.1 ์ ๋๋ฉ์ด์
ํจ๊ณผ</h4><p>์ผ๋จ ๋ค์ ํจํค์ง๋ฅผ ์ค์นํด์ฃผ์ธ์. ์ด ํจํค์ง๋ Meteor์์ ๋ค์ํ ์ ๋๋ฉ์ด์
ํจ๊ณผ๋ฅผ ๋ผ ์ ์๋๋ก ํด์ฃผ๋ ํจํค์ง ์
๋๋ค.</p>
<blockquote>
<p>์ค์นํจํค์ง</p>
<ul>
<li>meteor add webtempest:animate</li>
</ul>
</blockquote>
<p>์ฌ์ค ์ด ํจํค์ง์์ ์ฌ์ฉ๋ ์ฝ๋๋ ์๋์ ์ ๋๋ฉ์ด์
ํ๋ ์์ํฌ๋ฅผ Meteor์์ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋๋ก ๋ง๋ ํจํค์ง๊ฐ ๋๊ฒ ์ต๋๋ค. ์๋ ๋งํฌํ์ด์ง๋ก ๊ฐ์๋ฉด ์ฌ์ฉํ ์ ์๋ ํจ๊ณผ๋ค์ ๋ณผ ์ ์์ต๋๋ค. </p>
<ul>
<li><a href="https://daneden.github.io/animate.css/" target="_blank" rel="noopener">https://daneden.github.io/animate.css/</a></li>
</ul>
<p>์ฌ์ฉ๋ฒ์ ์๋์ ๊ฐ์ต๋๋ค. ํจ๊ณผ๋ฅผ ๋ํ๋ด๊ณ ์ ํ ์์๋ฅผ <code>#transition</code> ๋ก ๊ฐ์ธ์ฃผ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. ์ฐธ ์ฝ์ฃ ? ^^</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">{{#transition in="๋ํ๋ ๋ํจ๊ณผ:ํจ๊ณผ์๊ฐ" out="์ฌ๋ผ์ง๋ํจ๊ณผ:ํจ๊ณผ์๊ฐ"}}</div><div class="line"> {{> yield}}</div><div class="line">{{/transition}}</div></pre></td></tr></table></figure>
<p>๊ทธ๋ฆฌ๊ณ ์ง๊ธ ๋ง๋ค๊ณ ์๋ account์์ ์ ๊ฒฝ์ฐ ์ฌ์ค ํ์ด์ง๊ฐ ๋ช๊ฐ ๋์ง ์์ง๋ง, ์ง๊ธ๋ณด๋ค ํจ์ฌ ๋ง์ ํ์ด์ง๋ก ์ด๋ฃจ์ด์ง ์๋น์ค์ ๊ฒฝ์ฐ ๊ฐ ํ์ด์ง๋ง๋ค ํจ๊ณผ๋ฅผ ์ค๋ค๋ฉด ์ฝ๊ฐ ๊ท์ฐฎ์ ๊ฒ์
๋๋ค. ๊ทธ๋์ ์ฐ๋ฆฌ์ ํ๋ฉด์ ํ ํจ๊ณผ๋ <code>mainLayout</code> ํ
ํ๋ฆฟ๋ง์๋ง ์ค ๊ฒ์
๋๋ค. ์ด๊ณณ์๋ง ์ฃผ๋ฉด, ํน๋ณํ ์ํฉ์ด ์๋์ด์, ๋ชจ๋ ํ์ด์ง๊ฐ ๋ํ๋ ๋ ํจ๊ณผ๊ฐ ์ ์ฉ๋๋ ๊ฒ์ ๋ณผ ์ ์์ ๊ฒ์
๋๋ค. <code>main-layout.html</code> ํ์ด์ง๋ฅผ ์๋์ ๊ฐ์ด ๋ณ๊ฒฝํด์ฃผ์ธ์.</p>
<p><code>client/main-layout.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><template name="mainLayout"></div><div class="line"> <div class="container"></div><div class="line"> {{#transition in="fadeIn:500" out="fadeOut:500"}}</div><div class="line"> {{> Template.dynamic template=content }}</div><div class="line"> {{/transition}}</div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>์ด์ ์คํ์ ์์ผ๋ณด๋ฉด ํ๋ฉด์ด ๋ถ๋๋ฝ๊ฒ ์ ํ๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. </p>
<h4 id="7-2-๋ก๋ฉ-ํจ๊ณผ"><a href="#7-2-๋ก๋ฉ-ํจ๊ณผ" class="headerlink" title="7.2 ๋ก๋ฉ ํจ๊ณผ"></a>7.2 ๋ก๋ฉ ํจ๊ณผ</h4><p>๋ค์์ ๋ก๋ฉํจ๊ณผ์ ๋ํด์ ์ค๋ช
๋๋ฆด ํ
๋ฐ์. ํ์ฌ ์ฐ๋ฆฌ๊ฐ ๋ง๋ค๊ณ ์๋ ํ์ด์ง์์ ๋ก๋ฉ ํจ๊ณผ๊ฐ ์ค์ ๋ก ํ์ํ ๋ถ๋ถ์ ๊ฐ์
๋ฉ์ผ ๋ณด๋ด๊ธฐ ๋ถ๋ถ ์ ๋๊ฐ ๋ ๊ฒ์
๋๋ค. ์ด์ค์์๋ ๊ฐ์
๋ฉ์ผ ๋ค์๋ณด๋ด๊ธฐ ๋ถ๋ถ์ ๊ฒฝ์ฐ๊ฐ 2~3์ด ์ ๋์ ๋๋ ์ด๊ฐ ์๊ธธ ์ ์์ด ์ด๋ ๋ก๋ฉํจ๊ณผ๋ฅผ ์ฃผ๋ ๊ฒ์ผ๋ก ํ์ด์ง๋ฅผ ์ข ๋ ์์ฑ๋ ์๊ฒ ๋ณด์ผ ์ ์์ ๊ฒ์ผ๋ก ์๊ฐ๋ฉ๋๋ค. </p>
<p>๋ก๋ฉํจ๊ณผ์ ์ฌ์ฉ๋ Meteor์ api๋ <code>reactive-var</code> ๋ผ๋ ๊ฒ์
๋๋ค. ์ด๋
์์ ๋ํด์๋ง์ผ๋ก ํ์ฑํฐ ์ ๋ ๊ฐ์ข๊ฐ ํ์ํ๊ฒ ์ง๋ง ์ผ๋จ์ ๊ฐ๋จํ๊ฒ๋ง ์ค๋ช
๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p><code>reactive-var</code>๋ ์ผ์ข
์ ์ผ์ ํจ์? ๋ผ๊ณ ๋ณด๋ฉด ๋ ๊ฒ ๊ฐ์๋ฐ์. ๋ค์๋ง์ ์ด๋ค ๊ฐ์ ๋ณํ๋ฅผ ๊ฐ์งํ๋ ์ญํ ์ ํ๋ API๋ผ๊ณ ๋ณด์๋ฉด ๋๊ฒ ์ต๋๋ค. <code>reactive-var</code>์ ํน์ ์ํ๋ฅผ ์ ์ํด ๋๊ณ , ์ด ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ <code>reactive-var</code>๊ฐ ์๋ํ๊ฒ ๋๋๋ฐ์. ์ค์ ํ์ฌ๊ฐ์ง ์ผ์์์ ์ด์ด ๊ฐ์ง๋๋ฉด ์ผ์๊ฐ ์คํ๋ง ์ฟจ๋ฌ๋ฅผ ์๋์์ผ ์ฃผ๋ ๋จธ ๊ทธ๋ฐ ๊ธฐ๋ฅ์ ํ๋ฏ(๋ค๋ฅธ ๋ถ๊ป์ ์ด๋ ๊ฒ ์ค๋ช
ํ์ ๊ฒ์ ๊ธฐ์ตํฉ๋๋ค.) <code>reactive-var</code>๋ ๊ฑฐ์ ๋น์ทํ ์ญํ ์ ํ๋ค๊ณ ์ดํดํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค. </p>
</blockquote>
<p><code>public/images/</code> ํด๋๋ฅผ ๋ง๋ค๊ณ , ๋ก๋ฉ์ด๋ฏธ์ง๋ฅผ git ํ์ด์ง์์ ๋ค์ด๋ฐ์ ๋ณต์ฌํด์ฃผ์ธ์.</p>
<p>๊ทธ๋ฆฌ๊ณ main-layout.js์ ๋ค์๊ณผ ๊ฐ์ด <code>mainLoading</code> ํ
ํ๋ฆฟ์ ์
๋ ฅํด์ฃผ์ธ์. ๋ mainLayout ํ
ํ๋ฆฟ๋ ์๋ ์์ค๋ฅผ ์ฐธ๊ณ ๋ก <code>#if showLoadingEffectLoad</code> ๋ผ๋ ์กฐ๊ฑด๋ฌธ์ ํ๋ ์ถ๊ฐํ๊ฒ ์ต๋๋ค. </p>
<p><code>client/main-layout.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><template name="mainLayout"> </div><div class="line"> {{#if showLoadingEffectLoad}} <!-- ์ถ๊ฐ๋ ์กฐ๊ฑด๋ฌธ --></div><div class="line"> {{#transition in="fadeIn:500" out="fadeOut:500"}}</div><div class="line"> {{> mainLoading}}</div><div class="line"> {{/transition}}</div><div class="line"> {{/if}}</div><div class="line"> <div class="container"></div><div class="line"> {{#transition in="fadeIn:500" out="fadeOut:500"}}</div><div class="line"> {{> Template.dynamic template=content }}</div><div class="line"> {{/transition}}</div><div class="line"> </div></div><div class="line"></template></div><div class="line"></div><div class="line"><template name="mainLoading"> <!-- ์ถ๊ฐ๋ ํ
ํ๋ฆฟ --></div><div class="line"> <div class="table y100 text_center bg-main"></div><div class="line"> <div class="table-cell py4"></div><div class="line"> <img src="images/loading-spinning-bubbles.svg" width="64" height="64" /></div><div class="line"> <h1 class="h1 mt2 mb0">Now loading...</h1></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>์ด์ ์ด <code>mainLoading</code> ํ
ํ๋ฆฟ์ด ์ ์๋ํ๋๋ก ๋ง๋ค์ด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.<br>์ฐ์ ์ <code>showLoadingEffect</code> ์ด๋ผ๋ ๊ฐ์ ์ ์๋ฅผ ํด์ผ ํ๋๋ฐ, ์ด๊ฒ์ mainLayout ํ
ํ๋ฆฟ์ด ์์ฑ๋ ๋ ํ๋๋ก ํด์ฃผ๋ฉด ๋๊ฒ ์ต๋๋ค. ์ฐธ๊ณ ๋ก ์ด ๊ฐ์ฒด๋ฅผ <code>window.showLoadingEffect</code>๊ฒ ๋ง๋ค์ด ์ฌ์ฉํ๋ ์ด์ ๋ ์ ์ญ์ผ๋ก ํด์ผ๋ง ๋ค๋ฅธ ํ
ํ๋ฆฟ์์๋ ์ด ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค. ๊ธฐ๋ณธ๊ฐ์ false๋ก ์ ์ ํ๊ฒ ์ต๋๋ค.<br>๊ทธ๋ฆฌ๊ณ ์ด ๊ฐ์ฒด๋ฅผ ํ
ํ๋ฆฟ ์ฆ html์์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ helpers์์ ๋ถ๋ฌ ์ค์ผ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ ์๋ ์ฒ๋ผ <code>Template.mainLayout.helpers</code> ์ ๋ฆฌํด์ ํด์ฃผ๋ฉด ๋๊ฒ ์ต๋๋ค.<br>์ด๋ ๊ฒ ํด๋๋ฉด ์ต์์ ํ์ด์ง์ธ main-layout ์๋์ ๋ชจ๋ ํ์ด์ง๋ ์ฒซ ํ๋ฉด์ด ๋ฐ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก <code>showLoadingEffect</code> ๊ฐ true๊ฐ ๋๊ณ , ๋ฐ๋ผ์ <code>mainLoading</code> ํ
ํ๋ฆฟ์ด ํ์ฑํ ๋๋ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๊ฒ ๋ฉ๋๋ค. </p>
<p><code>client/main-layout.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">Template.mainLayout.onCreated(function(){</div><div class="line"></div><div class="line"> // ReactiveVar์ ๊ฒฝ์ฐ ๋ค๋ฅธ ํฌํ๋ฆฟ์์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ window๋ฅผ ์จ ์ ์ญ์ผ๋ก ๋ง๋ค์ด ์ค์ผ๋ง ํ๋ค.</div><div class="line"> window.showLoadingEffect = new ReactiveVar(false);</div><div class="line">});</div><div class="line"></div><div class="line">Template.mainLayout.helpers({</div><div class="line"></div><div class="line"> showLoadingEffectLoad: function ()</div><div class="line"> {</div><div class="line"> return showLoadingEffect.get();</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>reactive-var ๋ ์ผ์ข
์ ์ผ์? ๊ฐ์ ์ญํ ์ ํ๋ค๊ณ ์ค๋ช
๋๋ ธ์ต๋๋ค. ๊ทธ๋ผ ์ด ์ผ์(?)๊ฐ ์ด๋ป๊ฒ ์๋ํ๋์ง ์ด์ ๋ถํฐ ์์๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>์ด์ ๋ชจ๋ ํด๋ผ์ด์ธํธ ํ์ด์ง์์ โshowLoadingEffect.set(true);โ ์ด set๋ ๊ฐ์ true๋ก ํ๋ฉด <code><template name="mainLoading"></template></code>์ด ๋ณด์ฌ์ง๊ณ , false๋ก ํด์ฃผ๋ฉด ์ด ํ
ํ๋ฆฟ์ด ์ฌ๋ผ์ง๋ ์๋ฆฌ์
๋๋ค.</p>
<p>์ฐ์ ์ฐ๋ฆฌ๊ฐ ๋ง๋ ํ์ด์ง login.html, register.html ํ์ด์ง์ ์ ์ฉํด ํ์ด์ง๊ฐ ๋ฐ ๋ ๋ก๋ฉํจ๊ณผ๊ฐ ๋ํ๋๋๋ก ํด๋ณด๊ฒ ์ต๋๋ค.<br>๋ค์ ์์ค๋ ํ์ฌ ์ฌ์ฉํ๊ณ ์๋ <code>login.js</code> ํ์ด์ง์ conCreated์ onRendered ๋ผ๋ ๋ผ์ดํ ์ฌ์ดํด ํจ์๋ฅผ ์ถ๊ฐํ ๋ด์ฉ์
๋๋ค. onCreated ๋ ๋ <code>showLoadingEffect.set(true);</code> ๋ฅผ ์๋์ํค๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ๋ก๋ฉ ํ์ด์ง๊ฐ ๋ณด์ฌ์ง๊ฒ ๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ onRendered ์ผ๋ <code>showLoadingEffect.set(false);</code> ๋ฅผ ํด์ฃผ๋ฉด ๋ก๋ฉ ํ๋ฉด์ด ์ฌ๋ผ์ง๊ฒ ์ฌ๋ผ์ง๊ฒ ๋ฉ๋๋ค. ์ฌ๋ผ์ง ๋๋ ๋ฐ๋ก false๋ฅผ ํด๋ฒ๋ฆฌ๋ฉด ๋ก๋ฉ ํจ๊ณผ๊ฐ ๋๋ฌด ๋นจ๋ฆฌ ์ฌ๋ผ์ง๋ฏ๋ก Meteor.setTimeout์ ์ด์ฉํด ์ฝ๊ฐ์ ๋๋ ์ด๋ฅผ ์ฃผ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ ์๋์ ๊ฐ์ด ์ ์ฉํ์ต๋๋ค. </p>
<p><code>client/login.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.login.onCreated(function () {</div><div class="line"> showLoadingEffect.set(true);</div><div class="line">});</div><div class="line"></div><div class="line">Template.login.onRendered(function () {</div><div class="line"></div><div class="line"> Meteor.setTimeout(function() {</div><div class="line"> showLoadingEffect.set(false);</div><div class="line"> }, 2 * 200);</div><div class="line"></div><div class="line">});</div><div class="line"></div><div class="line">[์๋ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div></pre></td></tr></table></figure>
<p>๊ฐ์ ์๋ฆฌ๋ก ๋ก๋ฉ ํจ๊ณผ๋ฅผ ์ฃผ๊ณ ์ถ์ ๋ค๋ฅธ ํ์ด์ง์๋ conCreated์ onRendered ์ผ ๋ ์์ ์์ค๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ๋ก๋ฉ ํ๋ฉด ํ์ ํ์ด์ง๊ฐ ๋ณด์ฌ์ง๊ฒ ๋ฉ๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/K89HeEI5NwNcDQmf0lIV9XViNutCV3Fg6pzdR-LAYA_0YeiKKEFqxB_ay4ULaaynSIptxrHfd4_RY5VsJMuTb-HJc8vRQrL2TA4xCFErqjNQPPcYylzqMwbY3jOdRUFI2XnH5xUhNHFZs12BxgNqXXnL7_2yL3ggbAEpiBd0SPuVKs5V3RRbtx4z_hCkvT7eyL-7GVLQApjjH02GS4nGnhx7qmrqQrVaVhjq579hqa69hDBgkhGjFL0KMbhis8ZK2Ykd-5t6qc7e0f6XFafTnJyxrkcq_sS2V9-qYZ61pB0naeHnEeSquerwY-SClQFSPH-EzU18ZCx_R8G_YxYiXNxzzc2M7al7wVFHwH5DY5-CkgMQrIlIszEUDE3WmNzXrJQgkyjkXBnCB13yHBWAbLmH_r5mzVTvHDKuC2zeNhAtg8g9mwW4mDLoRf61FjhFVaTKYldhkk89AoGoUSd15-64f_d8FLIwu5SjbykeL26YkaCobXHXop5qIuH1fG40IminMSQ4JNEuLXXdywVoT0BBZN5TZXctVc5uZXLbR-jXE3RHN2UFTX2UsVzW6H4GcYzo8xI5CmVznjVzLVl3HJ-gbnDfmVuYt_fJr1g0o5oM3OeisoRDdFc-93_SznFKfNBRDPwZDlwSu_KGfyNJ6mwJnTDaCcweLRcYr-U48z8=w518-h336-no"></p><p style="text-align: center;">[๋ก๋ฉํ๋ฉด]</p><p></p>
<p>๋ค์์ผ๋ก ์ด ํจ๊ณผ๋ฅผ ๋จ์ํ ํ๋ฉด์ด ๋ณ๊ฒฝ๋ ๋ ์ฃผ๋ ๊ฒ์ด ์๋ ์์์๋ ๋งํ์ง๋ง, ์ธ์ฆ๋ฉ์ผ ์ฌ๋ฐ์ก ๊ฐ์ด ์ ์ง ํ๋ฉด์ผ๋ก 2~3์ด ์ด์ ์์ด์ผ ํ๋ ํ์ด์ง์ ์ฃผ๋ ๋ฐฉ๋ฒ์ ์ค๋ช
๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฌ์ค ์ ์ฉ ๋ฐฉ๋ฒ์ ์์ ๋ด์ฉ๊ณผ ๊ฑฐ์ ๊ฐ์ต๋๋ค. </p>
<p><code>client/home.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">Template.home.events({</div><div class="line"> 'click button[name=btn-logout]' (vet, tmpl)</div><div class="line"> {</div><div class="line"> event.preventDefault();</div><div class="line"> Meteor.logout();</div><div class="line"> },</div><div class="line"> 'click button[name=resend-verification-link]' ( event, template ) {</div><div class="line"></div><div class="line"> showLoadingEffect.set(true); // ๋ก๋ฉํจ๊ณผ ์ถ๊ฐ</div><div class="line"></div><div class="line"> let user = Meteor.userId();</div><div class="line"></div><div class="line"> Meteor.call( 'sendVerificationLink', user, ( error, response ) => {</div><div class="line"> if ( error ) {</div><div class="line"> showLoadingEffect.set(false); // ๋ก๋ฉํจ๊ณผ ์ถ๊ฐ</div><div class="line"> Bert.alert( error.reason, 'danger' );</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"></div><div class="line"></div><div class="line"> showLoadingEffect.set(false);</div><div class="line"> let email = Meteor.user().emails[ 0 ].address;</div><div class="line"> Bert.alert( `Verification sent to ${ email }!`, 'success' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure></p>
<p>๋ฉ์ผ ์ฌ๋ฐ์ก ๋ฒํผ์ด<code>'click button[name=resend-verification-link]'</code> ํด๋ฆญ๋๋ฉด <code>showLoadingEffect.set(true);</code> ๋ฅผ ์ค์ ๋ก๋ฉ ํ๋ฉด์ด ๋ํ๋๊ฒ ํด์ค๋๋ค. ๊ทธ๋ฆฌ๊ณ <code>sendVerificationLink</code> ๋ฉ์๋๊ฐ ์คํ๋๊ณ , ์๋ฃ๋๋ ํ์ด๋ฐ(์ ์์คํ์ด๋ ์ค๋ฅ๊ฐ ๋ฌ๋)์ <code>showLoadingEffect.set(false);</code> ์ด ์ธํ
์ ํด์ฃผ๋ฉด ๋์
๋๋ค. ์ด์ ๋ฉ์ผ ๋ฐ์กํ ๋ช์ด๊ฐ์ ํ์ด๋ฐ์ ์ด์ฉ์๊ฐ ๊ธฐ๋ค๋ ค์ผ ํ๋ค๋ ๊ฒ์ ์ง๊ด์ ์ผ๋ก ์ธ์งํ ์ ์๋ ๊ตฌ์กฐ๊ฐ ๋์์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/ikmevgfSRK3ENk_Q6Aqjt1By-2ZSi1kkPpfcAr6Zajew3Yqg988lqseg4Rx5kUdyahLCo4OcQrohCmwg5-l6nIya_nxfL9AmLx4th6XqwXWIJOId8CEzcU6OyNB_KgriN_iIyaZQEvWtpMVR1T2qvfQwf3BLpw76N0Qa5VByPnYR-EiFlacsU-9RAd_ISDu-uwIAfHuEaLNBGpIJPPfi0Bpbuwf3yRAFEWT24qHMGad2c81EHC-sRY7HVYm_GpNqFx9pf312tI6tvZIJ51ZAeCZynGtRo7YyQwa4hl5AE6gApVpw7_McpF_i-ZD7BI3m-8GGJ32iqs2U_6QMhLyg-S033WrL_ZP3y1DyPrHgG4OuVu9B2FXJSH_PQNEucVmz42Ro_MdETC9ncVwIEqdwrNvharb0R3ROWVeuiAc1KLoNAnFOOllrIShRzV-D8d7LvwwRkalLO1_CB2ykqgClMeTmJxNRj1O5qWRL7m_uAytfUHYT_5Rzbi-MrsEtvR1eZfSYh_U0_oS4KnLkTgo5YZVtsGJTRwU2ccyOVOcdz7-7GUVLZwXvUvLEYN6rnCp69q4oRYKVrNygY8vaOt6I_9MxtfK57yzClzJC_MgX3H-K9lGeXf7yBqxp3uqmqdnfWZWQsK22dz6iNbRJxgfS2U2I2q6lZcUi2b-ix86uxYw=w806-h528-no"></p>
<p>์ด์์ผ๋ก <code>ReactiveVar</code>๋ฅผ ์ด์ฉํ Meteor๋ก๋ฉ์ ๋ํด์ ์์๋ดค์ต๋๋ค. <code>ReactiveVar</code>๋ ์ด๋ฅผ ์์ฉํ๋ฉด ๋ค์ํ ๋ถ๋ถ์ ํ์ฉ์ด ๊ฐ๋ฅํ ์ ๊ธฐํ Meteor์ ๊ธฐ๋ฅ์
๋๋ค. ๋ค์ํ ๋ถ๋ถ์์ ํธ๋ฆฌํ๊ฒ ์ด์ฉํด ๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.<br>๊ทธ๋ผ ๋ค์ ์๊ฐ์ account ๊ฐ์ข๋ฅผ ๋ง๋ฌด๋ฆฌ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
]]></content>
<summary type="html">
<h3 id="7-ํ๋ฉด์ ํ-ํจ๊ณผ"><a href="#7-ํ๋ฉด์ ํ-ํจ๊ณผ" class="headerlink" title="7. ํ๋ฉด์ ํ ํจ๊ณผ"></a>7. ํ๋ฉด์ ํ ํจ๊ณผ</h3><p>Meteor ์ธ์ฆ(account) ๊ด๋ จ ๊ฐ์ข๋ฅผ ๋ ์งํํ๊ธฐ ์ ์ ํ์ฌ๋ง๋ค
</summary>
<category term="meteor, custom account, ๋ฏธํฐ์ด" scheme="http://freeseamew.github.io/tags/meteor-custom-account-%EB%AF%B8%ED%8B%B0%EC%96%B4/"/>
</entry>
<entry>
<title>Meteor custom account ๊ฐ์ข 3</title>
<link href="http://freeseamew.github.io/2017/07/04/meteor-account-tutorial-3/"/>
<id>http://freeseamew.github.io/2017/07/04/meteor-account-tutorial-3/</id>
<published>2017-07-03T15:41:36.000Z</published>
<updated>2017-07-03T15:42:28.000Z</updated>
<content type="html"><![CDATA[<h3 id="6-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ-๋ฐ-์ฌ๋ฐ๊ธ"><a href="#6-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ-๋ฐ-์ฌ๋ฐ๊ธ" class="headerlink" title="6. ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๋ฐ ์ฌ๋ฐ๊ธ"></a>6. ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๋ฐ ์ฌ๋ฐ๊ธ</h3><h4 id="6-1-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ"><a href="#6-1-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ" class="headerlink" title="6.1 ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ"></a>6.1 ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</h4><p>์ด์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์๊ฐ์
, ๋ก๊ทธ์ธ, ๋ก๊ทธ์์์ ๋ํ ๊ธฐ๋ฅ๋ค์ ๋ชจ๋ ๋ง๋ค์์ต๋๋ค. ๋ค์์ ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ ๋ฐ ์ฌ๋ฐ๊ธ์ ๋ํ ๊ธฐ๋ฅ์ ์ถ๊ฐํด ๋ณด๊ฒ ์ต๋๋ค.<br>์๋๋ ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ html ํ์ผ์์ค์
๋๋ค. ๊ธฐ์กด๋น๋ฒ, ์๋น๋ฒ, ์๋น๋ฒ ํ์ธ์ 3๊ฐ์ง ํ
์คํธ ๋ฐ์ค๋ก ๊ตฌ์ฑ๋ ํผ ์
๋๋ค. </p>
<p><code>client/change-password.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><template name="changePassword"></div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <a href="{{pathFor '/'}}"><h2>METEOR ACCOUNTS</h2></a></div><div class="line"> <p>๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</p></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"></div><div class="line"> <form class="col-md-12 panel-body-inner"></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" id="old-password" class="form-control account-text-form-1" placeholder="๊ธฐ์กด ๋น๋ฐ๋ฒํธ"></div><div class="line"> </div></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" id="new-password" class="form-control account-text-form-1" placeholder="์ ๋น๋ฐ๋ฒํธ"></div><div class="line"> </div></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" id="new-password-confirm" class="form-control account-text-form-1" placeholder="์ ๋น๋ฐ๋ฒํธ ํ์ธ"></div><div class="line"> </div></div><div class="line"> </form></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="change-password" class="btn btn-danger btn-lg btn-block button">๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</button></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๋ค์์ ์ด ํผ์ด ์ค์ ๋ก ์คํ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์
๋๋ค. ์ง๊ธ๊น์ง์์ ์์ค์ ์กฐ๊ธ ๋ค๋ฅธ ์ ์ด ์๋ค๋ฉด ํจ์ค์๋ ๋ณ๊ฒฝ api์ธ <code>Accounts.changePassword</code>์ด ํด๋ผ์ด์ธํธ ์ธก์์ ์คํ๋๋ค๋ ์ ์
๋๋ค. ๊ทธ๋์ ํผ๊ฒ์ฆ์ ์๋ฒ๊ฐ ์๋ ํด๋ผ์ด์ธํธ์์ ์คํ์์ผ ์ฃผ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ์ด์ ๊ฐ์ข์์๋ ๋งํ๋ฏ <code>lib</code> ํด๋์ ์๋ ์์ค๋ ํด๋ผ์ด์ธํธ์ ์๋ฒ ๋ชจ๋์์ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค๋ ๊ฒ์ ๋ค์ํ๋ฒ ํ์ธ ํ ์ ์์ต๋๋ค. </p>
<p><code>client/change-password.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.changePassword.events({</div><div class="line"> 'click button[name=change-password]' (evt, tmpl)</div><div class="line"> {</div><div class="line"></div><div class="line"> evt.preventDefault(); //์๋ก ๊ณ ์นจ ๋ฐฉ์ง</div><div class="line"></div><div class="line"> var oldPassword = tmpl.find('#old-password').value;</div><div class="line"> var newPassword = tmpl.find('#new-password').value;</div><div class="line"> var newPasswordConfirm = tmpl.find('#new-password-confirm').value;</div><div class="line"></div><div class="line"></div><div class="line"> try</div><div class="line"> {</div><div class="line"> NotEmptyString(oldPassword);</div><div class="line"> NotEmptyString(newPassword);</div><div class="line"> NotEmptyString(newPasswordConfirm);</div><div class="line"> isValidPassword(newPassword);</div><div class="line"> isMatchPassword(newPassword, newPasswordConfirm);</div><div class="line"> }</div><div class="line"> catch(err)</div><div class="line"> {</div><div class="line"> Bert.alert( err.message , 'danger', 'growl-top-right' );</div><div class="line"></div><div class="line"> return;</div><div class="line"> }</div><div class="line"></div><div class="line"> Accounts.changePassword(oldPassword, newPassword, function(err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> Bert.alert('ํจ์ค์๋๋ฅผ ๋ณ๊ฒฝํ์ต๋๋ค.' , 'success', 'growl-top-right');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"></div><div class="line"> var errMessage = '';</div><div class="line"></div><div class="line"> if(err.message === 'Incorrect password [403]')</div><div class="line"> {</div><div class="line"> errMessage = "๊ธฐ์กด ๋น๋ฐ๋ฒํธ๊ฐ ๋ค๋ฆ
๋๋ค."</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> errMessage = err.message;</div><div class="line"> }</div><div class="line"></div><div class="line"> Bert.alert( errMessage , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>Meteor API๋ ๊ทธ ์ฑ๊ฒฉ์ ๋ฐ๋ผ ํด๋ผ์ด์ธํธ, ์๋ฒ ๋ชจ๋์์ ์คํ๋๊ธฐ๋ ํ๊ณ , ๊ฐ๊ฐ์์๋ง ์คํ๋๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค. ์๋ ๋งํฌ์๋ ๊ฐ API๊ฐ ์ด๋ค ๊ณณ์์ ์คํ๋๋์ง ์ ์ ๋ฆฌ๋์ด ์์ต๋๋ค. ๊ฐ๋ ์ ์ด๊ณณ์์ ์คํ์ด ์๋์ง ํ ๋ ํ์ธํด ๋ณด์๋ฉด ๋์์ ๋ฐ์ ์ ์์ต๋๋ค. </p>
<blockquote>
<p><a href="http://frozeman.de/blog/2015/01/meteor-cheatsheet/" target="_blank" rel="noopener">http://frozeman.de/blog/2015/01/meteor-cheatsheet/</a></p>
</blockquote>
<hr>
<h4 id="6-2-๋น๋ฐ๋ฒํธ-์ฌ๋ฐ๊ธ-์์ด๋ฒ๋ ธ์-๋"><a href="#6-2-๋น๋ฐ๋ฒํธ-์ฌ๋ฐ๊ธ-์์ด๋ฒ๋ ธ์-๋" class="headerlink" title="6.2 ๋น๋ฐ๋ฒํธ ์ฌ๋ฐ๊ธ(์์ด๋ฒ๋ ธ์ ๋)"></a>6.2 ๋น๋ฐ๋ฒํธ ์ฌ๋ฐ๊ธ(์์ด๋ฒ๋ ธ์ ๋)</h4><p>๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ๊ณผ ํจ๊ป ์์ฃผ ์ฐ๊ฒ ๋ ๊ธฐ๋ฅ์ ๋น๋ฐ๋ฒํธ ์ฌ๋ฐ๊ธ์ด ๋ ๊ฒ์
๋๋ค. ๋น์ทํ ๊ธฐ๋ฅ ๊ฐ์ง๋ง, ์ฌ๋ฐ๊ธ์ ๊ฒฝ์ฐ ๋น๋ฐ๋ฒํธ๋ฅผ ์์ด๋ฒ๋ ธ์ ๊ฒฝ์ฐ์ ์ฌ์ฉ๋๋ ๊ธฐ๋ฅ์
๋๋ค.<br>์ฌ๋ฐ๊ธ ๊ณผ์ ์ ์ค๋ช
๋๋ฆฌ๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>์ฌ๋ฐ๊ธ ๊ณผ์ : ์ฌ๋ฐ๊ธ ํ์ด์ง(๊ฐ์
์ด๋ฉ์ผ ์
๋ ฅ) -> ๊ฐ์
์ด๋ฉ์ผ ํ์ด์ง์์ ๋งํฌ ํ์ธ -> ์ฌ๋ฐ๊ธ ํ์ด์ง์์ ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</p>
</blockquote>
<ol>
<li>์ฌ๋ฐ๊ธ ํ์ด์ง</li>
</ol>
<p><img src="https://lh3.googleusercontent.com/b502yJY5IKW-c0hzmFGfO6iQG4yxzX4b-6otBlL3OE0kq4mLgIGFQoaj6t0-x4rHN24V57P5-XcguT3tzaJStYj9-Ii-u_Vy-zKiFrD1KEmJ-Hd5D3_QD8VZwpyQWNqfwbVvbG9A696RR5hjWa4vAfKiXwLLX_DbSLnmrM7DcoHYaBVPAaAQNWa_62HlNLv_4X8T5kKg_k3WwJ5qP0vAksP1MJtfOKfGp0JCqWoZBvCuHlAtC_LWVxjR-2RaBHVzaWatE_Jow0E8EzIFIZS3oQeGzmAgZTs4mDaMQQg8EZtMK_OxnhEJcMxTmt_0dvPGdAVLg20T9nDEuwdG4c0ort-p5fN5a3_5qDoOqjR13rFQtjrxpQVg39JnXXEDP8pPjQMpzEblOAdeGxfs87mtU7HxnGtoCbi212Jb9cQCzhy5vtSvu6fAiTBfS1_Vu7VOyXrlhHk9beCc-ykTPtA7g1lin_OtMJuMab4I9h1ficD5CXISIrqAq5z0hIwHiBYWNYzdP_HrTriFtD-Z1gX00N5vScS7suow1lYy0AL3MmPnXzTsSCgU59mffNwl-QWciLi1OPf8tOVSAM0DNhIlqQnBFHhVM_6eVvmrpPnkrnyrcHI8RxsqA92MSVT0zQqfvRHqh83alr_UEtH-13gUitLT4fQ1mzolIqE5CDnq8kQ=w599-h318-no"></p>
<ol>
<li>๊ฐ์
๋ฉ์ผ์์ ์ฌ๋ฐ๊ธ ํ์ด์ง ๋งํฌ ํ์ธ</li>
</ol>
<p><img src="https://lh3.googleusercontent.com/U9-7PCzQ3fRaXc8BBWbj2MrD7dAdkhP3ntIkBmbbpbvp_ElCAunqcsswX613QFtxqbV1K6jY3i-wCsm-PopMEIy_PQETqjUdXdaIHx_PT56xWNKa4IO4u9UiJT93CJOGb4hfyiNxkFtrgGWXXq8SZaznlmuIHOvybw796KzfFOof0LQUFhipM9Q9gA31vGT9Vngbryp3RYFRnvdeyGnp1ithq2rsBMQxcAdYjb6RgXOTndxdIevtO3cNrKe-EIYxXoRYNGUpqjwHEKXrc_pxPy0kMIeE0shanzXGTAEhu70bRrjytckLXbVDlpGl4RuovZXz9oBg36fwaZOwTxym3Ip0bWUKJx6leCQMnJPihi_90_IoC5P_VjA2J3RLPt_CmNG0TffBmPJWKexZah80R4v28dup8n3nnEtAWOzxwlwCEGexsysW_XNVeblpQT8c3jVD_LZKnxHQoAkhDvdSDubr5320Aa0ohs0yVnAScGuu_-DnbDej0pFgCEoA-Qe4wBZgYs6K0RDPORscOn-WNv4cs-aO5FylWFVM3L-OsHyD8zTEYvO5dctnsySHVcjqX1Gn1BNeB4JkhVY-b1H-z69z2p5u2aMlhXcFDvAS4ZqP0ZvZX5bCF-Ej8iBHjID8ADODx0YzNEwkTNwakjGcnxWQvMzYJJJ47CSdEYtkPvw=w659-h116-no"></p>
<ol>
<li>์ฌ๋ฐ๊ธ ํ์ด์ง์์ ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</li>
</ol>
<p><img src="https://lh3.googleusercontent.com/JUTn6Anry7zeWb2CxT8DgB3WuwHFi3x3bNbkr2nrcDRmTLXTMpHVFQZ2MhLP0CoZ0Quf8OfCaX1u1WqrOputshtKYhOcHS-mD4B0aQ7-Exvej343tD0l5FrV6gWLuOrD1pyVxvAoJPwP-OoqZklCiyA7kl45q7iJt72HXee8jAUTULT-YEIcijc8AwJJOuH8AO8z9i8_zwmNF7Z_8IqUQU96ZyY4LHAzghoYZlVqHqz2STr5hdpXC_kM5RgqYKGN2NbrVjVMMSzrJYwQWlfFXlyzBZu_xUqwVobxo0by8R0TNlmIy-DMo6A0SHYUEXrdfeZU_y810I74UkUpyT_VJnR9kGKeDOZXZh_y-NUMgFRr_BZXWUKe_BQ-gPPJOpBF2YhH9iepZMTHnZqKbmJMK4ARgDyVgZ5w9yun7dYHc7mp8-1WVnNtijKBuyGw6SL15YT2S9BpEL1FkIMWhnTWWIpCtAfJiGNgVU4V52BLSO67JOBkwnmL-zofwRJYgu6J7EW9Gj6KQJXutMwDlTeVxIJc1siv0PM0koKp7JliGUP4Pm48zbQoG0Bc-eqfmVKDAcEyuxvPGzsNyP9JUvTqze1boGjRMmYd7LxAXdSeMV15_2cHvXbSXtOnyI20smJkQMg3ZWveoaQ2Aweq3aBsqMWgVmyqCErDpNxlUq3yVl8=w599-h389-no"></p>
<p>์ ๋จผ์ ๋ผ์ฐํฐ๋ฅผ ์ถ๊ฐํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. <code>recover</code>๋ ๊ธฐ๋ณธ์ ์ธ ์ฌ๋ฐ๊ธ ํ์ด์ง์ ๋ํ ์ฃผ์๊ฐ ๋๊ณ , <code>reset-password</code>๋ ๋ฉ์ผ๋ก ๋ณด๋ด์ง ํค ๊ฐ์ ํ์ธํ๋ ํ์ด์ง๊ฐ ๋๊ฒ ์ต๋๋ค. ํค๊ฐ ๋ง์ผ๋ฉด <code>window.resetPasswordVar</code>๋ผ๋ reactiveVar๋ฅผ ๋ง๋ค๊ณ ์ฌ๊ธฐ์ ํค๊ฐ์ ๋ฃ์ด ์ฃผ๋ ์์ ๊ตฌ์กฐ๊ฐ ๋๊ฒ ์ต๋๋ค. </p>
<p><code>lib/routes.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ ์๋ต]</div><div class="line"></div><div class="line"></div><div class="line">// ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๊ด๋ จ</div><div class="line">FlowRouter.route('/ recover', {</div><div class="line"> name:'recoverPassword',</div><div class="line"> action: function()</div><div class="line"> {</div><div class="line"> BlazeLayout.render('mainLayout', {</div><div class="line"> content: 'recoverPassword'</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">FlowRouter.route( '/reset-password/:token', {</div><div class="line"> name: 'reset-password/',</div><div class="line"> action( params )</div><div class="line"> {</div><div class="line"> window.resetPasswordVar = new ReactiveVar(params.token);</div><div class="line"> FlowRouter.go( '/recover' );</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>๋๋ฒ์งธ๋ก ํจ์ค์๋ ์ฌ๋ฐ๊ธ์ ๊ฒฝ์ฐ๋ ๋ฉ์ผ์ ํตํด์ ์ด๋ฃจ์ด์ง๋ฏ๋ก ๊ฐ์
ํ์ธ ๋ฉ์ผ๊ณผ ๋ค๋ฅธ ์ฌ๋ฐ๊ธ ํค ๊ฐ์ ๋ํ ๋ฉ์ผ์ ๋ณด๋ด๋ ๋ถ๋ถ์ ์ธํ
ํ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p><code>server/accountsMails.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"></div><div class="line">// ๊ฐ์
ํ์ธ ๋ฉ์ผ</div><div class="line">Accounts.emailTemplates.verifyEmail = {</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line">// ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๋ฉ์ผ</div><div class="line">Accounts.emailTemplates.resetPassword = {</div><div class="line"> subject() {</div><div class="line"> return "Meteor accounts ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๋ฉ์ผ";</div><div class="line"> },</div><div class="line"> text( user, url ) {</div><div class="line"> //let emailAddress = user.emails[0].address,</div><div class="line"> let emailAddress = user.username,</div><div class="line"> urlWithoutHash = url.replace( '#/', '' ),</div><div class="line"> supportEmail = "์ด๋ฉ์ผ ์ฃผ์",</div><div class="line"> emailBody = `๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ์ ์ํ์๋ฉด ๋ค์ ๋งํฌ๋ฅผ ํด๋ฆญํด์ฃผ์ธ์. \n\n link: ${urlWithoutHash} \n\n ๋ง์ฝ ํ์ธ์ ์์ฒญํ์ง ์์ ๊ฒฝ์ฐ, ์ด ์ด๋ฉ์ผ์ ๋ฌด์ํ์ญ์์ค. ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐ๋๋ฉด ๋ค์ ์๋น์ค ์ง์ํ์ ๋ฌธ์ํ์ญ์์ค. \n\n ๋ฌธ์ ์ฃผ์ : ${supportEmail}.`;</div><div class="line"></div><div class="line"> console.log('mailUser');</div><div class="line"> console.log(user);</div><div class="line"></div><div class="line"> return emailBody;</div><div class="line"> }</div><div class="line">};</div></pre></td></tr></table></figure>
<p>๋ค์์ผ๋ก <code>recover-password.html</code> ๋ฅผ ์์ฑํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค ์์ค์์ ํน๋ณํ ์ ์ <code>#if resetPassword ...else</code> ์ด ๋ถ๋ถ์ด ๋๊ฒ ๋๋ฐ์. ์ด๋ฉ์ผ๋ก ๋ณด๋ด์ง ํค๊ฐ์ ํ์ธํด reactiveVar๋ก ๋๊ฒจ์ง <code>resetPasswordVar</code> ๋ฅผ ์ฒดํฌํ์ฌ ๊ฐ์ด ์์ผ๋ฉด ๋ฉ์ผ๋ณด๋ด๊ธฐ ํ์ด์ง๋ฅผ ํค๊ฐ์ด ์์ผ๋ฉด ์๋ก์ด ๋น๋ฐ๋ฒํธ ์
๋ ฅ ํ์ด์ง๋ฅผ ๋ณด์ฌ์ฃผ๋ ์กฐ๊ฑด๋ฌธ์ด๋ผ๊ณ ๋ณด์๋ฉด ๋๊ฒ ์ต๋๋ค. (reactiveVar์ ๊ฒฝ์ฐ ์์ ๊ฐ์ข์์ ์กฐ๊ธ ์ค๋ช
๋๋ ธ์ผ๋ ๊ทธ๋ถ๋ถ์ ์ฐธ๊ณ ํ์๋ฉด ๋์์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ธฐํ๊ฐ ๋๋ฉด ์ข ๋ ์์ธํ ๋ค๋ฃฐ ๋งํ ์ฃผ์ ๊ธด ํ๋ค์. ์์๋๋ฉด ์ฐธ ํธ๋ฆฌํ ๊ธฐ๋ฅ์ด๋ผ๊ณ ์๊ฐํ๋ ๊ธฐ๋ฅ์
๋๋ค.ใ
)</p>
<p><code>client/recover-password.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line"><template name="recoverPassword"></div><div class="line"> {{#if resetPassword}}</div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <a href="{{pathFor '/'}}"><h2>METEOR ACCOUNTS</h2></a></div><div class="line"> <p>๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</p></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"></div><div class="line"> <form class="col-md-12 panel-body-inner"></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" id="reset-password" class="form-control account-text-form-1" placeholder="๋น๋ฐ๋ฒํธ"></div><div class="line"> </div></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" id="reset-password-confirm" class="form-control account-text-form-1" placeholder="๋น๋ฐ๋ฒํธ ํ์ธ"></div><div class="line"> </div></div><div class="line"> </form></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="reset-password" class="btn btn-danger btn-lg btn-block button">๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</button></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> {{else}}</div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <a href="{{pathFor '/'}}"><h2>METEOR ACCOUNTS</h2></a></div><div class="line"> <p>๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</p></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"></div><div class="line"> <form class="col-md-12 panel-body-inner"></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" id="user-email" class="form-control account-text-form-1" placeholder="๋ฉ์ผ์ฃผ์"></div><div class="line"> </div></div><div class="line"> </form></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="send-email" class="btn btn-danger btn-lg btn-block button">๋ฉ์ผ๋ณด๋ด๊ธฐ</button></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> {{/if}}</div><div class="line"></template></div></pre></td></tr></table></figure>
<p>์์ htmlํ์ด์ง์ ๋ํ js ํ์ผ์ ์์ฑํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฐ์ <code>Template.recoverPassword.helpers({})</code> ์ resetPassword๋ผ๋ ํจ์๋ฅผ ๋ง๋ค๊ณ ๋ผ์ฐํฐ์์ ์ธํ
๋ <code>resetPasswordVar</code>๋ฅผ get() ํ๋ ์์ค๋ฅผ ์์ฑํด์ฃผ์ธ์. ์ด ๋ถ๋ถ ๋๋ฌธ์ htmlํ์ด์ง์ <code>#if resetPassword</code>์ด ์๋ํ๊ฒ ๋ฉ๋๋ค. </p>
<p><code>Accounts.resetPassword(resetPasswordVar.get(), password, function(err){})</code> ๋ถ๋ถ์ ์ค์ ํจ์ค์๋๋ฅผ ์ฌ๋ฐ๊ธ ํ๋ ์์ค ์
๋๋ค. ์ฒ์ <code>resetPasswordVar.get()</code> ๋ ๋ฉ์ผ๋ก ๋ฐ์ก๋ ํค ๊ฐ์ ๋ํ ๊ฒ์ฆํ๋ ๋ถ๋ถ์ด ๋๊ฒ ์ต๋๋ค. ์ด ๋ฐ๊ธ๋ ํค๊ฐ ๋ง๋ค๋ฉด ์๋ก ์
๋ ฅํ๋ ํจ์ค์๋๋ก ๋ณ๊ฒฝ์ด ์ด๋ฃจ์ด ์ง๋๋ค. ๋ณด์๋ฉด ์๊ฒ ์ง๋ง, ์ฌ์ฉ๋๋ API๋ค์ด ์๋นํ ๊ผผ๊ผผํ๊ฒ ๋ง๋ค์ด ์ก๋ค๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. </p>
<p><code>client/recover-password.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div></pre></td><td class="code"><pre><div class="line">Template.recoverPassword.onRendered(function () {</div><div class="line"> showLoadingEffect.set(false);</div><div class="line">});</div><div class="line"></div><div class="line">Template.recoverPassword.helpers({</div><div class="line"> resetPassword: function()</div><div class="line"> {</div><div class="line"> //return Session.get('resetPassword');</div><div class="line"> return resetPasswordVar.get();</div><div class="line"> Bert.alert( resetPasswordVar.get(), 'success' );</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">Template.recoverPassword.events({</div><div class="line"></div><div class="line"> 'click button[name=reset-password]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"></div><div class="line"> var password = tmpl.find('#reset-password').value;</div><div class="line"> var passwordAgain = tmpl.find('#reset-password-confirm').value;</div><div class="line"> </div><div class="line"> // ์
๋ ฅ ๊ฒ์ฆ</div><div class="line"> try</div><div class="line"> {</div><div class="line"> NotEmptyString(password);</div><div class="line"> NotEmptyString(passwordAgain);</div><div class="line"> isMatchPassword(password, passwordAgain);</div><div class="line"> }</div><div class="line"> catch (err)</div><div class="line"> {</div><div class="line"> Bert.alert( err.message , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> </div><div class="line"> // ๋น๋ฐ๋ฒํธ ์ฌ๋ฐ๊ธ</div><div class="line"> Accounts.resetPassword(resetPasswordVar.get(), password, function(err)</div><div class="line"> {</div><div class="line"> if(err)</div><div class="line"> {</div><div class="line"> Bert.alert( 'ํจ์ค์๋ ๋ณ๊ฒฝ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.' , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> Bert.alert('ํจ์ค์๋๋ฅผ ๋ณ๊ฒฝํ์ต๋๋ค ', 'success', 'growl-top-right');</div><div class="line"> }</div><div class="line"> });</div><div class="line"> },</div><div class="line"> 'click button[name=send-email]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"> showLoadingEffect.set(true);</div><div class="line"></div><div class="line"> var email = tmpl.find('#user-email').value; // trim ๋๊ธฐ</div><div class="line"> Accounts.forgotPassword({email: email}, function(err)</div><div class="line"> {</div><div class="line"> if(err)</div><div class="line"> {</div><div class="line"> if(err.message == 'User not found [403]')</div><div class="line"> {</div><div class="line"> console.log(err.message);</div><div class="line"> showLoadingEffect.set(false);</div><div class="line"> Bert.alert( 'ํด๋น๋ฉ์ผ๋ก ๊ฐ์
์๊ฐ ์์ต๋๋ค.' , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> showLoadingEffect.set(false);</div><div class="line"> Bert.alert( '์ค๋ฅ๋ก ๋ฉ์ผ ๋ฐ์ก์ ์คํจํ์ต๋๋ค. ์ ์ํ ๋ค์ ์๋ํด์ฃผ์ธ์.' , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> showLoadingEffect.set(false);</div><div class="line"> Bert.alert( '๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ์ ๊ดํ ๋ฉ์ผ์ ๋ฐ์กํ์ต๋๋ค.' , 'success', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>์ด์์ผ๋ก ํจ์ค์๋ ์ฌ๋ฐ๊ธ ๊น์ง ๋ง๋ค์ด ๋ดค์ต๋๋ค. ์ด์ ์ ๋ฒ ๊ทธ๋ด๋ฏํ ํ์๊ฐ์
๊ธฐ๋ฅ์ด ๊ตฌํ๋ ๊ฒ ๊ฐ์๋ฐ์. ๋ค์ ๊ฐ์ข์์๋ ๋ง์ง๋ง์ผ๋ก ๊ฐ์ข
์์
์๋น์ค๋ฅผ ํตํ ๊ฐ์
์ ๋ํ ๊ธฐ๋ฅ์ ๊ตฌํํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ด์ ์์ ๋ง์ ๋๋ฆฌ์ง๋ง ์ฌ์ค์ ์ด ์์ค๋ ์์
๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ ๋ง๋ค๋ค๊ฐ ์ ๋ฆฌ๋ ์์ค๋ผ๊ณ ๋ณด์
๋ ๋ฉ๋๋ค. ๋งค๋ ฅ์ ์ด๊ณ ๋ง์ด ์ฐ์ด๋ ๊ธฐ๋ฅ๋ค์ด meteor์์๋ ์ฐธ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋ผ ๋ค์๊ฐ์ข์์ ์์
๋ก๊ทธ์ธ์ ๊ตฌํํด ๋ณด๋ ๊ฒ์ผ๋ก Meteor custom account ๊ฐ์ข๋ฅผ ๋ง๋ฌด๋ฆฌ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค ^^</p>
]]></content>
<summary type="html">
<h3 id="6-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ-๋ฐ-์ฌ๋ฐ๊ธ"><a href="#6-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ-๋ฐ-์ฌ๋ฐ๊ธ" class="headerlink" title="6. ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๋ฐ ์ฌ๋ฐ๊ธ"></a>6. ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ ๋ฐ ์ฌ๋ฐ๊ธ</h3><h4 id="6-1-๋น๋ฐ๋ฒํธ-๋ณ๊ฒฝ
</summary>
<category term="meteor, custom account, ๋ฏธํฐ์ด" scheme="http://freeseamew.github.io/tags/meteor-custom-account-%EB%AF%B8%ED%8B%B0%EC%96%B4/"/>
</entry>
<entry>
<title>Meteor custom account ๊ฐ์ข 2</title>
<link href="http://freeseamew.github.io/2017/07/03/meteor-account-tutorial-2/"/>
<id>http://freeseamew.github.io/2017/07/03/meteor-account-tutorial-2/</id>
<published>2017-07-03T13:55:18.000Z</published>
<updated>2017-07-03T14:07:25.000Z</updated>
<content type="html"><![CDATA[<h3 id="4-ํ์๊ฐ์
-๊ธฐ๋ณธ"><a href="#4-ํ์๊ฐ์
-๊ธฐ๋ณธ" class="headerlink" title="4. ํ์๊ฐ์
๊ธฐ๋ณธ"></a>4. ํ์๊ฐ์
๊ธฐ๋ณธ</h3><p>์ ๋ฒ ๊ฐ์ข๋ฅผ ํตํด ๊ธฐ๋ณธ์ ์ธ ํ์ด์ง ๋์์ธ๊ณผ ํ์ด์ง ์ด๋(routing) ๊ด๋ จ ๊ธฐ๋ฅ์ ์์ฑํ์ต๋๋ค. ๊ทธ๋ผ ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก meteor์ ๊ด๋ จ๋ ๊ธฐ๋ฅ๋ค์ ์์ฑํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ผ๋จ Account์์ ๊ฐ์ฅ ๊ธฐ๋ณธ์ด ๋๋ ํ์ ๊ฐ์
๋ถํฐ ๋ง๋ค์ด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>ํ์๊ฐ์
์ ๋ค์๊ณผ ๊ฐ์ด ๋ช๊ฐ์ง ์๋๋ฆฌ์ค๋ฅผ ๋๊ณ ์งํํ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>1๋จ๊ณ: ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๊ณผ์ ์
๋๋ค. clientํ์ด์ง์์ ๊ฐ์
์ ๋ณด๋ฅผ ํผ์ผ๋ก ๋ฐ๊ณ , ์๋ฒ๋ก ๋ถํฐ ํ์๊ฐ์
์์ฒญ ํ ๊ฐ์
์๋ฃ ๋๋ ํํ์ ์งํ์ด ๋๊ฒ ์ต๋๋ค.<br>2๋จ๊ณ: ์ ํจ์ฑ๊ฒ์ฌ(validate) ์ถ๊ฐ<br>3๋จ๊ณ: ์ด๋ฉ์ผ ์ธ์ฆ </p>
</blockquote>
<hr>
<h4 id="4-1-๊ธฐ๋ณธ-ํ์-๊ฐ์
"><a href="#4-1-๊ธฐ๋ณธ-ํ์-๊ฐ์
" class="headerlink" title="4.1 ๊ธฐ๋ณธ ํ์ ๊ฐ์
"></a>4.1 ๊ธฐ๋ณธ ํ์ ๊ฐ์
</h4><p>์ฐ์ register.js ๋ฅผ ์ด๊ณ ์๋ ์์ค๋ฅผ ์
๋ ฅํด ์ค๋๋ค. </p>
<p><code>client/register.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Template.register.events({</div><div class="line"> 'click button[name=btn-register]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault(); //์๋ก ๊ณ ์นจ ๋ฐฉ์ง</div><div class="line"></div><div class="line"> var inputUsername = tmpl.find('input[name=user-email]').value;</div><div class="line"> var inputEmail= tmpl.find('input[name=user-email]').value;</div><div class="line"> var inputPassword = tmpl.find('input[name=user-password]').value;</div><div class="line"> var inputPasswordAgain = tmpl.find('input[name=user-passwordAgain]').value;</div><div class="line"> var inputFirstName = tmpl.find('input[name=user-firstName]').value;</div><div class="line"> var inputLastName = tmpl.find('input[name=user-lastName]').value;</div><div class="line"></div><div class="line"></div><div class="line"> var inputUser = {</div><div class="line"> username: inputUsername,</div><div class="line"> email: inputEmail,</div><div class="line"> password: inputPassword,</div><div class="line"> passwordAgain: inputPasswordAgain,</div><div class="line"> profile: {</div><div class="line"> firstName: inputFirstName,</div><div class="line"> lastName: inputLastName</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"></div><div class="line"> //์๋ฒ๋ก์ ๋ก๊ทธ์ธ ํธ์ถ</div><div class="line"> Meteor.call('register', inputUser, function (err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> Bert.alert( '๊ฐ์
์ ์ฑ๊ณตํ์ต๋๋ค. ๊ฐ์
ํ ๋ฉ์ผ๋ก ์ธ์ฆ์ ๋ฐ์์ฃผ์ธ์' , 'danger', 'growl-top-right' );</div><div class="line"> FlowRouter.go('/login');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> Bert.alert( err.message , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line"> }</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure></p>
<p>๊ธฐ๋ณธ์ ์ผ๋ก ํ
ํ๋ฆฟ์ ์์๋ฅผ ๊ฐ์ง๊ณ ์ด๋ฒคํธ(๋ง์ฐ์ค click, over ๋ฑ)๋ฅผ ์ผ์ผํค๋ ๋ฐฉ๋ฒ์ <code>Template.ํ
ํ๋ฆฟ์ด๋ฆ.event({})</code> ์ด ๊ฐ์ ๋ฌธ๋ฒ์ ์ฌ์ฉํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ <code>click button[name=btn-register]' (evt, tmpl)</code> ์ด ๋ถ๋ถ์ name=btn-register๋ผ๋ ์ ํ์์ click ์ด๋ฒคํธ๊ฐ ๋ฐ์ ํ์ ๋ ์ด๋ค ์ฒ๋ฆฌ๋ฅผ ํ ๊ฒ์ธ๊ฐ์ ๋ํ ์คํฌ๋ฆฝํธ๊ฐ ๋๊ฒ ์ต๋๋ค. ์ฌ๊ธฐ์ evt, tmpl ์ด๋ผ๋ 2๊ฐ์ง ํ๋ผ๋ฏธํฐ๋ฅผ ๊ฐ๊ฒ ๋๋๋ฐ์. evt๋ ์์ ์์ค๋ก ์๋ฅผ ๋ค์๋ฉด ์ค์ ํด๋ฆญ์ด ์ผ์ด๋ ๋ฒํผ์ ์ก์
๋๊ณ , tmpl์ ํด๋น ์ด๋ฒคํธ๊ฐ ์ผ์ด๋๋ ํ
ํ๋ฆฟ ์ ๋ณด๋ก tmpl์ ์ด์ฉํ์ฌ ์ฌ์ฉํ ํ
ํ๋ฆฟ์ ์ ๋ณด(ex: input ๊ฐ)๋ฅผ ๋ฐ์์ฌ ์ ์์ต๋๋ค. </p>
<p>์ด๋ฅผ ๋ฐํ์ผ๋ก ์๋์ ๊ฐ์ด input ์ ๋ณด๋ฅผ ๋ณ์์ ๋ด์ ์ ์์ต๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">var inputUsername = tmpl.find('input[name=user-email]').value;</div></pre></td></tr></table></figure>
<p><code>var inputUser</code>์ ๊ฒฝ์ฐ ๋ด์ฉ์ ์๋์ ๊ฐ์ ์๋ฏธ๋ฅผ ๊ฐ๋๋ฐ, ์ฌ๊ธฐ์ ์ค์ํ ์ ์ username, email, password ๋ meteor account์ ๊ธฐ๋ณธ ์ ์ฅ ํํ์ด๋ฏ๋ก ๊ผญ ์ด๋ฐ ์์ผ๋ก ์ด๋ฆ์ ์ ํ๋ฉด ๋๊ณ ๊ธฐํ ์ ๋ณด๋ค์ profile์๋์ ์ฌ์ฉ์๊ฐ ์ปค์คํ
ํ๊ฒ ์ํ๋ ์ ๋ณด๋ฅผ ์
๋ ฅํด ๋ ์ ์์ต๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">var inputUser = {</div><div class="line"> username: inputUsername, // ์ ์ ์ด๋ฆ</div><div class="line"> email: inputEmail, // ์ ์ ์ด๋ฉ์ผ</div><div class="line"> password: inputPassword, // ๋น๋ฐ๋ฒํธ(db์ ์ ์ฅ๋ ๋ ์ํธํ ๋จ)</div><div class="line"> passwordAgain: inputPasswordAgain, // ๋น๋ฐ๋ฒํธ ํ์ธ</div><div class="line"> profile: { // ์์ ์ ๋ณด ์ด์ธ์ ์ ๋ณด๋ profile์ ์ ์ฅํ๋ฉด ๋๋ค. </div><div class="line"> firstName: inputFirstName,</div><div class="line"> lastName: inputLastName</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure>
<p>๋ง์ง๋ง์ผ๋ก <code>Meteor.call('register', inputUser, function (err) {})</code> ๋ register๋ผ๋ ๋ฉ์๋๋ฅผ ํธ์ถํด ์ค์ ํ์์ ๋ณด๋ฅผ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฃ๋ ์์
์ ํ๊ฒ ๋ฉ๋๋ค. </p>
<p>์ฐธ๊ณ ๋ก meteors๋ ์๋์ ๊ฐ์ด method๋ฅผ ๋ง๋ค๊ณ , ์ด๋ฅผ <code>Meteor.call('๋ฉ์๋ ์ด๋ฆ')</code> ์ด์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ํธ์ถํด์ ์ฌ์ฉํ ์ ์์ต๋๋ค. </p>
<ul>
<li><code>method ์์ฑ</code></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">Meteor.methods({</div><div class="line"></div><div class="line"> method์ด๋ฆ: function(data) </div><div class="line"> {</div><div class="line"></div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>๋ง๋ค์ด์ง method๋ ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ๋ถ๋ฌ์ ์ฌ์ฉํ ์ ์์ต๋๋ค. </p>
<ul>
<li><code>method ํธ์ถ</code></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">Meteor.call('method์ด๋ฆ', ๋๊ฒจ์ค๊ฐ์ฒด๋ฌถ์, function (err) {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> // ์ฑ๊ณต </div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> // ์คํจ</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>์ด์ ์์ register.js ์์ ํธ์ถํ๋ ๋ฉ์๋ <code>register</code>๋ฅผ ์๋์ ๊ฐ์ด ๋ง๋ค์ด ์์ฑํด ์ฃผ์ธ์. ์ฐธ๊ณ ๋ก ํด๋น ๋ฉ์๋๋ serverํด๋ ์๋์ accounts.js์์ ์์ฑ์ด ๋๋ฉฐ, ์ค์ ๋ก๋ ์๋ฒ์์ ์คํ์ด ๋๋ ์ฝ๋๊ฐ ๋๊ฒ ์ต๋๋ค. </p>
<p><code>server/accounts.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line">Meteor.methods({</div><div class="line"></div><div class="line"> register: function(inputUser) // ์๋ฒ์ธก์์ ํ์๊ฐ์
์คํ์ ์ฌ์ฉ๋จ.</div><div class="line"> {</div><div class="line"> var userEmail = inputUser.email;</div><div class="line"> var userPassword = inputUser.password;</div><div class="line"> var userPasswordAgain = inputUser.passwordAgain;</div><div class="line"> var userFirstName = inputUser.profile.firstName;</div><div class="line"> var userLastName = inputUser.profile.lastName;</div><div class="line"> </div><div class="line"> </div><div class="line"> // ํ์๊ฐ์
์์</div><div class="line"> try</div><div class="line"> {</div><div class="line"> Accounts.createUser({</div><div class="line"> username: userEmail,</div><div class="line"> email: userEmail,</div><div class="line"> password: userPassword,</div><div class="line"> profile: {</div><div class="line"> serviceType: 'site',</div><div class="line"> firstName: userFirstName,</div><div class="line"> lastName: userLastName,</div><div class="line"> gender: ''</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div><div class="line"> catch (err)</div><div class="line"> {</div><div class="line"> throw err;</div><div class="line"> }</div><div class="line"> </div><div class="line">});</div></pre></td></tr></table></figure>
<p>๊ทธ๋ฆฌ๊ณ ์ด์ ํ์๊ฐ์
์ ์ํด ์๋์ ํจํค์ง๋ฅผ ์ค์นํด ์ฃผ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง</p>
<ul>
<li>meteor add accounts-password</li>
</ul>
</blockquote>
<p>์ด์ <code>http://localhost:3000/register</code> ํ์ด์ง๋ก ๊ฐ์ ์ค๋ฅ ์์ด ํ์ ๊ฐ์
์ด ์๋ฃ๋๋ฉด, <code>FlowRouter.go('/');</code> ์ด ๋ช
๋ น์ด๋ฅผ ํ๊ณ , ์ฒ์ ํ์ด์ง๋ก ์ด๋ํ๊ฒ ๋ฉ๋๋ค. </p>
<p>์ฌ๊ธฐ์ ์ผ๋ฐ ์น๊ฐ๋ฐ์๋ผ๋ฉด ๋นํฉ์ค๋ฌ์ด ๋ถ๋ถ์ด ๋ฐ์ํ ์ ์๋๋ฐ์. ํ์ฌ๊น์ง ์ฐ๋ฆฌ๋ ๋ฑํ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์คํค๋ง ์ ์๋ ํ์ง ์์๊ณ , ์
๋ ฅ์ํ ํ๋ก์์ ๋ฅผ ๋ง๋ค๊ฑฐ๋, ์๋๋ฉด ์ง์ ์ฟผ๋ฆฌ๋ฅผ ์๋์ผ๋ก ์
๋ ฅํ์ง๋ ์์์ง๋ง, ๊ฐ์
์ด ์๋ฃ๋๊ณ ์ฌ์ง์ด ๋ก๊ทธ์ธ์ด ๋์๋ค๋ ๊ฒ์ ๋ฏฟ๊ธฐ ํ๋ค ์๋ ์์ต๋๋ค. meteor๊ฐ ์์ฐ์ฑ ์์ฐ์ฑ ํ๋๋ฐ๋ ๋ฐ๋ก ์ด๋ฐ ๋ถ๋ถ์์ ์ ์ ์์ต๋๋ค. ^^</p>
<p>๋ชฝ๊ณ ๋๋น์ ์ ์ํด ์ค์ ํ
์ด๋ธ์ด ์์ฑ๋์๊ณ , ๊ฐ์ฒด๊ฐ ๋ค์ด๊ฐ ์๋ ๊ฒ์ ๋ณด๋ ๋ฐฉ๋ฒ์ ๊ฐ๋จํ ์ค๋ช
๋๋ฆฌ๊ฒ ์ต๋๋ค. meteor๋ฅผ ์คํ์ํจ ์ํ์์ Robomongo๋ผ๋ ๋ชฝ๊ณ ๋๋น ํด๋ผ์ด์ธํธ ํด์ ์ด์ฉํด <code>localhost:3001</code> ๋ก ์ ์ํ๋ฉด ์๋์ ๊ฐ์ด meteor๋ผ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ user๋ผ๋ collection(RDBMS์ ํ
์ด๋ธ์ ํด๋น)์ด ์๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/7i-lbX36odDbL-6dVILHCSMXfGEgckkkGwCRsV9fkYQ4D1oVXoW3II4R63MPZbV1taQEugdmHwFRkEAMTtvQH55Fl4q_CVA-_NQ0E51IoeDPukJiLebh3JqkRhNVYm3JEwrxM2e5OxoKPAxgD1OCaqg6JIDByJfHvU9mmurkrI1rJSsS8vBIm-j1mDrlb4ShsgoEQzKwkQeS8lJtzG-uJMHcVbat6963P1jd9l8aycSMkEGgtK4kbEpNYjLEF4rUm5p-OYOAl9VbR08OxQR7r23N2J9p5UCRvSUau3QOE-uWkQaPaWTb4lPVIP5hZCFp4h8KG9_k5K6ExFDi4cos5eJ1ib8fOvbjb-ZAeIM927WIorDDnnhOSw7ADPrKuouJgr6Xu6wjGCpwq5YRNYBz2rfo8mO1Nhwa9j7IHlHRqoOXMUloIoB_AL6gqybOZWHPMF0pZgkUpL1DPgwNbEqwYxdLexycqycprD-sGMfZsDsf5MLlWzoLY2RotsMJniaP2Ymkep4VW-j1G71SwtAbjIULpOn1342MNy1xwPocnMzgGdW2eh_Vso2YtsFCPkp5xdzl7_g-XCtpxURGKFJt3pcOm3Xf3MWQaq-fUVRYk_spoQedXuIFvpAsuTfr_pBCz5Y_2q14mpyfSjC7jSZd8BdtY8yBzP2vBtfyQnV-BpQ=w718-h448-no"></p><p style="text-align: center;">[๋ชฝ๊ณ ๋๋น ๋ก๊ทธ์ธ ๋ถ๋ถ ์ฆ๋ช
]</p><p></p>
<p>๋ฏธํฐ์ด๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชฝ๊ณ ๋๋น๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ ์ด ๋ชฝ๊ณ ๋๋น๋ nosql ๋ฐ์ดํฐ ๋ฒ ์ด์ค๋ก ์ผ์ข
์ ํ
์คํธ ๊ธฐ๋ฐ์ ๋ฐ์ดํฐ ๋ฒ ์ด์ค๊ฐ ๋๊ฒ ์ต๋๋ค. ๋ชฝ๊ณ ๋๋น๋ ๋ฑํ ์คํค๋ง ์ ์๋ฅผ ํ์ง ์๊ณ , jsonํํ์ ๊ตฌ์กฐ๋ฅผ ์ฝ๊ณ , ์ฐ๊ณ , ์์ ํ๋ ๋ฐฉ๋ฒ์ผ๋ก ์ฌ์ฉํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์
๋๋ค. ์ฌ๊ธฐ์ ์ด๋ถ๋ถ๊น์ง ์์ธํ ์ค๋ช
์ ์ข ํ๋ค๊ฒ ์ง๋ง, <code>Accounts.createUser</code> Meteor์์ ์ด api๋ฅผ ํธ์ถํ๋ ๊ฒ์ผ๋ก ์ ์ ๊ฐ ์ ์ฅ๋๋ค๊ณ ์ผ๋จ ์ดํดํ์๋ฉด ๋๊ฒ ์ต๋๋ค. ^^</p>
<hr>
<h4 id="4-2-๋ก๊ทธ์ธ"><a href="#4-2-๋ก๊ทธ์ธ" class="headerlink" title="4.2 ๋ก๊ทธ์ธ"></a>4.2 ๋ก๊ทธ์ธ</h4><p>ํ์๊ฐ์
์ ๊ตฌํํ์ผ๋ ์ด์ด์ ๋ก๊ทธ์ธ ๋ฐ ๋ก๊ทธ์ธ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ๋ถ๋ถ์ ๋ง๋ค์ด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.</p>
<p><code>client/login.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">Template.login.events({</div><div class="line"> 'click button[name=btn-singIn]' (evt, tmpl)</div><div class="line"> {</div><div class="line"> evt.preventDefault();</div><div class="line"></div><div class="line"> var inputEmail = tmpl.find('input[name=user-email]').value;</div><div class="line"> var inputPwd = tmpl.find('input[name=user-pwasword]').value;</div><div class="line"></div><div class="line"> Meteor.loginWithPassword(inputEmail, inputPwd, function(err) </div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line"> return false;</div><div class="line"></div><div class="line"> }</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure></p>
<p>์์ค์์ ์ฌ์ฉ๋ <code>Meteor.loginWithPassword()</code>๋ meteor์์ ์ ๊ณตํ๋ ๊ธฐ๋ณธ ๋ก๊ทธ์ธ api ์
๋๋ค. </p>
<p>๋ค์์ผ๋ก ๋ก๊ทธ์ธ์ด ๋๋ฉด ํํ๋ฉด์์ ๋ก๊ทธ์ธ ์ ๋ณด๊ฐ ๋์ค๋๋ก ์ฒซํ๋ฉด์ ๋ฐ๊ฟ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p><code>client/home.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div></pre></td><td class="code"><pre><div class="line"><template name="home"></div><div class="line"> {{#unless loggingIn}}</div><div class="line"> {{#if currentUser}}</div><div class="line"> {{> userInfo}}</div><div class="line"> {{else}}</div><div class="line"> {{> defaultHome}}</div><div class="line"> {{/if}}</div><div class="line"> {{/unless}}</div><div class="line"></template></div><div class="line"></div><div class="line"><template name="defaultHome"></div><div class="line"> <div class="col-md-8 col-md-offset-2"></div><div class="line"> <div class="col-md-12"></div><div class="line"> <div class="col-md-12"></div><div class="line"> <h2>ํ์ํฉ๋๋ค.</h2></div><div class="line"> <hr/></div><div class="line"> </div></div><div class="line"> <div class="col-md-6"></div><div class="line"> <a href="{{pathFor 'login'}}" class="btn btn-primary btn-lg btn-block">Go Login</a></div><div class="line"> </div></div><div class="line"> <div class="col-md-6"></div><div class="line"> <a href="{{pathFor 'register'}}" class="btn btn-success btn-lg btn-block">Go Register</a></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></template></div><div class="line"></div><div class="line"><template name="userInfo"></div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <h2>METEOR ACCOUNTS</h2></div><div class="line"> <p>๊ฐ์
์ ์ ์ ๋ณด</p></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"></div><div class="line"> <div class="col-xs-12 panel-body-inner-box-3"></div><div class="line"> <p>Email: {{currentUser.username}} </p></div><div class="line"> <hr/></div><div class="line"> <p>First Name: {{currentUser.profile.firstName}} </p></div><div class="line"> <hr/></div><div class="line"> <p>Last Name: {{currentUser.profile.lastName}} </p></div><div class="line"> <hr/></div><div class="line"> </div></div><div class="line"></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="btn-logout" class="btn btn-danger btn-lg btn-block button">๋ก๊ทธ์์</button></div><div class="line"> <a href="{{pathFor 'changePassword'}}" class="a-right" >๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</a></div><div class="line"> </div></div><div class="line"></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๋ณ๊ฒฝ๋ home.html ์์ค๋ฅผ ์ค๋ช
๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค.<br>์ผ๋จ ๋จ์ผ ํ
ํ๋ฆฟ์ home, defalutHome, userInfo ์ ์ธ๊ฐ์ง ํ
ํ๋ฆฟ์ผ๋ก ๋ถ๋ฆฌํ์ต๋๋ค.<br><code>#if currentUser</code> ์ด ๋ถ๋ถ์ meteor์์ ๋ก๊ทธ์ธ ์ํ๋ฅผ ํ์ธํ ๋ ์ฌ์ฉํ๋ API์
๋๋ค. ๋ก๊ทธ์ธ์ด ๋์ด์์ผ๋ฉด ์ด ์กฐ๊ฑด์ ์ ํ๊ณ <code>> userInfo</code> ํ
ํ๋ฆฟ์ ํธ์ถํ์ฌ ๋ณด์ฌ์ฃผ๊ณ , ๋ก๊ทธ ์์ ์ํ ์ผ ๋๋ else ์กฐ๊ฑด์ ์ ๋ฐ๋ผ > defaultHome ์ ๋ณด์ฌ์ฃผ๋๋ก ์ค์ ํ ์์ค์
๋๋ค. </p>
<p>๊ทธ๋ฆฌ๊ณ userInfo ํ
ํ๋ฆฟ์ ๋ณด๋ฉด ์์๊ฒ ์ง๋ง, ๋ก๊ทธ์ธ ์ ๋ณด๋ currentUser๊ฐ์ฒด๋ก ๊ฐ์ข
์ ๋ณด๋ฅผ ๋ฐ์์ ํ์ ํ ์ ์์ต๋๋ค. </p>
<p>์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ์ด ๋๋ฉด ์ฒซํ๋ฉด์ด ๋ค์๊ณผ ๊ฐ์ด ๋์ค๊ฒ ๋ฉ๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/7YOzghuxYM9s60j7i3nvuP0-iJ646ZQOM3pcaZv3tRtVlajh0Puikz7iR3SK3hP_XN5ZO-LE0vrdYCsLG3hOM2R1SQ_Ed-_DUVMBwsgDpVl05UVfEgUuG6XbtsyMDhjlm3d-HvV3MIrhlAUHq3EsnZlvSDrCmF-MuPX2x7BIsAhuxDvnx5E0tGxOgkX203cyByk4t9JuGWf2R0EXnvD09nhOIyhhQleeB5Q0flv8sTyQC45w-S1IF9AfKjXfMRm6D1SMVNiZ0LXu0o0QfS7UZDtbqoeI1-Rl6q4EVFYvYy-q4f1N9MRZQfCKhfb_GviNkpXppULngziE-6n9rdYQb0me5YKsPx57WUgmnEV8IPPwfnMjkJm6oK6qnMvMUtLg63oyqOiVaWv72fBRrKjCOYulM8Mz7REGGW5MPgS2ILU3RlUQj0_HtEsJFA6LYlx6YR8RX5zOjp1F1OWZ4KW_NjDFGBmP2ogQKKz38XRD1sPZuiJtZEWtcas2nr3quLEGElmBwyJfDqyKbJvvQ3Mgmg-bKTU4K_WUIddaXQ0Lp2-keIuja9kQ4n6SgJldQcMkylmpEDZDiLXPS3Iso2VqqG-9iTrMEY5WyB_GhutJQze-jVUcpgRG0VvfqKMHmw5XcLQwZsG67KaoVgjTW4cAH5epD81UsYtF0e9x341F_8s=w627-h477-no"></p><p style="text-align: center;">[๋ก๊ทธ์ธ ํ ์ฒซํ๋ฉด]</p><p></p>
<p>์ฐธ๊ณ ๋ก ์ฌ๊ธฐ์ <code>#if currentUser</code> ๋ง ์ฌ์ฉํด๋ ๋์ง๋ง ์ด ์์ค ์์ <code>#unless loggingIn</code> ๋ก ๊ฐ์ธ์ค ์ด์ ๋ ํ์ด์ง๊ฐ ์๋ก ์์๋ ๋ 1์ด ์ ๋ currentUser๊ฐ ์๋ํ์ง ์๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด ํ์ ๋๋ฌธ์ defaultHome ํฌํ๋ฆฟ์ด ์์ฃผ ์ ๊น ๋ณด์ด๊ณ userInfo๋ก ๊ฐ๋ ์์ฑ ํ์์ด ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค. ์ด ์์ ํ์์ ๋ฐฉ์ง ํ๊ธฐ์ํ ์ผ์ข
์ ํต? ์ด <code>#unless loggingIn</code> ๋ก ๊ฐ์ธ์ฃผ๋ ๋ฐฉ๋ฒ์
๋๋ค. </p>
<hr>
<h4 id="4-3-์ ํจ์ฑ๊ฒ์ฌ-validate-์ถ๊ฐ"><a href="#4-3-์ ํจ์ฑ๊ฒ์ฌ-validate-์ถ๊ฐ" class="headerlink" title="4.3 ์ ํจ์ฑ๊ฒ์ฌ(validate) ์ถ๊ฐ"></a>4.3 ์ ํจ์ฑ๊ฒ์ฌ(validate) ์ถ๊ฐ</h4><p>ํ์ ๊ฐ์
์ด ๋์์ง๋ง, ์์ง ๋ถ์กฑํ ๋ถ๋ถ์ด ๋ง์ต๋๋ค. ์ด์ ํ๋์ฉ ๊ธฐ๋ฅ์ ๋ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์ฐ์ ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์ถ๊ฐํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>์ผ๋จ ์๋ ํจํค์ง๋ฅผ ์ค์นํด์ฃผ์ธ์. ํด๋น ํจํค์ง๋ ์ ํจ์ฑ๊ฒ์ฌ์ ์ง์ ์ ์ธ ๊ด๊ณ๋ ์์ง๋ง, ๊ฒฝ๊ณ ๋ฌธ์ ๋จ์ํ ์๋ฐ์คํฌ๋ฆฝํฐ alert ๋ฌธ์ ์ฐ๋ฉด ์ข ํ์ ํด(?) ๋ณด์ด๋ ๊ฒ์ ๊ฐ์ ํ๊ธฐ ์ํด ์ฌ์ฉํ ๊ณ ๊ธ์ง? alert ํจ๊ณผ ํจํค์ง ๋ผ๊ณ ๋ณด์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง</p>
<ul>
<li>meteor add themeteorchef:bert</li>
</ul>
</blockquote>
<p>bert ํจํค์ง์ ์ฌ์ฉ๋ฒ์ ์๋์ ๊ฐ์ด ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค. ๋ณด์๋ฉด ์๋นํ ์ฌํํ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฒ์ ์ ์ ์๋๋ฐ์. ํ์
๊ณผ ์ถ๋ ฅํํ๋ง ๋ฉ์ง์ง์ ์ฑ๊ฒฉ์ด๋ ๋์์ธ์ ๋ง๊ฒ ์ค์ ํด์ ๋ฐ๋ก ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Bert.alert( '๋ฉ์์ง', 'ํ์
(ex: success)', '์ถ๋ ฅํํ(ex: growl-top-right)' );</div></pre></td></tr></table></figure>
<blockquote>
<p>Bert์ ๋ํด ์ข ๋ ์์ธํ ์๊ณ ์ถ์ ๋ถ์ ์๋ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ์ธ์.<br><a href="https://themeteorchef.com/tutorials/client-side-alerts-with-bert" target="_blank" rel="noopener">https://themeteorchef.com/tutorials/client-side-alerts-with-bert</a></p>
</blockquote>
<p>๋ค์์ผ๋ก <code>checkPattern.js</code>ํ์ผ์ ๋ง๋ค๊ณ , ์๋ ์์ค๋ฅผ ์
๋ ฅํ์ธ์.<br>checkPattern.js์ ๊ฒฝ์ฐ ํด๋ผ์ด ์ธํธ๋ ์๋ฒ ๋ชจ๋์์ ์ฌ์ฉํ ๊ฒฝ์ฐ๊ฐ ์์ผ๋ฏ๋ก lib ํด๋์ ์์ฑํ๋๋ก ํ๊ฒ ์ต๋๋ค. ํ๊ฐ์ง ์ฃผ์ ํ ์ ์ ์ฌ๊ธฐ์ ์์ค๋ ๊ผญ ํจ์๋ช
์์ var๋ฅผ ์จ์๋ ์๋ฉ๋๋ค. ์ด๋ถ๋ถ๊ณผ ์ ๊ท์ ๋ถ๋ถ์ ์ ๋น๊ตํด์ ์ฌ์ฉํ์๋ฉด ๋๊ฒ ์ต๋๋ค. </p>
<p><code>lib/checkPattern.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div></pre></td><td class="code"><pre><div class="line">// ํ์ ์
๋ ฅ์ฌํญ ์ฒดํฌ</div><div class="line">NotEmptyString = function (value)</div><div class="line">{</div><div class="line"> if(value.length > 0)</div><div class="line"> {</div><div class="line"> return true</div><div class="line"> }</div><div class="line"> throw new Meteor.Error(403, 'ํ์ ์ฌํญ์ ์
๋ ฅํด์ฃผ์ธ์.');</div><div class="line">}</div><div class="line"></div><div class="line">// ์ด๋ฉ์ผ ํ์ ์ฒดํฌ </div><div class="line">isEmail = function (value)</div><div class="line">{</div><div class="line"> var filter = /^([0-9a-zA-Z_\.-]+)@([0-9a-zA-Z_-]+)(\.[0-9a-zA-Z_-]+){1,2}$/;</div><div class="line"> if(filter.test(value))</div><div class="line"> {</div><div class="line"> return true;</div><div class="line"> }</div><div class="line"> throw new Meteor.Error(403, '์ด๋ฉ์ผ ํ์์ด ๋ฐ๋ฅด์ง ์์ต๋๋ค ');</div><div class="line">}</div><div class="line"></div><div class="line">// ํจ์ค์๋ 6์๋ฆฌ ์ด์ ์ฒดํฌ</div><div class="line">isValidPassword = function (password)</div><div class="line">{</div><div class="line"> if(password.length >= 6)</div><div class="line"> {</div><div class="line"> return true;</div><div class="line"> }</div><div class="line"> throw new Meteor.Error(403, '๋น๋ฐ๋ฒํธ๋ 6์๋ฆฌ ์ด์์ด์ฌ์ผ ํฉ๋๋ค.');</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line">// ํจ์ค์๋, ํจ์ค์๋ ํ์ธ ์ผ์น ์ฒดํฌ</div><div class="line">isMatchPassword = function (password, passwordAgain)</div><div class="line">{</div><div class="line"> if(password === passwordAgain)</div><div class="line"> {</div><div class="line"> return true;</div><div class="line"> }</div><div class="line"> throw new Meteor.Error(403, '๋น๋ฐ๋ฒํธ์ ๋น๋ฐ๋ฒํธ ํ์ธ์ด ๋ค๋ฆ
๋๋ค.');</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line">// ์ ํ๋ฒํธ : "000-0000-0000"</div><div class="line">isPhone = function(value)</div><div class="line">{</div><div class="line"> var filter = /^\d{3}-\d{3,4}-\d{4}$/;</div><div class="line"> if(filter.test(value))</div><div class="line"> {</div><div class="line"> return true;</div><div class="line"> }</div><div class="line"> throw new Meteor.Error(403, '์ ํ๋ฒํธ ํ์์ด ๋ฐ๋ฅด์ง ์์ต๋๋ค ');</div><div class="line">}</div><div class="line"></div><div class="line">// ํน์ ๋ ์ง ํ์ : "yyyy/mm/dd"</div><div class="line">isBirthDay = function (value)</div><div class="line">{</div><div class="line"> var filter = /^(19[0-9][0-9]|20\d{2})\/(0[0-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])$/;</div><div class="line"> if(filter.test(value))</div><div class="line"> {</div><div class="line"> return true;</div><div class="line"> }</div><div class="line"> throw new Meteor.Error(403, '๋ ์ง ํ์์ด ๋ฐ๋ฅด์ง ์์ต๋๋ค ');</div><div class="line">}</div></pre></td></tr></table></figure></p>
<p>์ ์์ค๋ค์ ํ์์ ๊ฐ๊ฐ ๋น์ทํ๋ค๋ ๊ฒ์ ๊ธ๋ฐฉ ์ ์ ์์ ๊ฒ์
๋๋ค. ์ฐ์ฐ์๋ก ๋์ด์จ ๊ฐ์ ์ ๊ท์์ผ๋ก ๋น๊ตํ๊ณ ์ด ๊ฐ์ ์ค๋ฅ๊ฐ ์์ผ๋ฉด throw๋ฅผ ํตํด ์ค๋ฅ๋ฅผ ๋์ ธ์ฃผ๋ ๊ตฌ์กฐ์
๋๋ค. </p>
<p>๊ทธ๋ฆฌ๊ณ accounts.js์์ ์๋ ์์ค๋ฅผ ์ฐธ๊ณ ๋ก ์ถ๊ฐํด์ฃผ์๋ฉด ๋๊ฒ ์ต๋๋ค. (ํ์๊ฐ์
์
๋ ฅ๊ฐ ๊ฒ์ฆ ๋ถ๋ถ๋ง ๋ฃ์ด์ฃผ์ธ์)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line">[์ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> var userFirstName = inputUser.profile.firstName;</div><div class="line"> var userLastName = inputUser.profile.lastName;</div><div class="line"> </div><div class="line"> </div><div class="line"> </div><div class="line"> // ํ์๊ฐ์
์
๋ ฅ๊ฐ ๊ฒ์ฆ ์์</div><div class="line"> try</div><div class="line"> {</div><div class="line"> NotEmptyString(userEmail);</div><div class="line"> NotEmptyString(userPassword);</div><div class="line"> NotEmptyString(userPasswordAgain);</div><div class="line"> NotEmptyString(userFirstName);</div><div class="line"> NotEmptyString(userLastName);</div><div class="line"> isEmail(userEmail);</div><div class="line"> isValidPassword(userPassword);</div><div class="line"> isMatchPassword(userPassword, userPasswordAgain);</div><div class="line"> }</div><div class="line"> catch (err)</div><div class="line"> {</div><div class="line"> throw err;</div><div class="line"> }</div><div class="line"> // ํ์๊ฐ์
์
๋ ฅ๊ฐ ๊ฒ์ฆ ์ข
๋ฃ</div><div class="line"> </div><div class="line"> </div><div class="line"> // ํ์๊ฐ์
์์</div><div class="line"> try</div><div class="line"> {</div><div class="line"> Accounts.createUser({</div><div class="line"> username: userEmail,</div><div class="line"> email: userEmail,</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์๋ ์๋ต]</div></pre></td></tr></table></figure>
<p>์์ค์ ๋ํด ์ค๋ช
์ ์กฐ๊ธ ํ๋ฉด, ๊ธฐ๋ณธ์ ์ผ๋ก try,catch๋ฌธ์ ๋ง๋ค๊ณ try ์์ ๋ฏธ๋ฆฌ ์์ฑํด๋ ๊ฒ์ฆ๋ฌธ๊ณผ ์ด ๊ฒ์ฆ๋ฌธ์ ์ด๋ค input๊ฐ์ ๋์ํ๊ฒ ํ ์ง๋ฅผ ์ ํ๋ ๊ณผ์ ์
๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">try</div><div class="line">{</div><div class="line"> ๊ฒ์ฆ๊ตฌ๋ฌธ</div><div class="line">}</div><div class="line">catch(err)</div><div class="line">{</div><div class="line"> ์ค๋ฅ ๋ฐ์์ ๋ฉ์์ง ๋ฐ์</div><div class="line">}</div></pre></td></tr></table></figure>
<p>์ด์ ์์ ๊ฐ๋ค์ ๋ค ๋ฉ์นญํด ์ฃผ์
จ์ผ๋ฉด, ํ
์คํธ๋ฅผ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.<br>์ผ๋จ ๋ชจ๋ ๊ฐ์ ๋ฌด์กฐ๊ฑด ์
๋ ฅํด์ผ ํ๋ฏ๋ก, NotEmptyString๋ฅผ ์ฌ์ฉํด๊ณ , ์ด๋ฉ์ผ์ ์ด๋ฉ์ผ ํ์์ด ์์ผ๋ฉด, <code>isEamil</code>์ ์ฌ์ฉํด๊ณ , ํจ์๋๋ ๊ธฐ๋ณธ ๊ธธ์ด์, ํจ์ค์๋&ํจ์ค์๋ํ์ธ์ด ๊ฐ์์ง๋ฅผ ์ฒดํฌํ๋ ๋ถ๋ถ์ ์ถ๊ฐํด์ต๋๋ค. </p>
<p>์ด์ localhost:3000/register ๋ฅผ ์คํ์์ผ ๋ณด๊ณ , ๊ฒ์ฆ์ด ์ ์งํ๋๋ ํ์ธํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ๋ง์ฝ ๊ฒ์ฆ๋ถ๋ถ์ด ์ ์์ ์ผ๋ก ์
๋ ฅ๋์๋ค๋ฉด, ์๋ฌด๊ฒ๋ ์
๋ ฅํ์ง ์๊ฑฐ๋,์ด๋ฉ์ผ ํ์์ด ํ๋ฆฌ๋ ๋ฌธ์ ๋ฑ์ด ๋ฐ์์, ์๋์ ๊ฐ์ด ๊ฒฝ๊ณ ์ฐฝ์ด ๋จ๊ณ ๋์ด์ ์งํ์ด ์๋๋ ์ํ๊ฐ ๋ฉ๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/HjMmkYqb3WroN_ImSg6Qu9icIhmO8JyPNm7-v71VG0L-Fz2g9F6Ew0BeBNEed3HdXHWlpeD4TmpVJs-9nDKRaNs3lwVvY3TKg87JphA1OvtaP_XCOg-W7s1pVbyOqaZjGGAvQIpA0-4h9xVyj1PGLM-7eUCREyGhSUDfEFLp2dVTAZO5vOFZfZMWXVVw8xNt4FBupFTeV2ugdukwCtzmQrN_8OqqdtdsTcp2VmBYni_eO_O8Eftl6a2_CcO_lvwCj2aNWEfgwUyW3ULmSrwg4qHYQYWmpt4IHbgPNF7lecVx00tmvCq2-JqLpr6KxP-c_EmIMULJH7lWF881G53quswBgUUSeTT72P71rEIQQJqcFF8fHLAFOMcmn55ZvQz2et1pzMKh9-xpsH3aDZoLyYRTlKKW9rybFikEBbUBdqbFh3ahb-6jtn3BrJkPY1jO-SyA7kmXxakFHgE1qV5Hdu__OEMimq5fg3015iaP3S9_5o8aGuCxd-E60bEp5txXUBjZpD9CoLHXKNByOqUk2FqhhPg7us1HuTpGVaH5LlqDSxQPJgUCHZaWKlzJ3ay-90kHB96M5bNQEpehAro40dUyFfUxYGh3yeIM3nsHR9nuXcPDh_qcWfzhAk0O-yw9UG5tQwJM_1vQba0bTffmF9yWcqJ-r-zPVYTWZUcD_Nw=w1087-h746-no"></p>
<p>์ด ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ธฐ์กด ๋ก๊ทธ์ธ ํ๋ฉด๋ ๊ฒ์ฆ ๋ฐ ๊ฒฝ๊ณ ์ฐฝ์ ์ถ๊ฐํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ์๋ ์์ค๋ฅผ ๋ฐํ์ผ๋ก <code>๊ฒ์ฆ์ถ๊ฐ</code> ๋ถ๋ถ์ ์ถ๊ฐํด์ฃผ์ธ์.</p>
<p><code>client/login.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line">[์ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> var inputEmail = tmpl.find('input[name=user-email]').value;</div><div class="line"> var inputPwd = tmpl.find('input[name=user-pwasword]').value;</div><div class="line"> </div><div class="line"> // ๊ฒ์ฆ์ถ๊ฐ ์์</div><div class="line"> try</div><div class="line"> {</div><div class="line"> NotEmptyString(inputEmail);</div><div class="line"> NotEmptyString(inputPwd);</div><div class="line"> }</div><div class="line"> catch(err)</div><div class="line"> {</div><div class="line"> console.log(err);</div><div class="line"> //Bert.alert( err.message , 'danger', 'growl-top-right' );</div><div class="line"></div><div class="line"> return;</div><div class="line"> }</div><div class="line"> // ๊ฒ์ฆ์ถ๊ฐ ์ข
๋ฃ </div><div class="line"> </div><div class="line"> Meteor.loginWithPassword(inputEmail, inputPwd, function(err) </div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> }</div><div class="line"> .</div><div class="line"> .</div><div class="line"> .</div><div class="line"> [์๋ ์๋ต]</div></pre></td></tr></table></figure>
<p>ํ์๊ฐ์
๊ณผ ๋ก๊ทธ์ธ์์์ <code>์ ํจ์ฑ๊ฒ์ฌ</code>์์ ๋ค๋ฅธ ์ ์ด ์์ต๋๋ค. ๋ฐ๋ก ํ์๊ฐ์
์ ์๋ฒ์ชฝ์์ ๊ฒ์ฌ์ ํ๊ณ , ๋ก๊ทธ์ธ ํ์ด์ง๋ ํด๋ผ์ด์ธํธ์์ ์คํ๋๋๋ก ํ๊ฒ์
๋๋ค. ์ฆ <code>์ ํจ์ฑ๊ฒ์ฌ</code>๋ ์๋ฒ๋ ํด๋ผ์ด์ธํธ ์ด๋์๋ ์ฌ์ฉํ ์ ์๋ค๋ ์๊ธฐ๊ฐ ๋ฉ๋๋ค. ์ํฉ์ ๋ฐ๋ผ ์ฌ์ฉํ ์ ์๊ณ , ์์ฃผ ์ค์ํ ๋ด์ฉ์ด๋ผ๋ฉด, ์๋ฒ&ํด๋ผ์ด์ธํธ ๋ชจ๋์์ ์ ํจ์ฑ๊ฒ์ฌ๋ฅผ ํ ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ๋ ๊ฒฝ์ฐ ๋ชจ๋ <code>lib/checkPattren.js</code> ๋ฅผ ์ฐธ์กฐํด์ ์ด์ฉํ ์ ์๋ค๋ ์ ์ด Meteor์ ๋งค๋ ฅ์ค ํ๋๊ฐ ์๋๊น ์๊ฐํฉ๋๋ค. ^^ </p>
<hr>
<h4 id="4-4-์ด๋ฉ์ผ-์ธ์ฆ"><a href="#4-4-์ด๋ฉ์ผ-์ธ์ฆ" class="headerlink" title="4.4 ์ด๋ฉ์ผ ์ธ์ฆ"></a>4.4 ์ด๋ฉ์ผ ์ธ์ฆ</h4><p>๊ฐ์
์ ์๋๊ฐ์
๋ฑ์ ๋ง๋ ๋ฐฉ๋ฒ์ผ๋ก ๋ง์ด ์ฌ์ฉ๋๋ ๋ฐฉ๋ฒ์ผ๋ก ์ด๋ฉ์ผ ์ธ์ฆ์ด ์์ ๊ฒ์
๋๋ค. Meteor๋ ์ด์ ํ์ํ API๋ฅผ ๋๋ฆ ์ ์ ๊ณตํ๊ณ ์์ต๋๋ค.</p>
<p>์ฐ์ ์ฒซ๋ฒ์งธ๋ก ํ ์ผ์ ์ธ์ฆ์์ ๋ณด๋ผ ๋ฉ์ผ์ ๋ํ ์ค์ ๋ถํฐ ํด๋ณด๊ฒ ์ต๋๋ค. ๋ค์ ์์ค๋ฅผ ํด๋น๊ฒฝ๋ก์ ํ์ผ์ ๋ง๋ค๊ณ ์
๋ ฅํด์ฃผ์ธ์.</p>
<p><code>server/main.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">// Set up login services</div><div class="line">Meteor.startup(function() {</div><div class="line"></div><div class="line"> Accounts.config({</div><div class="line"> sendVerificationEmail: true</div><div class="line"> });</div><div class="line"></div><div class="line"> process.env.MAIL_URL="smtps://์ด๋ฉ์ผ์ฃผ์:ํจ์ค์๋@smtp.gmail.com:465/";</div><div class="line">});</div></pre></td></tr></table></figure>
<p>์ ์์ค์์<br><code>Meteor.startup</code> ์ ๊ฒฝ์ฐ meteor๊ฐ ์คํ๋ ๋ ์ด๊ธฐ์ ํ์ํ ์ธํ
๋ฑ์ ์คํ์ํค๋ ๋ถ๋ถ์ด ๋๊ฒ ์ต๋๋ค. ์ฌ๊ธฐ์๋ ๋ณด๋ด๋ ๋ฉ์ผ์ ๋ํ ์ ๋ณด(smtp ์ ๋ํ ์ ๋ณด)๋ฅผ ์
๋ ฅํด ์ฃผ์๋ฉด ๋๋๋ฐ smtp์ ๊ฒฝ์ฐ ๋ฉ์ผ ์๋น์ค ๋ง๋ค ์กฐ๊ธ ๋ค๋ฅธ ๋ถ๋ถ์ด ์ด์ ์ ์์ผ๋ ๊ผญ ์ฝ๋ ฅํ๊ธฐ ์ ์ ํด๋น smtp ์๋น์ค์ ์
๋ ฅ๋ฐฉ๋ฒ์ ํ์ธํด์ฃผ์ธ์.<br>์ฐธ๊ณ ๋ก ํ์ฌ ๋ฒ์ (1.5)์์ gmail์ ๊ฒฝ์ฐ <code>smtp</code>๊ฐ ์๋ ์์ ๊ฐ์ด <code>smtps</code>๋ก ํด์ผ ๋ฉ์ผ์ด ์ ์์ ์ผ๋ก ๋ฐ์ก๋ฉ๋๋ค.<br>Accounts.config ๋ถ๋ถ์ <code>sendVerificationEmail: true</code> ๋ง ์ฃผ๋ฉด ๋ฉ์ผ๋ก ํ์ธ์ ํด์ผ๋ง ๊ฐ์
์น์ธ์ด ๋จ์ด์ง๋ ๊ตฌ์กฐ๊ฐ ๋๊ณ , ์๋์ผ๋ก ๋ฉ์ผ์ ๋ฐ์กํฉ๋๋ค. ํ์ง๋ง ๋ฉ์ผ์ ๊ฒฝ์ฐ ์์ด๋ก ๋ ๊ธฐ๋ณธ ๋ฉ์ผ์ด ๋ฐ์ก๋๋ฏ๋ก ์๋ ์์ค๋ฅผ ์ฐธ๊ณ ๋ก ์น์ ํ ํ๊ธ ๋ฉ์ผ์ ๋ง๋ค ์ ์์ต๋๋ค. ^^</p>
<p><code>server/accountsMails.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">// ๊ณตํต์ฌํญ</div><div class="line">Accounts.emailTemplates.siteName = "account sample";</div><div class="line">Accounts.emailTemplates.from = "admin <admin@gmail.com>"; // ๋ณด๋ด๋ ์ฃผ์ ์ ๋ณด</div><div class="line"></div><div class="line">// ๊ฐ์
ํ์ธ ๋ฉ์ผ</div><div class="line">Accounts.emailTemplates.verifyEmail = {</div><div class="line"> subject() {</div><div class="line"> return "Meteor accounts ๊ฐ์
ํ์ธ ๋ฉ์ผ";</div><div class="line"> },</div><div class="line"> text( user, url ) {</div><div class="line"></div><div class="line"> let emailAddress = user.username,</div><div class="line"> urlWithoutHash = url.replace( '#/', '' ),</div><div class="line"> supportEmail = "๋ฉ์ผ์์ด๋@gmail.com",</div><div class="line"> emailBody = `์ด๋ฉ์ผ ์ฃผ์๋ฅผ ํ์ธํ๋ ค๋ฉด (${emailAddress}) ๋ค์ ๋งํฌ๋ฅผ ๋ฐฉ๋ฌธํ์ญ์์ค. \n\n link: ${urlWithoutHash} \n\n ๋ง์ฝ ํ์ธ์ ์์ฒญํ์ง ์์ ๊ฒฝ์ฐ, ์ด ์ด๋ฉ์ผ์ ๋ฌด์ํ์ญ์์ค. ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐ๋๋ฉด ๋ค์ ์๋น์ค ์ง์ํ์ ๋ฌธ์ํ์ญ์์ค. \n\n ๋ฌธ์์ฃผ์ : ${supportEmail}.`;</div><div class="line"></div><div class="line"> console.log('mailUser');</div><div class="line"> console.log(user);</div><div class="line"></div><div class="line"> return emailBody;</div><div class="line"> }</div><div class="line">};</div></pre></td></tr></table></figure>
<p>์ ์์ค์์ ๊ณตํต๋ถ๋ถ์ ๊ฐ์
์ธ์ฆ ๋ง๊ณ ๋ ๋ฉ์ผ ๋ณด๋ด๋ ๋ค๋ฅธ ๋ฉ์ผ ์๋น์ค์์ ๊ณ์ํด์ ์ฌ์ฉํ๊ฒ ๋ ๋ถ๋ถ์ผ๋ก, ์ฌ์ดํธ๋ช
๊ณผ ๋ณด๋ด๋ ์ฌ๋์ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์ค์ ํ๋ ๋ถ๋ถ์
๋๋ค. </p>
<p>๋ค์์ผ๋ก ์ค์ ๊ฐ์
ํ์ธ ๋ฉ์ผ์ ๊ดํ ๋ถ๋ถ์ ์กฐ๊ธ ์ค๋ช
๋๋ฆฌ๊ฒ ์ต๋๋ค.<br><code>supportEmail=user.username</code>์ผ๋ก ์ธํ
๋ ์ด์ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก username์ email๋ก ์ธํ
ํ๊ธฐ ๋๋ฌธ์ด๋ค<br>emailBody๋ ๋ฉ์ผ ๋ด์ฉ์ ๊ดํ ๋ถ๋ถ์
๋๋ค. ์ ์ผ ์ค์ํ ๋ถ๋ถ์ <code>${urlWithoutHash}</code> ์
๋๋ค. ์ด ๋งํฌ๋ ์ผ์ข
์ ์ผํ์ฑ ํค๊ฐ์ผ๋ก ํด๋น ๋งํฌ๋ก ๋ฐฉ๋ฌธ์ ํด์ผ ๊ฐ์
์น์ธ์ด ํ์ฑํ ๋ฉ๋๋ค.</p>
<p>๋ค์์ ์ด๋ฐ ์ค์ ๋ฉ์ผ์ ๋ณด๋ด๋ method๋ฅผ ์ถ๊ฐํด๋ณด๊ฒ ์ต๋๋ค.<br>์๋ ์์ค๋ฅผ ์ฐธ๊ณ ๋ก <code>sendVerificationLink</code>(๊ฐ์
ํ์ธ ๋ฉ์ผ ๋ฐ์ก) ๋ฉ์๋๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.</p>
<p><code>server/accounts.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Meteor.methods({</div><div class="line"></div><div class="line"></div><div class="line"> register: function(data) // ์๋ฒ์ธก์์ ํ์๊ฐ์
์คํ์ ์ฌ์ฉ๋จ.</div><div class="line"> {</div><div class="line"></div><div class="line"> // ์๋ฒ์์ ํ๋ฒ ๋ ์
๋ ฅ๊ฐ ๊ฒ์ฆ์ ํด๋ ๋๋ค. ์๋๋ฉด ๋ชจ๋ ์
๋ ฅ๊ฐ ๊ฒ์ฆ์ ์๋ฒ๋ก ์ฎ๊ฒจ ์๋ ์๊ด์ ์๋ค.</div><div class="line"> try</div><div class="line"> {</div><div class="line"> NotEmptyString(data.username);</div><div class="line"> NotEmptyString(data.password);</div><div class="line"> isEmail(data.username);</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"> }</div><div class="line"> catch (err)</div><div class="line"> {</div><div class="line"> throw err;</div><div class="line"> }</div><div class="line"></div><div class="line"> },</div><div class="line"> // ๊ฐ์
ํ์ธ ๋ฉ์ผ ๋ฐ์ก</div><div class="line"> sendVerificationLink(user)</div><div class="line"> {</div><div class="line"> var userId = user;</div><div class="line"> if ( userId ) {</div><div class="line"> return Accounts.sendVerificationEmail( userId );</div><div class="line"> }</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure></p>
<p>์ด์ ๊ฐ์
์ด ์ด๋ฃจ์ด์ง ํ์ด๋ฐ์ <code>sendVerificationLink</code> ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ์์
์ ํด๋ณด๊ฒ ์ต๋๋ค. ๊ฐ์ <code>server/accounts.js</code>์ <code>Accounts.onCreateUser()</code>๋ผ๋ ์ผ์ข
์ ๋ผ์ดํ ์ฌ์ดํด API๋ฅผ ์ด์ฉํ๋ฉด ๋๊ฒ ๋๋ฐ์. ์ฆ createUser api๋ก ์ ์ ๊ฐ ์์ฑ๋ ๋ ์ด๋ค ์ผ๋ค์ ํจ๊ป ์ฒ๋ฆฌํ ์ง๋ฅผ ์ ํ๋ ํจ์๋ผ๊ณ ๋ณด๋ฉด ๋๊ฒ ์ต๋๋ค.<br><code>onCreateUser</code>๋ก ํด์ผํ๋ ์ผ์ user.profile์ ๋ฃ์ด์ค ๊ฐ ์ฑํฌ, ๋ฉ์ผ ๋ฐ์ก, ๊ทธ๋ฆฌ๊ณ ์ดํ์ ํ ์ธ๋ถ api(facebook, google ๋ฑ)๋ฅผ ์ด์ฉํ ๋ก๊ทธ์ธ ์ profile ์ฑํฌ ๋ง์ถ๋ ์์
๋ฑ์ด ์๊ฒ ์ต๋๋ค. ์๋ ์์ค๋ฅผ ์ฐธ๊ณ ๋ก accounts.js ํ์ผ์ ์์ฑํด์ฃผ์ธ์. ๋ค์ ํ๋ฒ ๋ง์๋๋ฆฌ์๋ฉด ํ์์ ๋ค์ํ ์ ๋ณด(์ฑ๋ณ, ์ฃผ์ ๋ฑ๋ฑ)๋ฅผ user.profile์ ๋ฃ์ด๋๊ณ ์ฌ์ฉํ ์ ์์ต๋๋ค. </p>
<p><code>server/accounts.js</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Meteor.methods({</div><div class="line"></div><div class="line"></div><div class="line"> register: function(data) // ์๋ฒ์ธก์์ ํ์๊ฐ์
์คํ์ ์ฌ์ฉ๋จ.</div><div class="line"> {</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">[์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">});</div><div class="line"></div><div class="line">// ๊ฐ์
์ ๋ฉ์ผ ๋ฐ์ก</div><div class="line">Accounts.onCreateUser(function (options, user) {</div><div class="line"></div><div class="line"> user.profile = options.profile; // ์ด๋ ๊ฒ ์ํด์ฃผ๋ฉด profile์ด ์๋ ์ํ๋ก ๊ฐ์
๋จ...</div><div class="line"></div><div class="line"> Meteor.setTimeout(function() { // setTimeout์ ๊ฑธ์ด์ฃผ์ง ์์ผ๋ฉด ๋ฉ์ผ ๋ฐ์ก์ด ์๋จ</div><div class="line"></div><div class="line"> Meteor.call('sendVerificationLink', user._id, function (err)</div><div class="line"> {</div><div class="line"> if (err)</div><div class="line"> {</div><div class="line"> throw error.reason;</div><div class="line"> }</div><div class="line"> });</div><div class="line"> </div><div class="line"> }, 2 * 1000);</div><div class="line"></div><div class="line"> return user; // ๊ผญ ์ ์ฌ์ฉ์ ๊ฐ์ฒด๋ฅผ ๋ฐํํด์ผ ํจ.(๊ฐ์ด๋์ ๋์์๋ ๋ด์ฉ์)</div><div class="line"></div><div class="line">});</div></pre></td></tr></table></figure></p>
<p>๋ค์์ผ๋ก ๋ผ์ฐํฐ์ ํด๋น ์ด๋ฉ์ผ๋ก ๋ณด๋๋ ํ์ธ ์ฃผ์๋ก ์ ๊ทผํ ๊ฒฝ์ฐ ํค ๊ฐ์ด ๋ง๋์ง ํ์ธ ํ๋ ๋ถ๋ถ์ ์ถ๊ฐํด์ผ ํ๋ค. ๋ฉ์ผ๋ก ๋ณด๋ธ ๋งํฌ๊ฐ ์ ์์ ์ด๋ผ๋ฉด, ๋งํฌ๋ฅผ ํด๋ฆญํ ์ฃผ์๋ก ์ ์ํ๋ ์๊ฐ ํ์๊ฐ์
์ด ์๋ฃ๋๋ ๋ฐฉ์์ด ๋๊ฒ ์ต๋๋ค. ์ฐธ๊ณ ๋ก ์์ ์์ค์์ <code>sendVerificationLink</code> ํธ์ถ์ <code>Meteor.setTime()</code>๋ก ๊ฐ์ธ์ฃผ์ง ์์ผ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. </p>
<p><code>lib/routes.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line">[์ ์ค๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line"> content: 'changePassword'</div><div class="line"> });</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> FlowRouter.go('/');</div><div class="line"> }</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">//์ด๋ฉ์ผ ์ธ์ฆ ๊ด๋ จ</div><div class="line">FlowRouter.route( '/verify-email/:token', {</div><div class="line"> name: 'verify-email',</div><div class="line"> action( params )</div><div class="line"> {</div><div class="line"> Accounts.verifyEmail( params.token, ( error ) => {</div><div class="line"> if ( error )</div><div class="line"> {</div><div class="line"> Bert.alert( error.reason, 'danger' );</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> FlowRouter.go( '/' );</div><div class="line"> Bert.alert( '์ด๋ฉ์ผ ์ธ์ฆ์ ์ฑ๊ณตํ์ต๋๋ค.', 'success' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p><code>Accounts.verifyEmail</code> API๋ฅผ ์ด์ฉํด์ ๋ฉ์ผ์ ํตํ ๋งํฌ ์ ๊ทผ ๊ฐ์ด ์ ์์ ์ผ ๊ฒฝ์ฐ ํ์๊ฐ์
์ด ์ ์์ ์ผ๋ก ์ฒ๋ฆฌ๋๋๋ก ํฉ๋๋ค.</p>
<p>๋ค์์ผ๋ก ๋ก๊ทธ์ธ ํ ์ฒซ ํ๋ฉด์์ ํ์ ๊ฐ์
์ด ์งํ์ค์ผ ๊ฒฝ์ฐ(์ด๋ฉ์ผ ์ธ์ฆ์ ์์ง ๋ฐ์ง ์์ ์ํ)์๋ ์ ์ ์ ๋ณด๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด ์๋ ์์ง ๋ฉ์ผ์์ ๊ฐ์
์น์ธ์ ํ์ง ์์๋ค๋ ๋ฉ์์ง๋ฅผ ๋ณด์ฌ์ฃผ๋ ๋ถ๋ถ์ ์ถ๊ฐํ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p><code>client/home.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div></pre></td><td class="code"><pre><div class="line"><template name="userInfo"></div><div class="line"> </div><div class="line"> {{#unless currentUser.emails.[0].verified}}</div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <h2>METEOR ACCOUNTS</h2></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"></div><div class="line"> <div class="col-xs-12 panel-body-inner-box-4"></div><div class="line"> <h3>ํ์ธ ๋ฉ์์ง</h3></div><div class="line"> <p>๊ฐ์
ํ์ ์ด๋ฉ์ผ๋ก ๊ฐ์
์น์ธ์ ํด์ฃผ์
์ผ ์ฌ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.</p></div><div class="line"> <p>๋ฉ์ผ์ด ์ค์ง ์์ผ์
จ๋ค๋ฉด ๋ฉ์ผ์ ์ฌ๋ฐ์ก ํด์ฃผ์ธ์.</p></div><div class="line"> </div></div><div class="line"> <form class="col-md-12 panel-body-inner-1"></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" class="form-control account-text-form-1" placeholder="๊ฐ์
์ด๋ฉ์ผ"></div><div class="line"> </div></div><div class="line"> </form></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="resend-verification-link" class="btn btn-danger btn-lg btn-block button">๋ฉ์ผ ์ฌ๋ฐ์ก</button></div><div class="line"> </div></div><div class="line"></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> {{else}}</div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <h2>METEOR ACCOUNTS</h2></div><div class="line"> <p>๊ฐ์
์ ์ ์ ๋ณด</p></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"></div><div class="line"> <div class="col-xs-12 panel-body-inner-box-3"></div><div class="line"> <p>Email: {{currentUser.username}} </p></div><div class="line"> <hr/></div><div class="line"> <p>First Name: {{currentUser.profile.firstName}} </p></div><div class="line"> <hr/></div><div class="line"> <p>Last Name: {{currentUser.profile.lastName}} </p></div><div class="line"> <hr/></div><div class="line"> </div></div><div class="line"></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"></div><div class="line"> <button name="btn-logout" class="btn btn-danger btn-lg btn-block button">๋ก๊ทธ์์</button></div><div class="line"> <a href="{{pathFor 'changePassword'}}" class="a-right" >๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</a></div><div class="line"> </div></div><div class="line"></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> {{/unless}}</div><div class="line"></template></div></pre></td></tr></table></figure>
<p>์์ ๋ด์ฉ์ค์ <code>ํ์ธ ๋ฉ์์ง</code> ํ์ด์ง์ ๊ฒฝ์ฐ ํ์๊ฐ์
๋ง ๋์ด ์๊ณ , ๋ฉ์ผ๋ก ํ์ธ์ ํ์ง ์์์ ๋ ๋ณด์ฌ์ง๋ ํ๋ฉด์ธ๋ฐ์. ์ด ๊ฒฝ์ฐ ๋ฉ์ผ ๋ฐ์ก์ด ์ ๋ชป ์ด๋ฃจ์ด ์ก์ ์๋ ์์ด, ์ด๋ด ๊ฒฝ์ฐ ๋ค์ํ๋ฒ ๋ฉ์ผ์ ๋ฐ์กํ๋ input ๋ฐ์ค๋ฅผ ๋ง๋ค์ด ๋๋ ๋๋ ์ฅ์น๋ฅผ ์ถ๊ฐํ ๋ถ๋ถ์ด ๋๊ฒ ์ต๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/SiPWE2nGbL86uW4pthuNxwFlgdp1xIbMTSw7Ec4DyXgz5tWVa4ZJ5GdkzLTP4AVSlZFAsyxMM4jkxm0xEi-ql9n5xV4tZAihv05Orn245_OYs1QhKVAWjGUaT55qLYn7M8YnBn5bvo6BjM9TRHN6ooeIixne8JPWVadudca7MQ2G2W2bhi6RyuejwWKesV9aOKicKoAnkoJIJMBvX4jemBVASRbA3kMhx5yP0i-DXYs9H6DYRnWhd5Ns2Vf0p-NIcYoN3ZZ7G4cJKKqfpI7mmJDenZLrNYETfbn0aK52Fzy6ScNlOET_EdffjaP10tI_L20Qku4xdOrTtX33M7I9FRLWolDDO-q5BzK9NIt2W5LIsi9k0D-KC_bN8Q861bPcK6fUp4MeTj81AF3-kOpuY3nBQsF3T5VLOLcMxDRsYJiyLEFlvtO2vhWBgo63AMIoUQrtecmdOGAWgJQqf-oZQaQaXNKVtF5wkEQTD4Jfyeqji8xJUgtg_x0DaIRifcdlz9XQ_ATsleR1yFC7W37uFkPWADFlyH8tXfiN2TXqJUJqEt30qbH5Prsy9-1ARvYi2WCGgKwmKPoOXoGJZr_YdXuFoXs9Je3E8ncvBBADzTo4YxqGgjnBJAIGDM69sisHsm_Pcrh_NtQ2ncVn4QYy7LvgjXe8gbhxS_U5zLdzBLk=w619-h441-no"></p><p style="text-align: center;">[home.html ํ์ด์ง - ํ์๊ฐ์
ํ์ธ ํ์ด์ง]</p><p></p>
<p><code>home.html</code> ์ ์ด 3๊ฐ์ง์ ์ํฉ์ ๋ฐ๋ฅธ ํ๋ฉด์ ๋ํ๋
๋๋ค. ์์ ํ์๊ฐ์
ํ์ธ ํ์ด์ง์ ํจ๊ป ๋ค์ 2ํ์ด์ง๊ฐ ์ํฉ์ ๋ฐ๋ผ์ ๋ํ๋๊ฐ ๋ฉ๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/1W9MK5V3JUqstBrDbh-xqxpQ4SamNR8dPpfmZTcgdRk3z-fwYA4ix-yTzwrPv0TdMR4Aaisl6s3pCsHZONin7bb6Dctb0ra0D6pm-Qky20Uc_FFLLVQtaegdazpy_gJEaUcw7OxRpClgLBsgbfYK55TwGmHDWd7O6GScNXSVqldin90a38Ls0NseKKKDIVtcMGpm1nZT6o8X4nGhFiOYpSeeqUccJ4E2xxBVOoi4cIrZxHRWobhMhszC78wqHvltLRp9lWUYGCaFlH2qTrTba6UZAWYeovWHW8zfOcpoXal3iuwDV6i0iLDhBZ701G_Da2wfQagOofEjKvgLqtrfm2P5vxgAa06w9kaAQRbY92teH0J6rnOO7GncGMU6h8jONS1BnBxGJqiYIllKFG_-Vng7ra2SZ4vb1OuXEgjuuosJNpvgHJu16-hekbQs73srGgzqrpbmfYERFfk4SxwmmLMwfF9e41ThBgujhZiW-CcgY2AUCKgt6314W1xFprRs9mr_RDV1ahTk1vdlZhgbyDPyfkiAtNN86O39m7-ylNB3Kztzk0pNbU31Y1SH-3Z43J8C0ilcF4blhJjVnGAJU9tl3sXJa0NbQfm_4rcEXx2JY8flpPZcUIty3iz5BPSAE1sP_g6ahYTAAdQD1kJrS0uDF_vbSySZw_y7DCS4MdA=w727-h364-no"></p><p style="text-align: center;">[home.html ํ์ด์ง - ๋ก๊ทธ ์์ ์ํ์ผ ๋์ ํ์ด์ง]</p><p></p>
<p><img src="https://lh3.googleusercontent.com/TNqGkV0ZOW2480t4GBUaEOEA056ZaYC8tuKAvOWrR5hM6hE3mJeVAX8N9OXkrctqWtDVZPhw70lCGG_0P8ZpZ8fAzA9_cJRaPwW9YUsA8I5CYNlkMRjKBZH6diankWsOCn8rERZGeSYKmoiqgwIZ0LJlS2TraZeGrnDn_cavvnDXTsUoh8UBACUahRHQVQbe4tLsNFs6Kzhe8KN4psRKxzfJGoibVC1nME47rj7ZmtwIQXl5kRlwnBwK7Bw1oSzNkgbsfmumrRc8mfH3JokNQlriiYXXVAN7QBSy3XaNF3sdpiyNFGQtS5iR38OaNL8fnIIRMFz8hvXdKISPtYXO2odMq0usWHmDP1aXUGrfA2QcP79IzOxDkmAq-cFXa6yK9GJNcTEnIaDiJhPfPEKroMrmlfqQBY8kdUf256YFReOHnO49rNdm9h7lqhe9T9o17Ld1wKQlqmkf3-9Y8lvfS63yJXlG0Dx0xKM7o1mOs-Bw8dPUnNPgQWfVCFVc379QoNYzHldSGRfOtL_gH0cDnUVGCaOPf1NrU4UXI5N5guf-NQ24XKGiF7AyoU1g-En6HuO_ZMLTcetsqG041GMtDE_Vw1o7PKtbtGlxlsrkq89kx3_G3fnQ0_rghqJbwfFachWVwEktpQbtJxlFkbN-kj0QXrzDFDBT_RB7PVvp22g=w627-h477-no"></p><p style="text-align: center;">[home.html ํ์ด์ง - ํ์๊ฐ์
ํ์ธ ํ ๋ก๊ทธ์ธ ํ์ด์ง]</p><p></p>
<p>์ฌ๊ธฐ์ ์ ๊น meteor์์์ ํ์๊ฐ์
๊ณผ์ ์ ์กฐ๊ธ ์ค๋ช
๋๋ฆฌ๊ฒ ์ต๋๋ค. meteor๋ก <code>Accounts.createUser()</code>๋ก ํ์๊ฐ์
์ด ์งํ๋๋ฉด, ๋ฐ์ดํฐ๋ฒ ์ด์ค user collection(meteor๋ ๊ธฐ๋ณธ์ ์ผ๋ก mongodb๋ฅผ ์ฌ์ฉํฉ๋๋ค.)์ ๋ค์๊ณผ ๊ฐ์ json ํ๋๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. ๊ฐ ์ปฌ๋ผ์ ๋ค์๊ณผ ๊ฐ์ ์ฑ๊ฒฉ์ ๊ฐ์ง๋๋ค. ๊ธฐ๋ณธ์ ๋ณด ์ด์ธ์ ์ฌ์ดํธ๋ง๋ค ๋ฑ๋ก์ด ํ์ํ ๊ฐ๋ค์ profile ํ๋ ์๋์ ๋ฃ์ด๋๊ณ ์ฌ์ฉํ ์ ์์ต๋๋ค.</p>
<ul>
<li>_id : ๊ณ ์ ๊ฐ</li>
<li>createdAt : ์์ฑ๋ ์ง</li>
<li>services/password : ๋น๋ฐ๋ฒํธ(์๋์ผ๋ก ์ํธํ)</li>
<li>username: ๊ฐ์
์์ด๋(๊ธฐ๋ณธ์ ์ผ๋ก ๊ฐ์
์ด๋ฉ์ผ์ ์ฌ์ฉ)</li>
<li>emails/address : ๊ฐ์
ํ ์ด๋ฉ์ผ ์ฃผ์</li>
<li>emails/verified : ๊ฐ์
ํ์ธ ์ ๋ฌด(๊ธฐ๋ณธ false๋ก ์ด๋ฉ์ผ ๊ฐ์
ํ์ธ์ ์ฌ์ฉ)</li>
<li>profile: ๊ธฐํ ๊ฐ์
์ ๋ณด(์ฌ์ฉ์๊ฐ ์์๋ก ์ถ๊ฐํ๋ ํ๋์ ๊ฒฝ์ฐ ์ด ์๋์ ๋๊ณ ์ฌ์ฉํ๋ฉด ๋จ.)</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line"> "_id" : "gKdDPzkLRjcbAwnG5",</div><div class="line"> "createdAt" : ISODate("2017-05-27T15:13:55.357Z"),</div><div class="line"> "services" : {</div><div class="line"> "password" : {</div><div class="line"> "bcrypt" : "$2a$10$og01yOey9To/ugGr8uxBbe1nCqKZ30qCzikh88OJi4KY9Vj3Qm7xO"</div><div class="line"> }</div><div class="line"> },</div><div class="line"> "username" : "freeseamew@gmail.com",</div><div class="line"> "emails" : [ </div><div class="line"> {</div><div class="line"> "address" : "freeseamew@gmail.com",</div><div class="line"> "verified" : false // ์ด ๋ถ๋ถ์ ํตํด ์ด๋ฉ์ผ ์ธ์ฆ ํ์ธ ๊ฐ๋ฅ</div><div class="line"> }</div><div class="line"> ],</div><div class="line"> "profile" : {</div><div class="line"> "serviceType" : "site",</div><div class="line"> "firstName" : "๊ฐ์
์ ์ด๋ฆ",</div><div class="line"> "lastName" : "๊ฐ์
์ ์ฑ",</div><div class="line"> "gender" : ""</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure>
<p>์ด๋ฅผ ์ฐธ๊ณ ๋ก ์์ <code>home.html</code> ํ์ด์ง๊ฐ ์ํฉ์ ๋ฐ๋ผ์ ํ๋ฉด์ ๋ณด์ฌ์ฃผ๋ ์๋ฆฌ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. </p>
<p><code>#unless loggingIn</code> ๋ก ๋จผ์ ๋ก๊ทธ์ธ ์ํ๋ฅผ ํ์ธ ํ ๋ค์์ ๋ก๊ทธ์ธ ๋์ด ์์ผ๋ฉด, <code>#unless currentUser.emails.[0].verified</code>๋ฅผ ์ฐธ๊ณ ํ์ฌ <code>verified</code>๊ฐ true์ด๋ฉด ๋ก๊ทธ์ธ ์ด์ฉ์์ ์ ๋ณด๋ฅผ ๋ณด์ฌ์ฃผ๊ณ , false์ผ ๊ฒฝ์ฐ์๋ <code>ํ์๊ฐ์
ํ์ธ ํ์ด์ง</code>๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ตฌ์ฑ์ ๊ฐ์ง๊ฒ ๋ฉ๋๋ค. </p>
<hr>
<h3 id="5-ํ์๊ฐ์
์-์ฌ์ฉ์-์ ์-๊ฐ์
์ ๋ณด-์ถ๊ฐ-๋ฐฉ๋ฒ"><a href="#5-ํ์๊ฐ์
์-์ฌ์ฉ์-์ ์-๊ฐ์
์ ๋ณด-์ถ๊ฐ-๋ฐฉ๋ฒ" class="headerlink" title="5. ํ์๊ฐ์
์ ์ฌ์ฉ์ ์ ์ ๊ฐ์
์ ๋ณด ์ถ๊ฐ ๋ฐฉ๋ฒ"></a>5. ํ์๊ฐ์
์ ์ฌ์ฉ์ ์ ์ ๊ฐ์
์ ๋ณด ์ถ๊ฐ ๋ฐฉ๋ฒ</h3><p>์์์ ์ค๋ช
ํ์ง๋ง ๊ธฐ๋ณธ์ ์ธ ๊ฐ์
์์คํ
์ ๋ง๋ค๋ฉด, _id, createAt, username, emails์ ๊ฐ์ ์ต์ํ์ ์ ๋ณด๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ์ฅํฉ๋๋ค. ํ์ง๋ง ๊ทธ์ธ์ ์ ๋ณด(์ฑ๋ณ, ์ฌ์ฉ์์ด๋ฆ, ๋ ๋ฒจ, ์ฃผ์ ๋ฑ)๋ profile์ด๋ผ๋ ํ๋ ์๋์ ๋ฃ์ด์ ์ฌ์ฉ ํ ์ ์์ต๋๋ค. ์ฌ์ค ์์์๋ ์ด๋ฏธ ๊ทธ ๋ถ๋ถ์ ๋ํด์ ์กฐ๊ธ ์ค๋ช
์ ๋๋ ธ์ง๋ง, ์กฐ๊ธ ๋ ์ด ๋ถ๋ถ์ ๋ํด์๋ง ๋ค์ํ๋ฒ ์ค๋ช
๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>register.html์์ ํผ ๊ฐ ๋ฑ์ผ๋ก ์ ์๋ ๊ฐ์ register.js์ registerInfo๋ผ๋ ๊ฐ์ฒด์ ์ ์ฅ๋ ํ register ๋ฉ์๋๋ก ์ ๋ฌ๋ฉ๋๋ค. ์ด ๋ ํ์ํ ๊ฐ๋ค์ profile์๋์ ์ ์ํด์ ๋๊ธฐ๋ฉด ๋ฉ๋๋ค. </p>
<p><code>client/register.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line"> var registerInfo = {</div><div class="line"> username: inputUsername,</div><div class="line"> email: inputEmail,</div><div class="line"> password: inputPassword,</div><div class="line"> profile: { // ์ฌ์ฉ์ ์ ์ ๊ฐ์
์ ๋ณด</div><div class="line"> firstName: inputFirstName,</div><div class="line"> lastName: inputLastName</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"></div><div class="line"> //์๋ฒ๋ก์ ๋ก๊ทธ์ธ ํธ์ถ</div><div class="line"> Meteor.call('register', registerInfo, function (err)</div><div class="line"> {</div><div class="line"> if(!err)</div><div class="line"> {</div><div class="line"> Bert.alert( '๊ฐ์
์ ์ฑ๊ณตํ์ต๋๋ค. ๊ฐ์
ํ ๋ฉ์ผ๋ก ์ธ์ฆ์ ๋ฐ์์ฃผ์ธ์' , 'danger', 'growl-top-right' );</div><div class="line"> FlowRouter.go('/login');</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> Bert.alert( err.message , 'danger', 'growl-top-right' );</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line">}</div></pre></td></tr></table></figure>
<p>์ด๋ฅผ <code>server/accounts.js'์</code>register` ๋ฉ์๋์์ ๋ค์ ๋ฐ๊ฒ ๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ โAccounts.createUser()โ์ ๋ฐ์ ๊ฐ๋ค์ ๋๊น๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Meteor.methods({</div><div class="line"></div><div class="line"> register: function(data) // ์๋ฒ์ธก์์ ํ์๊ฐ์
์คํ์ ์ฌ์ฉ๋จ.</div><div class="line"> {</div><div class="line"></div><div class="line">'</div><div class="line">'</div><div class="line">'</div><div class="line">[์ค๋ต]</div><div class="line">'</div><div class="line">'</div><div class="line">'</div><div class="line"> // ํ์๊ฐ์
์์</div><div class="line"> try</div><div class="line"> {</div><div class="line"> user = Accounts.createUser({</div><div class="line"> username: data.username,</div><div class="line"> email: data.email,</div><div class="line"> password: data.password,</div><div class="line"> profile:{</div><div class="line"> serviceType: 'site',</div><div class="line"> firstName: data.profile.firstName,</div><div class="line"> lastName: data.profile.lastName,</div><div class="line"> gender: ''</div><div class="line"> }</div><div class="line"> });</div><div class="line"></div><div class="line"> return {</div><div class="line"> "userId": user</div><div class="line"> };</div><div class="line"></div><div class="line"> }</div><div class="line"> catch (err)</div><div class="line"> {</div><div class="line"> throw err;</div><div class="line"> }</div><div class="line"></div><div class="line"> },</div></pre></td></tr></table></figure>
<p>๋ง์ง๋ง์ผ๋ก <code>Accounts.onCreate()</code> api๋ฅผ ์ฌ์ฉํ์ฌ ์์ ๊ฐ์ด ์ ์ฅ๋ ๋ ๋ค์ํ๋ฒ, ์ฌ์ฉ์ ์ ์ ๊ฐ์ด ์ด๋์ ์ ์ฅ๋ ์ง ์ง์ ํด ์ฃผ๋ฉด ๋ฉ๋๋ค. ์ฐธ๊ณ ๋ก, profile๊ฐ๋ค์ options.profile์ ๋ค์ด๊ฐ ์๊ณ , ์๋์ ๊ฐ์ด ์ค์ ํ๋ฉด ์ ์์ ์ผ๋ก ๋ชฝ๊ณ ๋๋น์ user collection์ ๊ฐ์
์์ profile์ ์ ์ฅ๋ฉ๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">Accounts.onCreateUser(function (options, user) </div><div class="line">{</div><div class="line"></div><div class="line"> user.profile = options.profile;// ์ด๋ ๊ฒ ์ํด์ฃผ๋ฉด profile์ด ์๋ ์ํ๋ก ๊ฐ์
๋จ...</div><div class="line"></div><div class="line"></div><div class="line">[์๋ ์๋ต]</div><div class="line">.</div><div class="line">.</div><div class="line">.</div></pre></td></tr></table></figure>
<p>๋จธ ํ์๊ฐ์
๊ณผ์ ์ ๋๋ต ์ด๋ ์ต๋๋ค. ์ ์ค๋ช
์ผ๋ก ์กฐ๊ธ์ด๋๋ง ์ด ๊ณผ์ ์ด ์ดํด๊ฐ ๋์์ผ๋ฉด ์ข๊ฒ ์ง๋ง, ๊ทธ๋ ์ง ์๋ค๋ฉด, ๊ทธ๋ฅ ์ด๋ ๊ฒ ๊ฐ์
์ด ๋๊ณ ๋ก๊ทธ์ธ์ด ๋๋ค๋ก ์ดํดํ๊ณ ๋์ด๊ฐ ์ฃผ์
๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ ๊ฐ ๊ฐ์ข๋ฅผ ์ฒ์ ์ฐ๋ ๊ฒ์ด๋ผ, ์ฌ๋ฌ ์ค๋ช
์ด ์กฐ๊ธ ๋งค๋๋ฝ์ง ๋ชปํ์ ์ ์ํด ๋ถํ๋๋ฆฝ๋๋ค. ใ
กใ
</p>
<p>๊ทธ๋ผ ๋ค์ ๊ฐ์ข๋ ๊ณ์ ๋ด์ฃผ์ธ์ ^^</p>
]]></content>
<summary type="html">
<h3 id="4-ํ์๊ฐ์
-๊ธฐ๋ณธ"><a href="#4-ํ์๊ฐ์
-๊ธฐ๋ณธ" class="headerlink" title="4. ํ์๊ฐ์
๊ธฐ๋ณธ"></a>4. ํ์๊ฐ์
๊ธฐ๋ณธ</h3><p>์ ๋ฒ ๊ฐ์ข๋ฅผ ํตํด ๊ธฐ๋ณธ์ ์ธ ํ์ด์ง ๋์์ธ๊ณผ ํ์ด์ง ์ด๋(routing)
</summary>
<category term="meteor, custom account, ๋ฏธํฐ์ด" scheme="http://freeseamew.github.io/tags/meteor-custom-account-%EB%AF%B8%ED%8B%B0%EC%96%B4/"/>
</entry>
<entry>
<title>Meteor custom account ๊ฐ์ข 1</title>
<link href="http://freeseamew.github.io/2017/07/02/meteor-account-tutorial-1/"/>
<id>http://freeseamew.github.io/2017/07/02/meteor-account-tutorial-1/</id>
<published>2017-07-01T15:40:32.000Z</published>
<updated>2017-07-03T15:53:21.000Z</updated>
<content type="html"><![CDATA[<h3 id="0-๊ฐ์ข-์๊ฐ"><a href="#0-๊ฐ์ข-์๊ฐ" class="headerlink" title="0. ๊ฐ์ข ์๊ฐ"></a>0. ๊ฐ์ข ์๊ฐ</h3><p>ํ์คํ ํ๋ซํผ์ธ meteor๋ ๊ธฐ๋ณธ์ ์ผ๋ก account(๋ก๊ทธ์ธ, ํ์๊ฐ์
๋ฑ)์ ๋ํด์๋ ๊ฐ๋จํ ํ๊ทธ ํ๋๋ก ๊ตฌํํ ์ ์๋๋ก ๊ธฐ๋ฅ์ ์ ๊ณตํ๊ณ ์์ต๋๋ค. ํ์ง๋ง ์ค์ ํ๋ก์ ํธ์์๋ ์ด ๊ธฐ๋ณธ ๊ธฐ๋ฅ ์ด์ธ์ ์ฌ์ดํธ์ ๋ง๊ฒ account๋ฅผ ์์ ํด์ผ ํ ๊ฒฝ์ฐ๊ฐ ์ข
์ข
๋ฐ์ํ ๊ฒ์
๋๋ค. ์ด ๊ฐ์ข๋ ์ด๋ฐ account์ ๋ํ ์ฌ์ฉ์ ์ ์ ์์ฑ์ ๋ํ ๊ฐ์ข๊ฐ ๋๊ฒ ์ต๋๋ค.<br>์ด ๊ฐ์ข์์ meteor์ ๋ํ ๊ธฐ๋ณธ ์ค๋ช
์ ๋ชจ๋ ํ๊ธฐ๋ ์ด๋ ต๊ฒ ์ง๋ง ํ์ํ ๋ถ๋ถ์ ๋ํด์๋ ๊ฐ๋จํ๊ฒ ์ถ๊ฐ ์ค๋ช
์ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.</p>
<p>์ด ๊ฐ์ข์์ ๋ค๋ฃฐ Meteor์ account ๊ธฐ๋ฅ์ผ๋ก๋ <code>ํ์๊ฐ์
</code>, <code>๋ก๊ทธ์ธ</code>, <code>์ด๋ฉ์ผ ์ธ์ฆ</code>, <code>๋น๋ฐ๋ฒํธ ๋ถ์ค ๋ณ๊ฒฝ๋ฉ์ผ ๋ณด๋ด๊ธฐ</code>, <code>์์
๋ก๊ทธ์ธ</code> ์ด ๋๊ฒ ์ต๋๋ค. ์ฌ์ค ์ด๋ฉ์ผ์ ํตํ ํ์ ์ธ์ฆ๋ง ํ๋๋ผ๊ณ ๊ตฌํํ๊ธฐ ์ํด์๋ ๊ฝค ๋
ธ๋ ฅ์ด ํ์ํ๊ณ , ์์
๋ก๊ทธ์ธ(facebook, twiter, google, kakao)์ ๊ฒฝ์ฐ๋ ์ง๊ธ์ ๋ง์ ์ฌ์ดํธ์์ ๊ธฐ๋ณธ์ผ๋ก ์ฌ์ฉํ๋ ๊ธฐ๋ฅ์ด์ง๋ง ๋ง์ ๊ตฌํํด ๋ณด๋ ค๊ณ ํ๋ฉด ์ด๊ฒ๋ ๊ฝค ์ฝ์ง?์ด ํ์ํ ๊ธฐ๋ฅ์ธ ๊ฒ์ ๋ง์ ๋ถ๋ค์ด ๊ณต๊ฐํ์ค ๊ฒ๋๋ค. Meteor์์๋ ์ด ๋ชจ๋ ๊ธฐ๋ฅ๋ค์ด ๊ธฐ๋ณธ API๋ก ์ ๊ณต๋๊ธฐ๋ ํ๊ณ , ์ค์น ํจํค์ง๋ฅผ ํตํด ์ฝ๊ฒ ๊ตฌํํ ์ ์๋๋ก ํด์ฃผ๊ณ ์์ต๋๋ค. ์ฌ์ค ์์
๋ก๊ทธ์ธ ๊ธฐ๋ฅ๋ง์ผ๋ก๋ Meteor๋ฅผ ํ๋ฒ์ฏค ์ฌ์ฉํด๋ณผ ๊ฐ์น๊ฐ ์๋ค๊ณ ๊ฐ์ธ์ ์ผ๋ก๋ ์๊ฐํฉ๋๋ค. ์ ๊ทธ๋ผ ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ฐ์ข๋ฅผ ์์ํด ๋ณด๊ฒ ์ต๋๋ค. </p>
<blockquote>
<h4 id="๊ฐ์ข์์-๋ค๋ฅผ-๋ด์ฉ๋ค"><a href="#๊ฐ์ข์์-๋ค๋ฅผ-๋ด์ฉ๋ค" class="headerlink" title="# ๊ฐ์ข์์ ๋ค๋ฅผ ๋ด์ฉ๋ค"></a># ๊ฐ์ข์์ ๋ค๋ฅผ ๋ด์ฉ๋ค</h4><ul>
<li>ํ์๊ฐ์
ํผ</li>
<li>๋ผ์ฐํฐ</li>
<li>validate + method</li>
<li>๋ก๊ทธ์ธ</li>
<li>๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ</li>
<li>๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</li>
<li>ํ๋ฉด์ ํ + ๋ก๋ฉํจ๊ณผ</li>
<li>์์
๋ก๊ทธ์ธ </li>
</ul>
</blockquote>
<hr>
<h3 id="1-์ค์น"><a href="#1-์ค์น" class="headerlink" title="1. ์ค์น"></a>1. ์ค์น</h3><h4 id="1-1-์ค์น-๊ณตํต"><a href="#1-1-์ค์น-๊ณตํต" class="headerlink" title="1.1 ์ค์น ๊ณตํต"></a>1.1 ์ค์น ๊ณตํต</h4><blockquote>
<p>meteor.com ์์ os์ ๋ง๋ ๋ฒ์ ์ ํ๋ก๊ทธ๋จ์ ๋ค์ด ๋ฐ์ต๋๋ค.</p>
</blockquote>
<h4 id="1-2-๋ฆฌ๋
์ค-amp-๋งฅ-os"><a href="#1-2-๋ฆฌ๋
์ค-amp-๋งฅ-os" class="headerlink" title="1.2 ๋ฆฌ๋
์ค & ๋งฅ os"></a>1.2 ๋ฆฌ๋
์ค & ๋งฅ os</h4><ul>
<li>mkdir ๋ก ํด๋ ๋ง๋ ๋ค,</li>
<li>meteor create ํ๋ก์ ํธ๋ช
</li>
<li>meteor npm install โsave bcrypt</li>
<li>meteor npm install</li>
</ul>
<h4 id="1-3-์๋์ฐ-๋๊ธฐ"><a href="#1-3-์๋์ฐ-๋๊ธฐ" class="headerlink" title="1.3 ์๋์ฐ (๋๊ธฐ)"></a>1.3 ์๋์ฐ (๋๊ธฐ)</h4><p>ํ์๊ธฐ์์ ํด๋ ๋ง๋ค๊ณ cmd ์ฐฝ์ ์ด์ด ํด๋น ํด๋๋ก ์ด๋ํฉ๋๋ค. </p>
<p>: ์ฐธ๊ณ ์ฌ์ดํธ<br><a href="http://kr.discovermeteor.com/chapters/getting-started/" target="_blank" rel="noopener">http://kr.discovermeteor.com/chapters/getting-started/</a><br><a href="http://webframeworks.kr/getstarted/meteorjs/" target="_blank" rel="noopener">http://webframeworks.kr/getstarted/meteorjs/</a></p>
<h4 id="1-4-๊ธฐ๋ณธ-ํด๋"><a href="#1-4-๊ธฐ๋ณธ-ํด๋" class="headerlink" title="1.4 ๊ธฐ๋ณธ ํด๋"></a>1.4 ๊ธฐ๋ณธ ํด๋</h4><p>์์ ์ค์น๊ฐ ๋๋๋ฉด, client, server ํด๋ ๋ด์ ์ค์น์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๋ ํ์ผ๋ค์ ์ญ์ ํด ์ค๋๋ค. </p>
<p>ํด๋๊ตฌ์กฐ์ ๋ํด์ ๊ฐ๋จํ ์ค๋ช
ํด ๋๋ฆฌ์๋ฉด, client์ server๋ ๊ฐ๊ฐ ํด๋น ํด๋์ ๋ค์ด์๋ ํ์ผ๋ค์ ํด๋ผ์ด์ธํธ์ธก๊ณผ ์๋ฒ์ธก์์ ํธ์ถ์ด ๊ฐ๋ฅํ ํ์ผ๋ค์
๋๋ค. ํด๋์ ๋ฃ์ด ๋๋ ๊ฒ์ผ๋ก ํ์ผ๋ค์ ์คํ์์น๊ฐ ๊ฒฐ์ ๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ lib ํด๋์ ๊ฒฝ์ฐ ์ด ๋๊ณณ์์ ๋ชจ๋ ์ฌ์ฉํ ํ์๊ฐ ์๋ ๊ณตํต ํ์ผ๋ค์ ๋ฃ์ด๋๋ ๊ณณ์
๋๋ค. </p>
<p>์ฌ์ค ์ด ๋ฐฉ๋ฒ์ ํ์ฌ meteor ๊ฐ์ด๋์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ถ์ฒํ๋ ๋ฐฉ์์ ์๋๋๋ค. ํ์ฌ๋ es6 ์ ๊ธฐ๋ณธ ๋ฌธ๋ฒ์ธ import, export ๋ฅผ ํตํ ํ์ํ ํ์ผ๋ค์ ๋ถ๋ฌ์ค๊ณ ๋ด๋ณด๋ด๋ ๋ฐฉ์์ ์ถ์ฒํ๊ณ ์์ต๋๋ค. ํ์ง๋ง ์์ ๋ฐฉ์(ํด๋๋ณ๋ก ๋ฃ์ด๋๋ฉด ์๋์ผ๋ก ์คํ์์น์ ๋ฐ๋ผ ์คํ๋๋)์ด ๊ฐ๋ ํธ๋ฆฌํจ์ด ์์ด ๊ฐ์ธ์ ์ผ๋ก๋ ์์ง๊น์ง ์์ ๋ฐฉ์์ ์ฃผ๋ก ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๋์ค์ es6๋ฐฉ์์ผ๋ก๋ ๊ฐ์ข๋ฅผ ์ ๋ฆฌํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. (์์งํ ๋งํ๋ฉด import, export๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์ด ์์ง ์ํฝ๋๋ค. ใ
กใ
)</p>
<p><code># ๊ธฐ๋ณธ ํด๋ ๊ตฌ์กฐ</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">meteorAccount</div><div class="line">โโโ .meteor</div><div class="line">โโโ client</div><div class="line">โโโ lib</div><div class="line">โโโ node_module</div><div class="line">โโโ server</div></pre></td></tr></table></figure></p>
<hr>
<h3 id="2-๋ผ์ฐํฐ-์ค๊ณ-url-์ฃผ์์-๋ฐ๋ฅธ-ํ๋ฉด-์ ํ"><a href="#2-๋ผ์ฐํฐ-์ค๊ณ-url-์ฃผ์์-๋ฐ๋ฅธ-ํ๋ฉด-์ ํ" class="headerlink" title="2. ๋ผ์ฐํฐ ์ค๊ณ(url ์ฃผ์์ ๋ฐ๋ฅธ ํ๋ฉด ์ ํ)"></a>2. ๋ผ์ฐํฐ ์ค๊ณ(url ์ฃผ์์ ๋ฐ๋ฅธ ํ๋ฉด ์ ํ)</h3><p>์ ์ผ ์ฒ์ ํ ์ผ์, ์ผ๋จ ์ฒ์ ์์ํ์ด๋ฅผ ๋ง๋ค๊ณ , ๊ฑฐ๊ธฐ์ ๋ก๊ทธ์ธ ๋๋ ํ์๊ฐ์
ํ์ด์ง๋ก์ ํ๋ฉด์ ํ ํ์ด์ง๋ฅผ ๋ง๋๋ ๊ฒ๋ถํฐ ์์ํด ๋ณด๊ฒ ์ต๋๋ค. ์ฝ๊ฒ ๋งํด ํํ ํ๋ ๊ฐ๋จํ ๋ผ์ฐํ
์์
์ ํด๋ณด๋ ๊ฒ์
๋๋ค. </p>
<p>๋ฏธํฐ์ด๋ ๊ธฐ๋ณธ์ ์ผ๋ก router๋ฅผ ์ ๊ณตํ๊ณ ์์ง ์์ง๋ง, ์ค์น ํํค์ง๋ฅผ ํตํด์ ์ฌ์ฉ์๊ฐ router๋ฅผ ์ ํํด ์ค์นํ ์ ์์ต๋๋ค. ์ด๋ฒ ๊ฐ์ข์์๋ ํ์ฌ ์ ์ผ ๋ง์ด ์ฌ์ฉ๋๋ค๊ณ ํ๋จ๋๋ flow-router๋ฅผ ์ค์น ํ ์ฌ์ฉํ๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>ํ๋ก์ ํธ ํด๋์์ ํฐ๋ฏธ๋ ๋๋ cmd์ฐฝ์ ์ด๊ณ ์๋ <code>์ค์นํจํค์ง</code> ๊ด๋ จ ๋ช
๋ น์ด๋ฅผ ์
๋ ฅํด์ ํ์ํ ํจํค์ง๋ฅผ ์ค์นํ๋๋ก๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>meteor์ ๊ฒฝ์ฐ ๋ค์ํ front-end ํ๋ ์์ํฌ๋ฅผ ์ง์ํ๋๋ฐ, ์ด๋ฒ ๊ฐ์ข์์๋ meteor์ ๊ธฐ๋ณธ ํ๋ก ํธ์๋ ํ๋ ์์ํฌ์ธ blaze๋ฅผ ์ฌ์ฉํ ๊ฒ์์ผ๋ก ํ์ํ blaze-layout๋ ํจ๊ป ์ค์นํ๊ฒ ์ต๋๋ค. </p>
<p>์ฐธ๊ณ ๋ก meteor๋ <code>meteor add ํจํค์ง์ด๋ฆ</code> ์ด๋ฐ์์ผ๋ก ํ์ํ ํจํค์ง๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์์ ๋ช
๋ น์ด๋ฅผ ํ๋ก์ ํธ๊ฐ ์๋ ํด๋๊ฒฝ๋ก์ ํฐ๋ฏธ๋์ฐฝ์์ ์
๋ ฅํ์๋ฉด ๋ฉ๋๋ค. <code>์ฐธ๊ณ ์ฌ์ดํธ</code>๋ meteor์์ ์ฌ์ฉํ ์ ์๋ ์ปดํฌ๋ํธ๋ฅผ ๋ชจ์๋์ ์ฌ์ดํธ ์
๋๋ค. ์ด ์ฌ์ดํธ์์ ํ์ํ ๊ธฐ๋ฅ๋ค์ ๊ฒ์ํด ๋ณด์๋ฉด ๋ง์ ๊ธฐ๋ฅ๋ค์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์๋๊ณ ์๋ ๊ฒ์ ํ์ธ ํ ์ ์์ ๊ฒ์
๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง</p>
<ul>
<li>meteor add kadira:flow-router</li>
<li>meteor add kadira:blaze-layout</li>
</ul>
<p>: ์ฐธ๊ณ ์ฌ์ดํธ<br><a href="https://atmospherejs.com/" target="_blank" rel="noopener">https://atmospherejs.com/</a></p>
</blockquote>
<p>์๋ ํด๋ ๊ตฌ์กฐ๋ฅผ ์ฐธ๊ณ ํ์ฌ ์๋ก ํด๋ ๋ฐ ํ์ผ๋ค์ ๋ง๋ค์ด ์ค๋๋ค.<br>์ฐธ๊ณ ๋ก meteor์ blaze์ ๊ฒฝ์ฐ template๋ฐฉ์์ผ๋ก, ๊ฐ์ ์ด๋ฆ์ html, js, css ๊ฐ ํจ๊ป ์๋ํ๋ ๊ตฌ์กฐ์
๋๋ค. login.html์ html๊ตฌ์กฐ์ ํ
ํ๋ฆฟ์ ๋ง๋ค๊ณ , ์ฌ๊ธฐ์ ์ฌ์ฉํ js ํ์ผ์ ๊ฒฝ์ฐ login.js๋ฅผ ๋ง๋ค์ด ์ฌ์ฉํ๋ฉด ๋๋ ๊ตฌ์กฐ๊ฐ ๋ฉ๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">meteorAccount</div><div class="line">โโโ .meteor</div><div class="line">โโโ client</div><div class="line">โ โโโ styles </div><div class="line">โ โ โโโ main.css </div><div class="line">โ โโโ change-password.html </div><div class="line">โ โโโ change-password.js</div><div class="line">โ โโโ main-layout.html</div><div class="line">โ โโโ main-layout.js </div><div class="line">โ โโโ home.html</div><div class="line">โ โโโ home.js</div><div class="line">โ โโโ login.html </div><div class="line">โ โโโ login.js</div><div class="line">โ โโโ recover-password.html </div><div class="line">โ โโโ recover-password.js</div><div class="line">โ โโโ register.html </div><div class="line">โ โโโ register.js </div><div class="line">โโโ lib</div><div class="line">โ โโโ checkPattern.js </div><div class="line">โ โโโ routes.js </div><div class="line">โโโ node_module</div><div class="line">โโโ public</div><div class="line">โโโ server</div><div class="line"> โโโ accounts.js </div><div class="line"> โโโ accountsMails.js</div></pre></td></tr></table></figure>
<p>์ฌ์ฉํ css ์์๋ฅผ client/styles/main.css ์ ํ์ผ์ ๋ง๋ค๊ณ , ์๋ styleํ์ผ์ ๋ณต์ฌ์ ๋ถ์ฌ๋ฃ๊ธฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ฉํฉ๋๋ค. bootstrap์ ๊ธฐ๋ณธ์ผ๋ก ํ๊ณ , ์กฐ๊ธ ์์ ํ์ฌ ์ฌ์ฉํ ์์ ์
๋๋ค. bootstrap ์ญ์๋ ์๋๋ฅผ ์ฐธ๊ณ ๋ก ํจํค์ง๋ฅผ ์ค์นํ์ฌ ์ฌ์ฉ ํ ์ ์์ต๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง</p>
<ul>
<li>meteor add twbs:bootstrap@=3.3.6</li>
</ul>
<p>main.css ์์ค ๋งํฌ<br><a href="https://gist.github.com/freeseamew/bf3ce3e1fcc13fa33d26a6a1aaf06379" target="_blank" rel="noopener">https://gist.github.com/freeseamew/bf3ce3e1fcc13fa33d26a6a1aaf06379</a></p>
</blockquote>
<p>์ด์ ๋ผ์ฐํฐ ์ค์ ์ ํด๋ณด๊ฒ ์ต๋๋ค.<br>๊ธฐ๋ณธ์ ์ธ ๋ผ์ฐํฐ ์ค์ ์ ์๋์ ๊ฐ์ต๋๋ค. ์๋ ๋ด์ฉ์ ์ฐธ๊ณ ๋ก ํด๋น ์์น์ ํ์ผ์ ๋ง๋ค๊ณ ์์ค๋ฅผ ์
๋ ฅํด ์ฃผ์๋ฉด ๋ฉ๋๋ค. </p>
<p><code>lib/routes.js</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">FlowRouter.route('/', {</div><div class="line"> name: 'home',</div><div class="line"> action: function() {</div><div class="line"> BlazeLayout.render('mainLayout', {</div><div class="line"> content:'home'</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">FlowRouter.route('/login', {</div><div class="line"> name: 'login',</div><div class="line"> action() {</div><div class="line"> BlazeLayout.render('mainLayout', {</div><div class="line"> content: 'login'</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div><div class="line"></div><div class="line">FlowRouter.route('/register', {</div><div class="line"> name:'register',</div><div class="line"> action: function() {</div><div class="line"> BlazeLayout.render('mainLayout', {</div><div class="line"> content: 'register'</div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>๋ผ์ฐํฐ์ ๋ํด์ ์กฐ๊ธ ์ค๋ช
๋๋ฆฌ๋ฉด,<br>์๋์ ๋ด์ฉ์ ์๋ก <code>http://localhost:3000/register</code> ์ฃผ์๋ก url์ ์
๋ ฅํ๋ฉด <code>regiger</code>๋ผ๋ template์ด <code>mainLayout</code>์ด๋ผ๋ ๊ณณ์ ๋ณด์ฌ ์ง๋ค๋ ์๋ฏธ๋ฅผ ๊ฐ์ง๋๋ค. ๋ค์ ์ค๋ช
ํ์๋ฉด, url์ฃผ์์ ๋ฐ๋ผ home, login, register ๋ฑ์ ํ์ด์ง๋ก ์ด๋ํ๊ฒ ํ๋ ๊ธฐ๋ฅ์ ํฉ๋๋ค. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">FlowRouter.route('/register', { // url ๊ฒฝ๋ก</div><div class="line"> name:'register', // ํด๋น ๋ผ์ดํ
์ด๋ฆ</div><div class="line"> action: function() {</div><div class="line"> BlazeLayout.render('mainLayout', { // template์ด ๋ฟ๋ ค์ง ์์น </div><div class="line"> content: 'register' // template ์ด๋ฆ </div><div class="line"> });</div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure>
<p>๋ค์์ ์์ ์ ์ ์ค๋ช
ํ ์ฃผ์์ ๋ฐ๋ผ ํ
ํ๋ฆฟ์ ๋ฟ๋ ค์ค ์ผ์ข
์ ๋ถ๋ชจ ํ
ํ๋ฆฟ์ ์ค์ ํ๋ ํ์ผ์ด ๋๊ฒ ์ต๋๋ค. client/main-layout.js ์ ํ์ผ์ ๋ง๋ค๊ณ ๋ด์ฉ์ ์
๋ ฅํด ์ฃผ์ธ์.</p>
<p><code>main-layout.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><template name="mainLayout"></div><div class="line"> <div class="container"></div><div class="line"> {{> Template.dynamic template=content }}</div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๋ค์์ผ๋ก ์๋ ์์ค๋ค์ ๊ฐ๊ฐ login.html, register.html ๊ทธ๋ฆฌ๊ณ home.html๋ก ์ด๋ฃจ์ด์ง ๊ธฐ๋ณธ ํ์ด์ง๊ฐ ๋๊ฒ ์ต๋๋ค. </p>
<p>์ฐธ๊ณ ๋ก ์๋์ ๊ฐ์ด <code>pathFor 'login'</code> ์ด๋ ๊ฒ a ํ๊ทธ์ ์
๋ ฅํด ์ฃผ๋ฉด <a href="http://localhost:3000/login" target="_blank" rel="noopener">http://localhost:3000/login</a> ์ฒ๋ผ ์ฃผ์์ + ์ด๋ํ url ํํ์ ๋งํฌ ์ฃผ์๋ฅผ ๋ง๋ค์ด ์ฃผ๊ฒ ๋๋ ๋ฌธ๋ฒ์
๋๋ค. </p>
<p>์ด ๊ธฐ๋ฅ์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์๋ ํจํค์ง๊ฐ ํ์ํฉ๋๋ค. </p>
<blockquote>
<p>์ค์น ํจํค์ง</p>
<ul>
<li>meteor add arillo:flow-router-helpers</li>
</ul>
</blockquote>
<p><code>client/home.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><template name="home"></div><div class="line"> <div class="col-md-8 col-md-offset-2"></div><div class="line"> <div class="col-md-12"></div><div class="line"> <div class="col-md-12"></div><div class="line"> <h2>ํ์ํฉ๋๋ค.</h2></div><div class="line"> <hr/></div><div class="line"> </div></div><div class="line"> <div class="col-md-6"></div><div class="line"> <a href="{{pathFor 'login'}}" class="btn btn-primary btn-lg btn-block">Go Login</a></div><div class="line"> </div></div><div class="line"> <div class="col-md-6"></div><div class="line"> <a href="{{pathFor 'register'}}" class="btn btn-success btn-lg btn-block">Go Register</a></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p><code>client/register.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><template name="register"></div><div class="line"> <h1>Register Page</h1></div><div class="line"></template></div></pre></td></tr></table></figure>
<p><code>client/login.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><template name="login"></div><div class="line"> <h1>Login page</h1></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>์ด์ ์ค์ ์ด ์๋ฃ ๋์์ต๋๋ค. ๊ธฐ๋ณธ ์ฃผ์์ธ localhost:3000/ ์ ๋ธ๋ผ์ฐ์ ์ ์
๋ ฅํ๊ณ ํ๋ฉด์ด ๋์ค๋์ง ํ์ธํด ๋ณด์ธ์. ๊ทธ๋ฆฌ๊ณ localhost:3000/login , localhost:3000/register ๋ก ์ฃผ์๋ฅผ ๋ณ๊ฒฝํด ํด๋นํ์ด์ง๋ก ์ ์ด๋ํ๋์ง ํ์ธ ๋ณด์๋ฉด ๋ฉ๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/0yllbkf5fFZcn0bBoht3mxG4zkZpQlE_cIfNVKvW7GE2Mi0_x5RKnxqoJbQtSEYjCm5Bp1yLNPPnvCeeRRA4jOugmSVIaEizhe0TH1vSTIUGBwToXJIIRAoZAr8ekmxmnYSTiMLYBbRRwGSreU5hMdYQefcC8oIiY1hO2RynG6sZFD8xuxd1u3An1Y8kJTEyQk3Mli7YxZBoNW648P5LrJxhsgZPxP5bFQSOUDXL_tXBaXuYpJqBCb2rVO27p89VOgfO8VgBrXF8vRKigGvGBmO5oyGcHfe3ELWcdESFQgSj3U_V7wRzFx4QZ00FgOs3W-URZxInesRvF63ZMTwWdVBW49W8_glHFTKikp-nOTxMhJBnImshQKUcTbBuiJduzs3sPqhG6vLhEBn3e_6-ZOmXWPX1qFRFDq95TgBjozhBvNFPJpU_ZWYR8AyE43EnlbT4acjix2XWbaWy3gViExLGspiMTOzi7N3R--SjnHRHwptzym1dQ1O-d3DjdHUooGItgWqgKcQvW08qDkuGmGtVCI18LhzuUdF279bV63lv6P0pLDwAKu0i66uyZx2XSsR48OazYoYX4gAHGira61qfHgtkTsPuECYWApx-TtorWvfPwTr4gQ=w890-h638-no"></p><p style="text-align: center;">[๋ผ์ฐํ
ํ๋ฉด]</p><p></p>
<hr>
<h3 id="3-ํ์๊ฐ์
"><a href="#3-ํ์๊ฐ์
" class="headerlink" title="3. ํ์๊ฐ์
"></a>3. ํ์๊ฐ์
</h3><p>์ด์ ํ์ ๊ฐ์
ํผ๊ณผ ๋ก๊ทธ์ธ ํผ์ ์์ฑํ๊ฒ ์ต๋๋ค.<br>์ฐ์ ์๋ ์์ค๋ ๋ก๊ทธ์ธ ํ์ผ์
๋๋ค. </p>
<p><code>client/login.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div></pre></td><td class="code"><pre><div class="line"><template name="login"></div><div class="line"></div><div class="line"> <div class="container"></div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <h2>METEOR ACCOUNTS</h2></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"> <span class="span-or">or</span></div><div class="line"> <div class="col-xs-12 button-box-1"></div><div class="line"> <a href="{{pathFor 'register'}}" class="top-button ">ํ์๊ฐ์
</a></div><div class="line"> <a href="#null" class="top-button top-button-selected">๋ก๊ทธ์ธ</a></div><div class="line"> </div></div><div class="line"> <div class="col-xs-12 button-box-2"></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-left"></div><div class="line"> <button name="facebook" class="btn btn-primary button-full button-facebook">facebook</button></div><div class="line"> </div></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-right"></div><div class="line"> <button name="google" class="btn btn-primary button-full button-google">google</button></div><div class="line"> </div></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-left"></div><div class="line"> <button name="twitter" class="btn btn-primary button-full button-twitter">twitter</button></div><div class="line"> </div></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-right"></div><div class="line"> <button name="kakao" class="btn btn-primary button-full button-kakao">kakao</button></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> <form class="col-md-12 panel-body-inner"></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" name="user-email" class="form-control account-text-form-1" placeholder="๊ฐ์
์ด๋ฉ์ผ"></div><div class="line"> </div></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" name="user-pwasword" class="form-control account-text-form-1" placeholder="๋น๋ฐ๋ฒํธ"></div><div class="line"> </div></div><div class="line"> </form></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="btn-singIn" class="btn btn-success btn-lg btn-block button">๋ก๊ทธ์ธ</button></div><div class="line"> <a href="{{pathFor 'recover'}}" class="a-right" >๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ</a></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div><div class="line"></template></div></pre></td></tr></table></figure>
<p>๋ก๊ทธ์ธ ํ์ด์ง๋ฅผ ์
๋ ฅํ๊ณ โlocalhost:3000/loginโ ์ ์ ์ํ๋ฉด ์๋์ ๊ฐ์ ํ๋ฉด์ ๋ณด์ฌ์ค๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/OEydsReV1cWjwbaYsdBsSYvB1o6hnHEnHEvR5IxeNuiZiQbURGN3uf8cnRONQalyGtGjqi6-R9cA7al-bhp6A8caALjO9BB-qW-AQ74g079k2rF7uTHYbCec6oUAf1L12MyCWEfCccJ01rZQsuUnL2PK9zE1oNXZiQxCsxLS4xqV_0bmepn4RoK-KpuEDCExMtEj6jDdGup8WPvi9ghEYCeRtI2A65RuRNyk_ZX67kvmkky4DRaLR0AdQdjEwf98lC6Klr1E5druaA2OBvle7MQtCz0iJDMtRGytNi5MTxzdomsghq7CBRjTz_Ny1gGHqff9uufEk_K39c3cOPnUU7W4t_udN9SG4RJ39CKX6n50VgtJjH3kmmND3Czbux_m32KRbZPbh9ipDhMdIsFa8hdaKVPZn6LTyRefU00DvFTg1I48wcwbDJgaOJRvWdcxHP88o_9hTocQJB9HPtGuYw4BuPanYkpXua1LVt7c7kdFtIlsQlnhtQV5MmugJT5zhgtBHjt4XO0XmP0D1deMJ4uhhv5iVFmJQs6o0Vw7x8xMf4gu2IK1ET314GgVa95n-YVHO32Gsv9vhQBYT57qxvswq04mB8JzXEyqbmqjeWHSoG8p7KZ7JgrT1O6NQ25a3YWL_reGXqhgIQyi1Nb7BKjvQdf2gQLIisfUab76sF0=w639-h602-no"></p><p style="text-align: center;">[๋ก๊ทธ์ธํผ ํ๋ฉด]</p><p></p>
<p>๋ค์์ ํ์๊ฐ์
ํผ ๊ด๋ จ ์์ค์
๋๋ค. </p>
<p><code>client/register.html</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div></pre></td><td class="code"><pre><div class="line"><template name="register"></div><div class="line"> <div class="panel panel-default col-md-6 col-md-offset-3 panel-custom"></div><div class="line"> <div class="panel-heading text_center"></div><div class="line"> <h2>METEOR ACCOUNTS</h2></div><div class="line"> </div></div><div class="line"> <div class="panel-body panel-body-set"></div><div class="line"> <span class="span-or">or</span></div><div class="line"> <div class="col-xs-12 button-box-1"></div><div class="line"> <a href="#null" class="top-button top-button-selected">ํ์๊ฐ์
</a></div><div class="line"> <a href="{{pathFor 'login'}}" class="top-button">๋ก๊ทธ์ธ</a></div><div class="line"> </div></div><div class="line"> <div class="col-xs-12 button-box-2"></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-left"></div><div class="line"> <button name="facebook" class="btn btn-primary button-full button-facebook">facebook</button></div><div class="line"> </div></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-right"></div><div class="line"> <button class="btn btn-primary button-full button-google">google</button></div><div class="line"> </div></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-left"></div><div class="line"> <button class="btn btn-primary button-full button-twitter">twitter</button></div><div class="line"> </div></div><div class="line"> <div class="col-xs-6 button-box-2-inner button-box-right"></div><div class="line"> <button name="kakao" class="btn btn-primary button-full button-kakao">kakao</button></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> <form class="col-xs-12 panel-body-inner"></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" name="user-email" class="form-control account-text-form-1" placeholder="๊ฐ์
์ด๋ฉ์ผ"></div><div class="line"> </div></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" name="user-password" class="form-control account-text-form-1" placeholder="๋น๋ฐ๋ฒํธ"></div><div class="line"> </div></div><div class="line"> <div class="form-group"></div><div class="line"> <input type="text" name="user-passwordAgain" class="form-control account-text-form-1" placeholder="๋น๋ฐ๋ฒํธ ํ์ธ"></div><div class="line"> </div></div><div class="line"> <div class="form-group col-xs-6 panel-body-inner-box-1"></div><div class="line"> <input type="text" name="user-lastName" class="form-control account-text-form-2" placeholder="์ฑ"></div><div class="line"> </div></div><div class="line"> <div class="form-group col-xs-6 panel-body-inner-box-2"></div><div class="line"> <input type="text" name="user-firstName" class="form-control account-text-form-2" placeholder="์ด๋ฆ"></div><div class="line"> </div></div><div class="line"> </form></div><div class="line"> <div class="form-group panel-body-inner bottom-padding"></div><div class="line"> <button name="btn-register" class="btn btn-success btn-lg btn-block button">๊ฐ์
ํ๊ธฐ</button></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></template></div></pre></td></tr></table></figure>
<p>ํ์๊ฐ์
ํผ ์ญ์ โlocalhost:3000/registerโ ์ ์ ์ํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๋ชจ์ต์ ๋ณด์ฌ์ค๋๋ค. </p>
<p><img src="https://lh3.googleusercontent.com/G3rObdtW8OeRcoJF1hwBjFslttmYxU_ErLXIrU5qtHULOSgaHaMpn-n_rzrwTfUhMs0pzJgLWogUmNOp2fKTpXERta9InsWydVyjq2SYFrY9DVWXMxbAmkcdi_AV6OGij7nB1CtGsMox4L01licd_D3bcJAeNREGViggIaaWcfeElA_Q0uT2Ean-b9GtjU6ffBLzCtsbYVT1tX1NWKbgVDIdaDeEMmhpOtflpgx3x00yxN7DRpxqye4jV9VV4QnDskT0irDUuzUn26-HpnYeg0oUfHU9rNGKSkPT-WCUx2oWNFngklAsZBuBad9bxKY24tS-fN3geI4LbdHU19wCtgFyM71RavARBtr4U5i-Gr2J9C5P2efM6Mk8xFSwy41NbC7gqfRaIKVWV9ZHveRNpoBsXxhvSwDr_PubQTPxR9XMdf6A7tsHZhSAVu3lO44yLg9y5TtIecC2NVprYwWxqitjUygLIzvS_94bdfrrsG4A0LummWDZbpAjaMA28xQr6B5--_dhLrd11NXKOeZk0DmS6-0IgnWtnVySD1cDjyKrraC7QOmVEqf8_gXBMR0JJsLhC4WrXzSVg27P0xTTrDgD6AzzvDalLxY1rs5uc2LRXfyVkRjcHqCtxFx5i3zpyRU23UlZRauwpVRxyMoYsUiip60r8if5vxC4fyKViNM=w631-h714-no"></p><p style="text-align: center;">[ํ์๊ฐ์
ํผ ํ๋ฉด]</p><p></p>
<p>์ ์ด๋ ๊ฒ ๊ธฐ๋ณธ์ ์ธ account ์ธํ์ ๋ค ๋ง๋ค์ด ๋ดค๋๋ฐ์. ์ด์ ๋ค์ ๊ฐ์ข์์๋ ๋ณธ๊ฒฉ์ ์ผ๋ก ํ์๊ฐ์
, ๋ก๊ทธ์ธ ๋ฑ์ด ์ค์ ์๋ํ๋๋ก ๋ง๋ค์ด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. </p>
<p>๊ทธ๋ผ ๋ค์ ๊ฐ์ข๋ ๊ธฐ๋ํด์ฃผ์ธ์ ^^</p>
]]></content>
<summary type="html">
<h3 id="0-๊ฐ์ข-์๊ฐ"><a href="#0-๊ฐ์ข-์๊ฐ" class="headerlink" title="0. ๊ฐ์ข ์๊ฐ"></a>0. ๊ฐ์ข ์๊ฐ</h3><p>ํ์คํ ํ๋ซํผ์ธ meteor๋ ๊ธฐ๋ณธ์ ์ผ๋ก account(๋ก๊ทธ์ธ, ํ์๊ฐ์
๋ฑ)์ ๋ํด์
</summary>
<category term="meteor, custom account, ๋ฏธํฐ์ด" scheme="http://freeseamew.github.io/tags/meteor-custom-account-%EB%AF%B8%ED%8B%B0%EC%96%B4/"/>
</entry>
</feed>