#include <LoginWidget.h>
Inherits Wt::WContainerWidget.
Public Member Functions | |
LoginWidget (WContainerWidget *parent=0) | |
Public Attributes | |
Wt::Signal< std::wstring, Dictionary > | loginSuccessful |
Private Slots | |
void | checkCredentials () |
void | startPlaying () |
Private Member Functions | |
void | confirmLogin (const std::wstring text) |
Private Attributes | |
WText * | IntroText |
WLineEdit * | Username |
WLineEdit * | Password |
WComboBox * | Language |
std::wstring | User |
Dictionary | Dict |
Definition at line 22 of file LoginWidget.h.
LoginWidget::LoginWidget | ( | WContainerWidget * | parent = 0 |
) |
Definition at line 21 of file LoginWidget.C.
00022 : 00023 WContainerWidget(parent) 00024 { 00025 setPadding(100, Left | Right); 00026 00027 WText *title = new WText("Login", this); 00028 title->decorationStyle().font().setSize(WFont::XLarge); 00029 00030 IntroText = 00031 new WText("<p>Hangman keeps track of the best players. To recognise " 00032 "you, we ask you to log in. If you never logged in before, " 00033 "choose any name and password. If you don't want to be in " 00034 "our database for some reason, use the 'guest/guest' " 00035 "account.</p>" 00036 "<p>Warning: hangman contains some words and " 00037 "pictures that may offend really young players.</p>", this); 00038 00039 WTable *layout = new WTable(this); 00040 WLabel *usernameLabel = new WLabel("User name: ", layout->elementAt(0, 0)); 00041 layout->elementAt(0, 0)->resize(WLength(14, WLength::FontEx), WLength::Auto); 00042 Username = new WLineEdit(layout->elementAt(0, 1)); 00043 usernameLabel->setBuddy(Username); 00044 00045 WLabel *passwordLabel = new WLabel("Password: ", layout->elementAt(1, 0)); 00046 Password = new WLineEdit(layout->elementAt(1, 1)); 00047 Password->setEchoMode(WLineEdit::Password); 00048 passwordLabel->setBuddy(Password); 00049 00050 WLabel *languageLabel = new WLabel("Language: ", layout->elementAt(2, 0)); 00051 Language = new WComboBox(layout->elementAt(2, 1)); 00052 Language->insertItem(0, "English words (18957 words)"); 00053 Language->insertItem(1, "Nederlandse woordjes (1688 woorden)"); 00054 languageLabel->setBuddy(Language); 00055 00056 new WBreak(this); 00057 00058 WPushButton *LoginButton = new WPushButton("Login", this); 00059 LoginButton->clicked().connect(SLOT( this, LoginWidget::checkCredentials)); }
void LoginWidget::checkCredentials | ( | ) | [private, slot] |
Definition at line 61 of file LoginWidget.C.
00062 { 00063 User = Username->text(); 00064 std::wstring pass = Password->text(); 00065 Dict = (Dictionary) Language->currentIndex(); 00066 00067 if (HangmanDb::validLogin(User, pass)) { 00068 confirmLogin(L"<p>Welcome back, " + User + L".</p>"); 00069 } else if (User == L"guest" && pass == L"guest") { 00070 confirmLogin(L"<p>Welcome guest, good luck.</p>"); 00071 } else if (HangmanDb::addUser(User, pass)) { 00072 confirmLogin(L"<p>Welcome, " 00073 + User + L". Good luck with your first game!</p>"); 00074 } else { 00075 IntroText 00076 ->setText("<p>You entered the wrong password, or the username " 00077 "combination is already in use. If you are a returning " 00078 "user, please try again. If you are a new user, please " 00079 "try a different name.</p>"); 00080 IntroText->decorationStyle().setForegroundColor(Wt::red); 00081 Username->setText(""); 00082 Password->setText(""); 00083 } 00084 }
void LoginWidget::confirmLogin | ( | const std::wstring | text | ) | [private] |
Definition at line 86 of file LoginWidget.C.
00087 { 00088 clear(); 00089 00090 WText *title = new WText("Loging successful", this); 00091 title->decorationStyle().font().setSize(WFont::XLarge); 00092 00093 new WText(text, this); 00094 (new WPushButton("Start playing", this)) 00095 ->clicked().connect(SLOT(this, LoginWidget::startPlaying)); 00096 }
void LoginWidget::startPlaying | ( | ) | [private, slot] |
Definition at line 98 of file LoginWidget.C.
00099 { 00100 loginSuccessful.emit(User, Dict); 00101 }
Dictionary LoginWidget::Dict [private] |
Definition at line 40 of file LoginWidget.h.
WText* LoginWidget::IntroText [private] |
Definition at line 34 of file LoginWidget.h.
WComboBox* LoginWidget::Language [private] |
Definition at line 37 of file LoginWidget.h.
Wt::Signal<std::wstring, Dictionary> LoginWidget::loginSuccessful |
Definition at line 27 of file LoginWidget.h.
WLineEdit* LoginWidget::Password [private] |
Definition at line 36 of file LoginWidget.h.
std::wstring LoginWidget::User [private] |
Definition at line 39 of file LoginWidget.h.
WLineEdit* LoginWidget::Username [private] |
Definition at line 35 of file LoginWidget.h.