LoginWidget Class Reference

#include <LoginWidget.h>

Inheritance diagram for LoginWidget:

Inheritance graph
[legend]

List of all members.

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

WTextIntroText
WLineEditUsername
WLineEditPassword
WComboBoxLanguage
std::wstring User
Dictionary Dict


Detailed Description

Definition at line 22 of file LoginWidget.h.


Constructor & Destructor Documentation

LoginWidget::LoginWidget ( WContainerWidget parent = 0  ) 

Definition at line 21 of file LoginWidget.C.

00021                                                 :
00022    WContainerWidget(parent)
00023 {
00024    setPadding(100, Left | Right);
00025 
00026    WText *title = new WText("Login", this);
00027    title->decorationStyle().font().setSize(WFont::XLarge);
00028 
00029    IntroText =
00030       new WText("<p>Hangman keeps track of the best players. To recognise "
00031                 "you, we ask you to log in. If you never logged in before, "
00032                 "choose any name and password. If you don't want to be in "
00033                 "our database for some reason, use the 'guest/guest' "
00034                 "account.</p>"
00035                 "<p>Warning: hangman contains some words and "
00036                 "pictures that may offend really young players.</p>", this);
00037 
00038    WTable *layout = new WTable(this);
00039    WLabel *usernameLabel = new WLabel("User name: ", layout->elementAt(0, 0));
00040    layout->elementAt(0, 0)->resize(WLength(14, WLength::FontEx), WLength::Auto);
00041    Username = new WLineEdit(layout->elementAt(0, 1));
00042    usernameLabel->setBuddy(Username);
00043 
00044    WLabel *passwordLabel = new WLabel("Password: ", layout->elementAt(1, 0));
00045    Password = new WLineEdit(layout->elementAt(1, 1));
00046    Password->setEchoMode(WLineEdit::Password);
00047    passwordLabel->setBuddy(Password);
00048 
00049    WLabel *languageLabel = new WLabel("Language: ", layout->elementAt(2, 0));
00050    Language = new WComboBox(layout->elementAt(2, 1));
00051    Language->insertItem(0, "English words (18957 words)");
00052    Language->insertItem(1, "Nederlandse woordjes (1688 woorden)");
00053    languageLabel->setBuddy(Language);
00054 
00055    new WBreak(this);
00056 
00057    WPushButton *LoginButton = new WPushButton("Login", this);
00058    LoginButton->clicked().connect(SLOT( this, LoginWidget::checkCredentials));
00059 }


Member Function Documentation

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 (HangmanDb::addUser(User, pass)) {
00070       confirmLogin(L"<p>Welcome, "
00071                    + User + L". Good luck with your first game!</p>");
00072    } else {
00073       IntroText
00074         ->setText("<p>You entered the wrong password, or the username "
00075                   "combination is already in use. If you are a returning "
00076                   "user, please try again. If you are a new user, please "
00077                   "try a different name.</p>");
00078       IntroText->decorationStyle().setForegroundColor(Wt::red);
00079       Username->setText("");
00080       Password->setText("");
00081    }
00082 }

void LoginWidget::startPlaying (  )  [private, slot]

Definition at line 96 of file LoginWidget.C.

00097 {
00098    loginSuccessful.emit(User, Dict);
00099 }

void LoginWidget::confirmLogin ( const std::wstring  text  )  [private]

Definition at line 84 of file LoginWidget.C.

00085 {
00086    clear();
00087 
00088    WText *title = new WText("Loging successful", this);
00089    title->decorationStyle().font().setSize(WFont::XLarge);
00090 
00091    new WText(text, this);
00092    (new WPushButton("Start playing", this))
00093      ->clicked().connect(SLOT(this, LoginWidget::startPlaying));
00094 }


Member Data Documentation

Definition at line 27 of file LoginWidget.h.

Definition at line 34 of file LoginWidget.h.

Definition at line 35 of file LoginWidget.h.

Definition at line 36 of file LoginWidget.h.

Definition at line 37 of file LoginWidget.h.

std::wstring LoginWidget::User [private]

Definition at line 39 of file LoginWidget.h.

Definition at line 40 of file LoginWidget.h.


The documentation for this class was generated from the following files:

Generated on Tue Nov 3 15:34:40 2009 for Wt by doxygen 1.5.6