<commit_before>package com.inepex.ineFrame.client.auth;

import java.util.Date;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.ButtonElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.SubmitButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.inepex.ineFrame.client.async.IneDispatch;
import com.inepex.ineFrame.client.async.IneDispatchBase;
import com.inepex.ineFrame.client.auth.AbstractAuthManager.AuthActionCallback;
import com.inepex.ineFrame.client.i18n.IneFrameI18n;
import com.inepex.ineFrame.client.misc.HandlerAwareComposite;
import com.inepex.ineFrame.client.navigation.HistoryProvider;
import com.inepex.ineFrame.client.navigation.NavigationProperties;
import com.inepex.ineFrame.client.navigation.PlaceHandler;
import com.inepex.ineFrame.client.navigation.PlaceRequestEvent;
import com.inepex.ineFrame.client.widgets.CaptchaWidget;
import com.inepex.ineFrame.shared.auth.AuthStatusResultBase;
import com.inepex.ineFrame.shared.auth.CaptchaInfoAction;
import com.inepex.ineFrame.shared.auth.CaptchaInfoResult;
import com.inepex.ineFrame.shared.util.DateHelper;
import com.inepex.ineom.shared.IFConsts;

public abstract class LoginBox extends HandlerAwareComposite {

	protected final VerticalPanel vp = new VerticalPanel();
	protected FormPanel formPanel;
	protected final VerticalPanel formContent = new VerticalPanel();
	protected TextBox userName;
	protected PasswordTextBox password;
	protected Label captchaLabel;
	protected CaptchaWidget captchaWidget;
	protected Button loginButton;

	protected final AuthManager authManager;
	protected final HistoryProvider historyProvider;
	protected final EventBus eventBus;
	protected final IneDispatch ineDispatch;
	
	protected LoginBox(AuthManager authManager, HistoryProvider historyProvider, EventBus eventBus, IneDispatch ineDispatch) {
		this.authManager = authManager;
		this.historyProvider=historyProvider;
		this.eventBus=eventBus;
		this.ineDispatch=ineDispatch;
	
		createUI();
		initWidget(vp);	
		if(IFConsts.COOKIE_TRUE.equals(Cookies.getCookie(IFConsts.COOKIE_NEEDSTAYSIGNEDIN)))
			getCheckBox().setValue(true);	
	}
	
	/**
	 * this method initializes the protected fields: labels and button 
	 */
	protected void createUI() {
		Element usernameEl = DOM.getElementById("username");
		Element passwordEl = DOM.getElementById("password");
		ButtonElement submitEl = (ButtonElement) Document.get().getElementById("loginSubmit");
		Element formEl = DOM.getElementById("loginform"); 
		
		userName = (usernameEl == null ? new TextBox() : TextBox.wrap(usernameEl));
		password = (passwordEl == null ? new PasswordTextBox() : PasswordTextBox.wrap(passwordEl));
		loginButton = (submitEl == null ? new SubmitButton() : Button.wrap(submitEl));
		loginButton.setText(IneFrameI18n.LOGIN());
		
		formContent.add(new Label(IneFrameI18n.USERNAME()));
		formContent.add(userName);
		formContent.add(new Label(IneFrameI18n.PASSWORD()));
		formContent.add(password);
		captchaLabel=new Label(IneFrameI18n.CAPTCHA());
		formContent.add(captchaLabel);
		captchaWidget=new CaptchaWidget();
		formContent.add(captchaWidget);
		formContent.add(loginButton);
		
		formPanel = (formEl == null ? new FormPanel() : FormPanel.wrap(formEl));
		formEl.getStyle().setDisplay(Display.BLOCK);
		formPanel.add(formContent);
		vp.add(formPanel);
	}
	

	@Override
	protected void onAttach() {
		super.onAttach();
		
		registerHandler(formPanel.addSubmitHandler(new SubmitHandler() {
			
			@Override
			public void onSubmit(SubmitEvent event) {
				doLogin();
				event.cancel();
			}
		}));
		
		registerHandler(getCheckBox().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
			
			@Override
			public void onValueChange(ValueChangeEvent<Boolean> event) {
				if(event.getValue()){
					Cookies.setCookie(IFConsts.COOKIE_NEEDSTAYSIGNEDIN, IFConsts.COOKIE_TRUE, DateHelper.addDaysSafe(new Date(), 30));
				}else{
					Cookies.setCookie(IFConsts.COOKIE_NEEDSTAYSIGNEDIN, IFConsts.COOKIE_FALSE, DateHelper.addDaysSafe(new Date(), 30));<commit_msg>disable username and password textbox when login in progress<commit_after>package com.inepex.ineFrame.client.auth;

import java.util.Date;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.ButtonElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.SubmitButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.inepex.ineFrame.client.async.IneDispatch;
import com.inepex.ineFrame.client.async.IneDispatchBase;
import com.inepex.ineFrame.client.auth.AbstractAuthManager.AuthActionCallback;
import com.inepex.ineFrame.client.i18n.IneFrameI18n;
import com.inepex.ineFrame.client.misc.HandlerAwareComposite;
import com.inepex.ineFrame.client.navigation.HistoryProvider;
import com.inepex.ineFrame.client.navigation.NavigationProperties;
import com.inepex.ineFrame.client.navigation.PlaceHandler;
import com.inepex.ineFrame.client.navigation.PlaceRequestEvent;
import com.inepex.ineFrame.client.widgets.CaptchaWidget;
import com.inepex.ineFrame.shared.auth.AuthStatusResultBase;
import com.inepex.ineFrame.shared.auth.CaptchaInfoAction;
import com.inepex.ineFrame.shared.auth.CaptchaInfoResult;
import com.inepex.ineFrame.shared.util.DateHelper;
import com.inepex.ineom.shared.IFConsts;

public abstract class LoginBox extends HandlerAwareComposite {

	protected final VerticalPanel vp = new VerticalPanel();
	protected FormPanel formPanel;
	protected final VerticalPanel formContent = new VerticalPanel();
	protected TextBox userName;
	protected PasswordTextBox password;
	protected Label captchaLabel;
	protected CaptchaWidget captchaWidget;
	protected Button loginButton;

	protected final AuthManager authManager;
	protected final HistoryProvider historyProvider;
	protected final EventBus eventBus;
	protected final IneDispatch ineDispatch;
	
	protected LoginBox(AuthManager authManager, HistoryProvider historyProvider, EventBus eventBus, IneDispatch ineDispatch) {
		this.authManager = authManager;
		this.historyProvider=historyProvider;
		this.eventBus=eventBus;
		this.ineDispatch=ineDispatch;
	
		createUI();
		initWidget(vp);	
		if(IFConsts.COOKIE_TRUE.equals(Cookies.getCookie(IFConsts.COOKIE_NEEDSTAYSIGNEDIN)))
			getCheckBox().setValue(true);	
	}
	
	/**
	 * this method initializes the protected fields: labels and button 
	 */
	protected void createUI() {
		Element usernameEl = DOM.getElementById("username");
		Element passwordEl = DOM.getElementById("password");
		ButtonElement submitEl = (ButtonElement) Document.get().getElementById("loginSubmit");
		Element formEl = DOM.getElementById("loginform"); 
		
		userName = (usernameEl == null ? new TextBox() : TextBox.wrap(usernameEl));
		password = (passwordEl == null ? new PasswordTextBox() : PasswordTextBox.wrap(passwordEl));
		loginButton = (submitEl == null ? new SubmitButton() : Button.wrap(submitEl));
		loginButton.setText(IneFrameI18n.LOGIN());
		
		formContent.add(new Label(IneFrameI18n.USERNAME()));
		formContent.add(userName);
		formContent.add(new Label(IneFrameI18n.PASSWORD()));
		formContent.add(password);
		captchaLabel=new Label(IneFrameI18n.CAPTCHA());
		formContent.add(captchaLabel);
		captchaWidget=new CaptchaWidget();
		formContent.add(captchaWidget);
		formContent.add(loginButton);
		
		formPanel = (formEl == null ? new FormPanel() : FormPanel.wrap(formEl));
		formEl.getStyle().setDisplay(Display.BLOCK);
		formPanel.add(formContent);
		vp.add(formPanel);
	}
	

	@Override
	protected void onAttach() {
		super.onAttach();
		setTextBoxesEnabled(true);
		
		registerHandler(formPanel.addSubmitHandler(new SubmitHandler() {
			
			@Override
			public void onSubmit(SubmitEvent event) {
				doLogin();
				event.cancel();
			}
		}));
		
		registerHandler(getCheckBox().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
			
			@Override
			public void onValueChange(ValueChangeEvent<Boolean> event) {
				if(event.getValue()){
					Cookies.setCookie(IFConsts.COOKIE_NEEDSTAYSIGNEDIN, IFConsts.COOKIE_TRUE, DateHelper.addDaysSafe(new Date(), 30));
				}else{
					Cookies.setCookie(IFConsts.COOKIE_NEEDSTAYSIGNEDIN, IFConsts.COOKIE_FALSE, DateHelper.addDaysSafe(new Date(), 30));
{'fraction_non_alphanumeric': 0.1130952380952381, 'fraction_numerical': 0.003228410008071025, 'mean_word_length': 5.893602225312935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4741097', 'n_tokens_mistral': 3374, 'n_tokens_neox': 3080, 'n_words': 502}