SHARE
TWEET

LoginPage

smallufo Jul 5th, 2014 226 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LoginPage extends WebPage
  2. {
  3.   Logger logger = LoggerFactory.getLogger(getClass());
  4.  
  5.   @Inject
  6.   private UserService userService;
  7.  
  8.   private boolean successful = false;
  9.  
  10.   public LoginPage(final PageParameters pps , final ModalWindow window)
  11.   {
  12.     super(pps);
  13.  
  14.     final TextField<String> usernameField = new RequiredTextField<String>("usernameField" , new Model<String>());
  15.     final PasswordTextField passwordField = new PasswordTextField("passwordField" , new Model<String>());
  16.     Form<Void> form = new Form<Void>("form");
  17.  
  18.     form.add(new AjaxButton("submit")
  19.     {
  20.       @Override
  21.       protected void onSubmit(AjaxRequestTarget target, Form<?> form)
  22.       {
  23.         String username = usernameField.getModelObject();
  24.         String password = passwordField.getModelObject();
  25.        
  26.         logger.info("submit onSubmit() : username = {}", username);
  27.        
  28.         User user = userService.login(username, password);
  29.         if (user != null)
  30.         {
  31.           logger.info("username / password correct . user = {}" , user);
  32.           // do something in cookie ...
  33.           Cookie cookie = // ....
  34.           ((WebResponse)getRequestCycle().getResponse()).addCookie(cookie);
  35.                  
  36.           successful = true;
  37.           window.close(target);
  38.         }
  39.         else
  40.           logger.warn("login failed : {}" , username);
  41.       } // onSubmit()
  42.     });
  43.    
  44.     form.add(new AjaxButton("cancel")
  45.     {
  46.       @Override
  47.       protected void onSubmit(AjaxRequestTarget target, Form<?> form)
  48.       {
  49.         logger.info("cancel onSubmit()");
  50.         window.close(target);
  51.       }
  52.     });
  53.    
  54.     form.add(usernameField);
  55.     form.add(passwordField);
  56.  
  57.     add(form);
  58.   }
  59.  
  60.   public boolean isSuccessful()
  61.   {
  62.     return successful;
  63.   }
  64.  
  65.   public void setSuccessful(boolean successful)
  66.   {
  67.     this.successful = successful;
  68.   }
  69.  
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top