Wt examples 3.1.10
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
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 Member Functions

void confirmLogin (const std::wstring text)
void checkCredentials ()
void startPlaying ()

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.

                                                :
   WContainerWidget(parent)
{
   setPadding(100, Left | Right);

   WText *title = new WText("Login", this);
   title->decorationStyle().font().setSize(WFont::XLarge);

   IntroText =
      new WText("<p>Hangman keeps track of the best players. To recognise "
                "you, we ask you to log in. If you never logged in before, "
                "choose any name and password. If you don't want to be in "
                "our database for some reason, use the 'guest/guest' "
                "account.</p>"
                "<p>Warning: hangman contains some words and "
                "pictures that may offend really young players.</p>", this);

   WTable *layout = new WTable(this);
   WLabel *usernameLabel = new WLabel("User name: ", layout->elementAt(0, 0));
   layout->elementAt(0, 0)->resize(WLength(14, WLength::FontEx), WLength::Auto);
   Username = new WLineEdit(layout->elementAt(0, 1));
   usernameLabel->setBuddy(Username);

   WLabel *passwordLabel = new WLabel("Password: ", layout->elementAt(1, 0));
   Password = new WLineEdit(layout->elementAt(1, 1));
   Password->setEchoMode(WLineEdit::Password);
   passwordLabel->setBuddy(Password);

   WLabel *languageLabel = new WLabel("Language: ", layout->elementAt(2, 0));
   Language = new WComboBox(layout->elementAt(2, 1));
   Language->insertItem(0, "English words (18957 words)");
   Language->insertItem(1, "Nederlandse woordjes (1688 woorden)");
   languageLabel->setBuddy(Language);

   new WBreak(this);

   WPushButton *LoginButton = new WPushButton("Login", this);
   LoginButton->clicked().connect(this, &LoginWidget::checkCredentials);
}

Member Function Documentation

void LoginWidget::checkCredentials ( ) [private]

Definition at line 61 of file LoginWidget.C.

{
   User = Username->text();
   std::wstring pass = Password->text();
   Dict = (Dictionary) Language->currentIndex();
   
   if (HangmanDb::validLogin(User, pass)) {
      confirmLogin(L"<p>Welcome back, " + User + L".</p>");
   } else if (User == L"guest" && pass == L"guest") {
      confirmLogin(L"<p>Welcome guest, good luck.</p>");
   } else if (HangmanDb::addUser(User, pass)) {
      confirmLogin(L"<p>Welcome, "
                   + User + L". Good luck with your first game!</p>");
   } else {
      IntroText
        ->setText("<p>You entered the wrong password, or the username "
                  "combination is already in use. If you are a returning "
                  "user, please try again. If you are a new user, please "
                  "try a different name.</p>");
      IntroText->decorationStyle().setForegroundColor(Wt::red);
      Username->setText("");
      Password->setText("");
   }
}
void LoginWidget::confirmLogin ( const std::wstring  text) [private]

Definition at line 86 of file LoginWidget.C.

{
   clear();

   WText *title = new WText("Loging successful", this);
   title->decorationStyle().font().setSize(WFont::XLarge);

   new WText(text, this);
   (new WPushButton("Start playing", this))
     ->clicked().connect(this, &LoginWidget::startPlaying);
}
void LoginWidget::startPlaying ( ) [private]

Definition at line 98 of file LoginWidget.C.


Member Data Documentation

Definition at line 36 of file LoginWidget.h.

Definition at line 30 of file LoginWidget.h.

Definition at line 33 of file LoginWidget.h.

Definition at line 27 of file LoginWidget.h.

Definition at line 32 of file LoginWidget.h.

std::wstring LoginWidget::User [private]

Definition at line 35 of file LoginWidget.h.

Definition at line 31 of file LoginWidget.h.


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

Generated on Mon Nov 14 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4