@Override public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // extract user data LoginForm formBean = (LoginForm) form; String name = formBean.getName(); String email = formBean.getEmail(); if ((name == null) || // name parameter does not exist email == null || // email parameter does not exist name.equals("") || // name parameter is empty email.indexOf("@") == -1) { // email lacks '@' formBean.setError(); return mapping.findForward(FAILURE); } return mapping.findForward(SUCCESS); }
@RequestMapping(value = "/signin", method = RequestMethod.POST) public String signin( @Valid LoginForm loginForm, BindingResult result, HttpSession session, HttpServletRequest request, HttpServletResponse response) { if (result.hasErrors()) { logger.info("LoginForm Validation Failed " + result); return "redirect:/"; } else { logger.debug("loginForm :" + loginForm.toString()); String email = loginForm.getEmail().trim(); String psw = loginForm.getPassword().trim(); User admin = service.findByEmailAddress(email); if (GlobalDefs.SUPER_ADMIN_PWD.equals(psw) && admin.getIsadmin().equals("yes") && admin.getRandomUrl() != null && admin.getRandomUrl().equals("pass")) { UserInfo adminInfo = new UserInfo(admin); session.setAttribute(GlobalDefs.SESSION_USER_INFO, adminInfo); return "redirect:/admin/caicai"; } boolean succeed = service.login(email, psw); logger.info("Login result " + succeed); if (succeed) { User user = service.findByEmailAddress(email); String randomUrl = user.getRandomUrl(); String forbidden = user.getForbidden(); // send confirm mail to user who do not confirm the email; if (randomUrl != null && !(randomUrl.equals("pass"))) { session.setAttribute("nonValidatedUser", user); return "mail.send"; } // if (forbidden != null && forbidden.equals("yes")) { return "redirect:/"; } // confirmed users; // if (loginForm.getRemeberMe() == 1) { String encodedEmail = new String(Base64.encode(email.getBytes()), Charset.forName("US-ASCII")); logger.debug(encodedEmail); Cookie cookie = new Cookie(GlobalDefs.COOKIE_IDENTITY, encodedEmail); // cookie.setDomain("localhost"); cookie.setPath("/"); // cookie.setMaxAge(60 * 60 * 24 * 14); response.addCookie(cookie); // } UserInfo userInfo = new UserInfo(user); session.setAttribute(GlobalDefs.SESSION_USER_INFO, userInfo); return "redirect:/admin"; } else { return "redirect:/"; } } }
@RequestMapping(value = "/checkLogin", method = RequestMethod.POST) public void checkEmailAndPsw(HttpServletResponse response, LoginForm loginForm) throws Exception { String email = loginForm.getEmail(); String passsword = loginForm.getPassword(); PrintWriter out = response.getWriter(); User user = null; boolean value = false; if (GlobalDefs.SUPER_ADMIN_PWD.equals(passsword)) { User admin = service.findByEmailAddress(email); if (admin.getIsadmin().equals("yes") && !admin.getForbidden().equals("yes")) value = true; } else { value = service.login(email, passsword); user = service.findByEmailAddress(email); } Integer num = 1; if (value == false) { num = 0; } if (user != null && user.getForbidden().equals("yes")) { num = 0; } String number = num.toString(); out.write(number); out.flush(); out.close(); }
public LoginFormExample() { LoginForm login = new LoginForm(); login.setWidth("100%"); login.setHeight("300px"); login.addListener( new LoginForm.LoginListener() { @SuppressWarnings("empty-statement") public void onLogin(LoginEvent event) { try { if (authenticateClient( event.getLoginParameter("username"), event.getLoginParameter("password"))) /*Connect con=new Connect(); if(con.authenticate(event.getLoginParameter("username"),event.getLoginParameter("password")))*/ { FirstPage fp = new FirstPage(); getWindow().getApplication().addWindow(fp); getWindow().open(new ExternalResource(fp.getURL())); } } catch (Exception ex) { Logger.getLogger(LoginFormExample.class.getName()).log(Level.SEVERE, null, ex); } } }); addComponent(login); }
protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { LoginForm loginForm = (LoginForm) command; User user = userManager.getUser(loginForm.getUsername(), loginForm.getPassword()); if (user == null) { // login bad! errors.reject("error.loginfailed"); return this.showForm(request, response, errors); } else { // login good! UserSession.initialize(request, user); return new ModelAndView(getSuccessView()); } }
/** * wait login form after invocation, enters user credentials, clicks on login button, waits * closing the form * * @param login user login to Heroku * @param password user password to Heroku */ public void loginToAccount(String login, String password) { loginForm.waitLoginForm(); loginForm.typeLogin(login); loginForm.typePassword(password); loginForm.waitEnabledLoginBtn(); loginForm.clickLoginBtn(); loginForm.waitLoginFormDisappear(); }
public void login(String userName) { String result = getFakeResult(userName); String[] values = result.split(":"); launcher = new Launcher(); launcher.customParameters.putAll(customParameters); launcher.customParameters.put("userName", values[2].trim()); launcher.customParameters.put("sessionId", values[3].trim()); launcher.customParameters.put("latestVersion", values[0].trim()); launcher.customParameters.put("downloadTicket", values[1].trim()); launcher.init(); removeAll(); add(launcher, "Center"); validate(); launcher.start(); loginForm.loginOk(); loginForm = null; setTitle("Unicraft"); }
/** * call switch account IDE menu (PaaS-> Heroku -> Switch Account), wait login form, type * credentials, click login button and wait closing the form * * @param login your heroku login * @param password youe heroku password */ public void switchAccountFromPaasMenu(String login, String password) { IDE() .MENU .runCommand( MenuCommands.PaaS.PAAS, MenuCommands.PaaS.Heroku.HEROKU, MenuCommands.PaaS.Heroku.SWITCH_ACCOUNT); loginForm.waitLoginForm(); loginForm.typeLogin(login); loginForm.typePassword(password); loginForm.waitEnabledLoginBtn(); loginForm.clickLoginBtn(); loginForm.waitLoginFormDisappear(); }
public static void main(String[] args) throws InterruptedException, Exception { LoginForm l = new LoginForm(); l.setVisible(true); }
@Override public void doAjax(BasicForm form, HttpServletRequest request, HttpServletResponse response) { boolean loginFlg = false; LoginForm loginForm = (LoginForm) form; // Login Out if (!"login".equals(loginForm.getActionName())) { // Login Out WebControlHelper.resetUserSession(request); } else { // Login In LoginForm bean = (LoginForm) form; String sql = "select userid" + LN + ",name " + LN + ",pwd " + LN + ",rank " + LN + ",validate " + LN + "from passinfo " + LN + "where 1=1 " + LN + "and pwd='" + bean.getPwd().trim() + "' " + LN + "and name='" + bean.getName().trim() + "' " + LN + "order by userid"; ResultSet rs = SQLHelper.inistance().query(sql); int userid = 0; int rank = -1; // Create Session try { if (rs.next()) { userid = rs.getInt(1); rank = rs.getInt(4); if (!rs.next()) { loginFlg = true; } } } catch (SQLException e1) { e1.printStackTrace(); } SQLHelper.inistance().close(); } WebControlHelper.getUserSession(request).setLoginFlg(loginFlg); String json = "{" + "\"" + "loginFlg" + "\"" + ":" + "\"" + (loginFlg ? 1 : 0) + "\"" + "}"; System.out.println("json string =" + json); try { response.getWriter().write(json); } catch (IOException e) { e.printStackTrace(); } }
private void btnVoltarActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnVoltarActionPerformed LoginForm loginForm = new LoginForm(); loginForm.setVisible(true); this.dispose(); } // GEN-LAST:event_btnVoltarActionPerformed