001    package org.hackystat.projectbrowser.authentication;
002    
003    import org.apache.wicket.markup.html.basic.Label;
004    import org.apache.wicket.markup.html.form.PasswordTextField;
005    import org.apache.wicket.markup.html.form.StatelessForm;
006    import org.apache.wicket.markup.html.form.TextField;
007    import org.apache.wicket.model.CompoundPropertyModel;
008    import org.apache.wicket.model.PropertyModel;
009    import org.hackystat.projectbrowser.ProjectBrowserApplication;
010    import org.hackystat.projectbrowser.ProjectBrowserSession;
011    import org.hackystat.projectbrowser.page.sensordata.SensorDataPage;
012    
013    /**
014     * The form for providing credentials to sign in to the Sensorbase. 
015     * 
016     * @author Philip Johnson
017     */
018    class SigninForm extends StatelessForm {
019    
020      /** Support serialization. */
021      private static final long serialVersionUID = 1L;
022      /** The sensorbase user. */
023      private String user;
024      /** The sensorbase password. */
025      private String password;
026    
027      /**
028       * Create this form, supplying the wicket:id.
029       * 
030       * @param id The wicket:id.
031       */
032      public SigninForm(final String id) {
033        super(id);
034        setModel(new CompoundPropertyModel(this));
035        add(new TextField("user"));
036        add(new PasswordTextField("password"));
037        add(new Label("signinFeedback", 
038            new PropertyModel(ProjectBrowserSession.get(), "signinFeedback")));
039      }
040      
041      /**
042       * Process the user action after submitting a username/password.  Note that they will go 
043       * to the page they requested if it was not the home page. 
044       */
045      @Override
046      public void onSubmit() {
047        boolean signinSuccessful = ProjectBrowserSession.get().signin(user, password);
048        if (signinSuccessful) {
049          ((ProjectBrowserApplication)this.getApplication()).getLogger().
050            info("User " + this.user + " has logged in.");
051          if (!continueToOriginalDestination()) {
052            setResponsePage(new SensorDataPage());
053          }
054        }
055        else {
056          ProjectBrowserSession.get().setSigninFeedback("User/Password not correct.");
057        }
058      }
059    
060      /**
061       * Returns the password.
062       * 
063       * @return The password.
064       */
065      public String getPassword() {
066        return password;
067      }
068    
069      /**
070       * Returns the user.
071       * 
072       * @return The user.
073       */
074      public String getUser() {
075        return user;
076      }
077    
078      /**
079       * Sets the password. 
080       * @param password The password. 
081       */
082      public void setPassword(String password) {
083        this.password = password;
084      }
085    
086      /**
087       * Sets the user. 
088       * @param user The user. 
089       */
090      public void setUser(String user) {
091        this.user = user;
092      }
093    }