Repository navigation
Expand file tree
/
Copy pathtactioncontroller.cpp
More file actions
1030 lines (851 loc) · 26 KB
/
Copy pathtactioncontroller.cpp
File metadata and controls
1030 lines (851 loc) · 26 KB
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2010-2015, AOYAMA Kazuharu
* All rights reserved.
*
* This software may be used and distributed according to the terms of
* the New BSD License, which is incorporated herein by reference.
*/
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QMetaMethod>
#include <QMetaType>
#include <QTextCodec>
#include <QCryptographicHash>
#include <QMutexLocker>
#include <QDomDocument>
#include <TActionController>
#include <TWebApplication>
#include <TAppSettings>
#include <TDispatcher>
#include <TActionView>
#include <TSession>
#include <TAbstractUser>
#include <TActionContext>
#include <TFormValidator>
#include "tsessionmanager.h"
#include "ttextview.h"
#define FLASH_VARS_SESSION_KEY "_flashVariants"
#define LOGIN_USER_NAME_KEY "_loginUserName"
/*!
\class TActionController
\~english
\brief The TActionController class is the base class of all action
controllers.
\~japanese
\brief TActionControllerはアクションコントローラのベースとなるクラス
*/
/*!
\~english
\brief Constructor.
\~japanese
\brief コンストラクタ
*/
TActionController::TActionController()
: QObject(),
TAbstractController(),
statCode(Tf::OK), // 200 OK
rendered(false),
layoutEnable(true),
rollback(false)
{
// Default content type
setContentType("text/html");
}
/*!
\fn TActionController::~TActionController();
\~english
\brief Destructor.
\~japanese
\brief デストラクタ
*/
/*!
\~english
Returns the controller name.
\~japanese
コントローラ名を返す
*/
QString TActionController::name() const
{
if (ctrlName.isEmpty()) {
ctrlName = className().remove(QRegExp("Controller$"));
}
return ctrlName;
}
/*!
\fn QString TActionController::className() const
\~english
Returns the class name.
\~japanese
クラス名を返す
*/
/*!
\fn QString TActionController::activeAction() const
\~english
Returns the active action name.
\~japanese
アクティブなアクション名を返す
*/
/*!
\fn const THttpRequest &TActionController::httpRequest() const;
\~english
Returns the HTTP request being executed.
\~japanese
HTTPリクエストへの参照を返す
*/
const THttpRequest &TActionController::httpRequest() const
{
return Tf::currentContext()->httpRequest();
}
/*!
\fn THttpRequest &TActionController::httpRequest();
\~english
Returns the HTTP request being executed.
\~japanese
HTTPリクエストへの参照を返す
*/
THttpRequest &TActionController::httpRequest()
{
return Tf::currentContext()->httpRequest();
}
/*!
\fn const THttpResponse &TActionController::httpResponse() const;
\~english
Returns a HTTP response to be sent.
\~japanese
送信するHTTPレスポンスへの参照を返す
*/
/*!
\fn THttpResponse &TActionController::httpResponse();
\~english
Returns a HTTP response to be sent.
\~japanese
送信するHTTPレスポンスへの参照を返す
*/
/*!
\~english
Sets the layout template to \a layout.
\~japanese
レイアウトテンプレート\a layout を設定する
\~
\sa layout()
*/
void TActionController::setLayout(const QString &layout)
{
if (!layout.isNull()) {
layoutName = layout;
}
}
/*!
\~english
Adds the cookie to the internal list of cookies.
\~japanese
クッキーをHTTPレスポンスに追加する
*/
bool TActionController::addCookie(const TCookie &cookie)
{
QByteArray name = cookie.name();
if (name.isEmpty() || name.contains(';') || name.contains(',') || name.contains(' ') || name.contains('\"')) {
tError("Invalid cookie name: %s", name.data());
return false;
}
cookieJar.addCookie(cookie);
response.header().removeAllRawHeaders("Set-Cookie");
for (QListIterator<TCookie> i(cookieJar.allCookies()); i.hasNext(); ) {
response.header().addRawHeader("Set-Cookie", i.next().toRawForm());
}
return true;
}
/*!
\~english
Adds the cookie to the internal list of cookies.
\~japanese
クッキーをHTTPレスポンスに追加する
*/
bool TActionController::addCookie(const QByteArray &name, const QByteArray &value, const QDateTime &expire,
const QString &path, const QString &domain, bool secure, bool httpOnly)
{
TCookie cookie(name, value);
cookie.setExpirationDate(expire);
cookie.setPath(path);
cookie.setDomain(domain);
cookie.setSecure(secure);
cookie.setHttpOnly(httpOnly);
return addCookie(cookie);
}
/*!
\~english
Returns the authenticity token.
\~japanese
HTTPリクエストの正当性を検証するためのトークンを返す
*/
QByteArray TActionController::authenticityToken() const
{
if (Tf::appSettings()->value(Tf::SessionStoreType).toString().toLower() == QLatin1String("cookie")) {
QString key = Tf::appSettings()->value(Tf::SessionCsrfProtectionKey).toString();
QByteArray csrfId = session().value(key).toByteArray();
if (csrfId.isEmpty()) {
throw RuntimeException("CSRF protectionsession value is empty", __FILE__, __LINE__);
}
return csrfId;
} else {
return QCryptographicHash::hash(session().id() + Tf::appSettings()->value(Tf::SessionSecret).toByteArray(), QCryptographicHash::Sha1).toHex();
}
}
/*!
\~english
Sets the HTTP session to \a session.
\~japanese
セッション \a session を設定する
*/
void TActionController::setSession(const TSession &session)
{
T_TRACEFUNC("");
sessionStore = session;
}
/*!
\~english
Sets CSRF protection informaion into \a session. Internal use.
\~japanese
CSRF対策の情報をセッションに設定する (内部使用)
*/
void TActionController::setCsrfProtectionInto(TSession &session)
{
if (Tf::appSettings()->value(Tf::SessionStoreType).toString().toLower() == QLatin1String("cookie")) {
QString key = Tf::appSettings()->value(Tf::SessionCsrfProtectionKey).toString();
session.insert(key, TSessionManager::instance().generateId()); // it's just a random value
}
}
/*!
Returns the list of all available controllers.
*/
const QStringList &TActionController::availableControllers()
{
static QStringList controllers;
static QMutex mutex;
if (controllers.isEmpty()) {
QMutexLocker lock(&mutex);
for (int i = QMetaType::User; ; ++i) {
const char *name = QMetaType::typeName(i);
if (!name)
break;
QString c(name);
if (c.endsWith("controller"))
controllers << c;
}
}
return controllers;
}
const QStringList &TActionController::disabledControllers()
{
static const QStringList disabledNames = { "application" };
return disabledNames;
}
QString TActionController::loginUserNameKey()
{
return QLatin1String(LOGIN_USER_NAME_KEY);
}
/*!
\~english
Verifies the HTTP request \a request.
\~japanese
HTTPリクエストを検証する
*/
bool TActionController::verifyRequest(const THttpRequest &request) const
{
if (!csrfProtectionEnabled()) {
return true;
}
if (Tf::appSettings()->value(Tf::SessionStoreType).toString().toLower() != QLatin1String("cookie")) {
if (session().id().isEmpty()) {
throw SecurityException("Request Forgery Protection requires a valid session", __FILE__, __LINE__);
}
}
QByteArray postAuthToken = request.parameter("authenticity_token").toLatin1();
if (postAuthToken.isEmpty()) {
throw SecurityException("Authenticity token is empty", __FILE__, __LINE__);
}
tSystemDebug("postAuthToken: %s", postAuthToken.data());
return (postAuthToken == authenticityToken());
}
/*!
\~english
Renders the template of the action \a action with the layout \a layout.
\~japanese
レイアウト \a layout を適用し、アクション \a action のテンプレートを描画する
*/
bool TActionController::render(const QString &action, const QString &layout)
{
T_TRACEFUNC("");
if (rendered) {
tWarn("Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return false;
}
rendered = true;
// Creates view-object and displays it
TDispatcher<TActionView> viewDispatcher(viewClassName(action));
setLayout(layout);
response.setBody(renderView(viewDispatcher.object()));
return !response.isBodyNull();
}
/*!
\~english
Renders the template given by \a templateName with the layout \a layout.
\~japanese
レイアウト \a layout を適用し、テンプレート \a templateName を描画する
*/
bool TActionController::renderTemplate(const QString &templateName, const QString &layout)
{
T_TRACEFUNC("");
if (rendered) {
tWarn("Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return false;
}
rendered = true;
// Creates view-object and displays it
QStringList names = templateName.split("/");
if (names.count() != 2) {
tError("Invalid patameter: %s", qPrintable(templateName));
return false;
}
TDispatcher<TActionView> viewDispatcher(viewClassName(names[0], names[1]));
setLayout(layout);
response.setBody(renderView(viewDispatcher.object()));
return (!response.isBodyNull());
}
/*!
\~english
Renders the text \a text with the layout \a layout.
\~japanese
レイアウト \a layout を適用し、テキストを描画する
*/
bool TActionController::renderText(const QString &text, bool layoutEnable, const QString &layout)
{
T_TRACEFUNC("");
if (rendered) {
tWarn("Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return false;
}
rendered = true;
// Creates TTextView object and displays it
setLayout(layout);
setLayoutEnabled(layoutEnable);
TTextView *view = new TTextView(text);
response.setBody(renderView(view));
delete view;
return (!response.isBodyNull());
}
static QDomElement createDomElement(const QString &name, const QVariantMap &map, QDomDocument &document)
{
QDomElement element = document.createElement(name);
for (QMapIterator<QString, QVariant> it(map); it.hasNext(); ) {
it.next();
QDomElement tag = document.createElement(it.key());
element.appendChild(tag);
QDomText text = document.createTextNode(it.value().toString());
tag.appendChild(text);
}
return element;
}
/*!
Renders the XML document \a document.
*/
bool TActionController::renderXml(const QDomDocument &document)
{
QByteArray xml;
QTextStream ts(&xml);
ts.setCodec("UTF-8");
document.save(ts, 1, QDomNode::EncodingFromTextStream);
return sendData(xml, "text/xml");
}
/*!
Renders the \a map as XML document.
*/
bool TActionController::renderXml(const QVariantMap &map)
{
QDomDocument doc;
QDomElement root = doc.createElement("map");
doc.appendChild(root);
root.appendChild(createDomElement("map", map, doc));
return renderXml(doc);
}
/*!
Renders the list of variants \a list as XML document.
*/
bool TActionController::renderXml(const QVariantList &list)
{
QDomDocument doc;
QDomElement root = doc.createElement("list");
doc.appendChild(root);
for (QListIterator<QVariant> it(list); it.hasNext(); ) {
QVariantMap map = it.next().toMap();
root.appendChild(createDomElement("map", map, doc));
}
return renderXml(doc);
}
/*!
Renders the list of strings \a list as XML document.
*/
bool TActionController::renderXml(const QStringList &list)
{
QDomDocument doc;
QDomElement root = doc.createElement("list");
doc.appendChild(root);
for (QStringListIterator it(list); it.hasNext(); ) {
const QString &str = it.next();
QDomElement tag = doc.createElement("string");
root.appendChild(tag);
QDomText text = doc.createTextNode(str);
tag.appendChild(text);
}
return renderXml(doc);
}
/*!
\~english
Returns the rendering data of the partial template given by \a templateName.
\~japanese
部分テンプレート \a templateName に変数 \a vars を設定した描画データを返す
*/
QString TActionController::getRenderingData(const QString &templateName, const QVariantMap &vars)
{
T_TRACEFUNC("templateName: %s", qPrintable(templateName));
// Creates view-object
QStringList names = templateName.split("/");
if (names.count() != 2) {
tError("Invalid patameter: %s", qPrintable(templateName));
return QString();
}
TDispatcher<TActionView> viewDispatcher(viewClassName(names[0], names[1]));
TActionView *view = viewDispatcher.object();
if (!view) {
return QString();
}
QVariantMap map = allVariants();
for (QMapIterator<QString, QVariant> i(vars); i.hasNext(); ) {
i.next();
map.insert(i.key(), i.value()); // item's value of same key is replaced
}
view->setController(this);
view->setVariantMap(map);
return view->toString();
}
/*!
\~english
Renders the \a view view.
\~japanese
ビューを描画する
*/
QByteArray TActionController::renderView(TActionView *view)
{
T_TRACEFUNC("view: %p layout: %s", view, qPrintable(layout()));
if (!view) {
tSystemError("view null pointer. action:%s", qPrintable(activeAction()));
return QByteArray();
}
view->setController(this);
view->setVariantMap(allVariants());
if (!layoutEnabled()) {
// Renders without layout
tSystemDebug("Renders without layout");
return Tf::app()->codecForHttpOutput()->fromUnicode(view->toString());
}
// Displays with layout
QString lay = (layout().isNull()) ? name().toLower() : layout().toLower();
TDispatcher<TActionView> layoutDispatcher(layoutClassName(lay));
TActionView *layoutView = layoutDispatcher.object();
TDispatcher<TActionView> defLayoutDispatcher(layoutClassName("application"));
if (!layoutView) {
if (!layout().isNull()) {
tSystemDebug("Not found layout: %s", qPrintable(layout()));
return QByteArray();
} else {
// Use default layout
layoutView = defLayoutDispatcher.object();
if (!layoutView) {
tSystemDebug("Not found default layout. Renders without layout.");
return Tf::app()->codecForHttpOutput()->fromUnicode(view->toString());
}
}
}
// Renders layout
layoutView->setVariantMap(allVariants());
layoutView->setController(this);
layoutView->setSubActionView(view);
return Tf::app()->codecForHttpOutput()->fromUnicode(layoutView->toString());
}
/*!
Renders a static error page with the status code, which page is [statusCode].html
in the \a public directory.
*/
bool TActionController::renderErrorResponse(int statusCode)
{
bool ret = false;
if (rendered) {
tWarn("Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return ret;
}
QString file = Tf::app()->publicPath() + QString::number(statusCode) + QLatin1String(".html");
if (QFileInfo(file).exists()) {
ret = sendFile(file, "text/html", "", false);
} else {
response.setBody("");
}
setStatusCode(statusCode);
rendered = true;
return ret;
}
/*!
\~english
Returns the layout class name. Internal use.
\~japanese
レイアウトクラス名を返す
*/
QString TActionController::layoutClassName(const QString &layout)
{
return QLatin1String("layouts_") + layout + "View";
}
/*!
\~english
Returns the class name of the partial view. Internal use.
\~japanese
部分ビューのクラス名を返す(内部使用)
*/
QString TActionController::partialViewClassName(const QString &partial)
{
return QLatin1String("partial_") + partial + "View";
}
/*!
\~english
Redirects to the URL \a url.
\~japanese
URL \a url へリダイレクトする
*/
void TActionController::redirect(const QUrl &url, int statusCode)
{
if (rendered) {
tError("Unable to redirect. Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return;
}
rendered = true;
setStatusCode(statusCode);
response.header().setRawHeader("Location", url.toEncoded());
response.setBody(QByteArray("<html><body>redirected.</body></html>"));
response.header().setContentType("text/html");
// Enable flash-variants
QVariant var;
var.setValue(flashVars);
sessionStore.insert(FLASH_VARS_SESSION_KEY, var);
}
/*!
\~english
Sends the file \a filePath as HTTP response.
\~japanese
HTTPレスポンスとして、ファイル \a filePath の内容を送信する
*/
bool TActionController::sendFile(const QString &filePath, const QByteArray &contentType, const QString &name, bool autoRemove)
{
if (rendered) {
tWarn("Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return false;
}
rendered = true;
if (!name.isEmpty()) {
QByteArray filename;
filename += "attachment; filename=\"";
filename += name.toUtf8();
filename += '"';
response.header().setRawHeader("Content-Disposition", filename);
}
response.setBodyFile(filePath);
response.header().setContentType(contentType);
if (autoRemove)
setAutoRemove(filePath);
return true;
}
/*!
\~english
Sends the data \a data as HTTP response.
\~japanese
HTTPレスポンスとして、データ \a data を送信する
*/
bool TActionController::sendData(const QByteArray &data, const QByteArray &contentType, const QString &name)
{
if (rendered) {
tWarn("Has rendered already: %s", qPrintable(className() + '#' + activeAction()));
return false;
}
rendered = true;
if (!name.isEmpty()) {
QByteArray filename;
filename += "attachment; filename=\"";
filename += name.toUtf8();
filename += '"';
response.header().setRawHeader("Content-Disposition", filename);
}
response.setBody(data);
response.header().setContentType(contentType);
return true;
}
/*!
\~english
Exports the all flash variants.
\~japanese
すべてのフラッシュオブジェクトをエクスポートする
*/
void TActionController::exportAllFlashVariants()
{
QVariant var = sessionStore.take(FLASH_VARS_SESSION_KEY);
if (!var.isNull()) {
exportVariants(var.toMap());
}
}
/*!
Validates the access of the user \a user. Returns true if the user
access is allowed by rule; otherwise returns false.
@sa setAccessRules(), TAccessValidator::validate()
*/
bool TActionController::validateAccess(const TAbstractUser *user)
{
if (TAccessValidator::accessRules.isEmpty()) {
setAccessRules();
}
return TAccessValidator::validate(user);
}
/*!
\~english
Logs the user \a user in to the system.
This is a virtual function.
\~japanese
ユーザ \a user をシステムへログインさせる
\~
\sa userLogout()
*/
bool TActionController::userLogin(const TAbstractUser *user)
{
if (!user) {
tSystemError("userLogin: null specified");
return false;
}
if (user->identityKey().isEmpty()) {
tSystemError("userLogin: identityKey empty");
return false;
}
if (isUserLoggedIn()) {
tSystemWarn("userLogin: Duplicate login detected. Force logout [user:%s]", qPrintable(identityKeyOfLoginUser()));
}
session().insert(LOGIN_USER_NAME_KEY, user->identityKey());
return true;
}
/*!
\~english
Logs out of the system.
This is a virtual function.
\~japanese
ユーザをログアウトさせる
\~
\sa userLogin()
*/
void TActionController::userLogout()
{
session().take(LOGIN_USER_NAME_KEY);
}
/*!
\~english
Returns true if a user is logged in to the system; otherwise returns false.
This is a virtual function.
\~japanese
ユーザがログインしている場合は true を返し、そうでない場合は false を返す
\~
\sa userLogin()
*/
bool TActionController::isUserLoggedIn() const
{
return session().contains(LOGIN_USER_NAME_KEY);
}
/*!
\~english
Returns the identity key of the user, i.e., TAbstractUser object,
logged in.
This is a virtual function.
\~japanese
ログインユーザのアイデンティティキーを返す
\~
\sa userLogin()
*/
QString TActionController::identityKeyOfLoginUser() const
{
return session().value(LOGIN_USER_NAME_KEY).toString();
}
/*!
\~english
Sets the automatically removing file.
The file \a filePath is removed when the context is extinguished,
after replied the HTTP response.
\~japanese
自動削除するファイルを設定する
HTTPレスポンスを返却したあとコンテキストが消滅する際に、ファイル
\a filePath が削除される
*/
void TActionController::setAutoRemove(const QString &filePath)
{
if (!filePath.isEmpty() && !autoRemoveFiles.contains(filePath))
autoRemoveFiles << filePath;
}
/*!
\~english
Returns the client address of the current session.
\~japanese
セッションをはっているクライアントのアドレスを返す
*/
QHostAddress TActionController::clientAddress() const
{
return Tf::currentContext()->clientAddress();
}
/*!
\~english
Sets the validation errors to flash variant.
\~japanese
バリデーションエラーとなったメッセージをフラッシュ変数へ設定する
*/
void TActionController::setFlashValidationErrors(const TFormValidator &v, const QString &prefix)
{
for (QStringListIterator i(v.validationErrorKeys()); i.hasNext(); ) {
const QString &key = i.next();
QString msg = v.errorMessage(key);
setFlash(prefix + key, msg);
}
}
void TActionController::sendTextToWebSocket(int sid, const QString &text)
{
QVariantList info;
info << sid << text;
taskList << qMakePair((int)SendTextTo, QVariant(info));
}
void TActionController::sendBinaryToWebSocket(int sid, const QByteArray &binary)
{
QVariantList info;
info << sid << binary;
taskList << qMakePair((int)SendBinaryTo, QVariant(info));
}
void TActionController::closeWebSokcet(int sid, int closeCode)
{
QVariantList info;
info << sid << closeCode;
taskList << qMakePair((int)SendCloseTo, QVariant(info));
}
/*!
\fn const TSession &TActionController::session() const;
Returns the current HTTP session, allows associating information
with individual visitors.
\sa setSession(), sessionEnabled()
*/
/*!
\fn TSession &TActionController::session();
Returns the current HTTP session, allows associating information
with individual visitors.
\sa setSession(), sessionEnabled()
*/
/*!
\fn virtual bool TActionController::sessionEnabled() const
Must be overridden by subclasses to enable a HTTP session. The
function must return \a false to disable a session. This function
returns \a true.
\sa session()
*/
/*!
\fn virtual bool TActionController::csrfProtectionEnabled() const;
Must be overridden by subclasses to disable CSRF protection. The
function must return \a false to disable the protection. This function
returns \a true.
\sa exceptionActionsOfCsrfProtection()
*/
/*!
\fn virtual QStringList TActionController::exceptionActionsOfCsrfProtection() const;
Must be overridden by subclasses to return a string list of actions
excluded from CSRF protection when the protection is enabled.
\sa csrfProtectionEnabled()
*/
/*!
\fn virtual bool TActionController::transactionEnabled() const;
Must be overridden by subclasses to disable transaction mechanism.
The function must return \a false to disable the mechanism. This function
returns \a true.
*/
/*!
\fn void TActionController::setLayoutEnabled(bool enable);
Enables the layout mechanism if \a enable is true, otherwise disables it.
By default the layout mechanism is enabled, and a HTML response is
generated with using the current layout.
\sa layoutEnabled()
*/
/*!
\fn void TActionController::setLayoutDisabled(bool disable);
Disables the layout mechanism if \a disable is true, otherwise enables it.
By default the layout mechanism is enabled, and a HTML response is
generated with using the current layout.
\sa layoutEnabled()
*/
/*!
\fn QString TActionController::layout() const
Returns the name of the layout template.
\sa setLayout()
*/
/*!
\fn bool TActionController::layoutEnabled() const;
Returns \a true if the layout mechanism is enabled; otherwise
returns \a false.
\sa setLayoutEnabled()
*/
/*!
\fn QString TActionController::flash(const QString &name) const
Returns the flash message for \a name.
\sa setFlash()
*/
/*!
\fn void TActionController::setFlash(const QString &name, const QVariant &value)
Sets the flash message of \a name to \a value.
\sa flash()
*/
/*!
\fn void TActionController::setStatusCode(int code);
Sets the status code to \a code.
\sa statusCode()
*/
/*!
\fn int TActionController::statusCode() const
Returns the status code of the HTTP response to be sent.
\sa setStatusCode()
*/
/*!
\fn bool TActionController::preFilter()
This function is called before actions on the controller are performed,
therefore can be overridden by subclasses (controllers) to filter a HTTP
request. If the function returns false, a action on the controller is not
executed.
*/
/*!
\fn void TActionController::postFilter()
This function is called after actions on the controller are performed.
Can be overridden by subclasses (controllers) in order to post-processing
of actions on the controller.
*/