// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2011 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WT_AUTH_ENTER_PASSWORD_FIELDS_H_
#define WT_AUTH_ENTER_PASSWORD_FIELDS_H_

#include <Wt/WObject>

namespace Wt {

class WLineEdit;
class WPushButton;
class WText;

  namespace Auth {

class AbstractPasswordService;
class User;

/*! \class EnterPasswordFields Wt/Auth/EnterPasswordFields
 *  \brief Helper class for creating a form to let a user enter his password
 *
 * This class implements the process of letting the user enter his
 * password. It also implements attempt throttling.
 *
 * \sa AuthWidget, PasswordPromptDialog, UpdatePasswordWidget
 *
 * \ingroup auth
 */
class WT_API EnterPasswordFields : public WObject
{
public:
  /*! \brief Constructor.
   *
   * The object uses a password entry field, a feed-back text field
   * (for error feed-back and/or help text), and optionally also
   * manipulates the "login"/"ok" button to indicate that attempts are
   * currently refused because of password attempt throttling.
   */
  EnterPasswordFields(const AbstractPasswordService& auth,
		      WLineEdit *password, WText *passwordInfo,
		      WPushButton *okButton, WObject *parent = 0);

  /*! \brief Validates the entered password.
   *
   * This validates the entered password, and provides the necessary
   * feed-back in the info field and ok button.
   *
   * Returns whether the entered password is valid.
   */
  bool validate(const User& user);

private:
  const AbstractPasswordService& auth_;
  WLineEdit *password_;
  WPushButton *okButton_;
  WText *passwordInfo_;

  void init();
  void enableThrottlingJS();
  void loginThrottle(int delay);
};

  }
}

#endif // WT_AUTH_ENTER_PASSWORD_FIELDS_H_
