<commit_before>package org.cloudcoder.app.client.page;

import org.cloudcoder.app.client.Session;
import org.cloudcoder.app.client.rpc.RPC;
import org.cloudcoder.app.shared.model.ConfigurationSettingName;
import org.cloudcoder.app.shared.model.User;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class LoginPage extends CloudCoderPage {
	private InlineLabel pageTitleLabel;
	private TextBox usernameTextBox;
	private PasswordTextBox passwordTextBox;
	private InlineLabel errorLabel;
	private InlineLabel loggingInLabel;
	public LoginPage() {
		setSize("640px", "480px");
		
		InlineLabel usernameLabel = new InlineLabel("User name:");
		add(usernameLabel);
		setWidgetLeftWidth(usernameLabel, 57.0, Unit.PX, 91.0, Unit.PX);
		setWidgetTopHeight(usernameLabel, 127.0, Unit.PX, 15.0, Unit.PX);
		
		usernameTextBox = new TextBox();
		add(usernameTextBox);
		setWidgetLeftWidth(usernameTextBox, 57.0, Unit.PX, 200.0, Unit.PX);
		setWidgetTopHeight(usernameTextBox, 148.0, Unit.PX, 31.0, Unit.PX);
		
		InlineLabel passwordLabel = new InlineLabel("Password:");
		add(passwordLabel);
		setWidgetLeftWidth(passwordLabel, 57.0, Unit.PX, 91.0, Unit.PX);
		setWidgetTopHeight(passwordLabel, 185.0, Unit.PX, 15.0, Unit.PX);
		
		passwordTextBox = new PasswordTextBox();
		add(passwordTextBox);
		setWidgetLeftWidth(passwordTextBox, 57.0, Unit.PX, 200.0, Unit.PX);
		setWidgetTopHeight(passwordTextBox, 206.0, Unit.PX, 33.0, Unit.PX);
		
		Button loginButton = new Button("Log in");
		loginButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				attemptLogin();
			}
		});
		add(loginButton);
		setWidgetLeftWidth(loginButton, 176.0, Unit.PX, 81.0, Unit.PX);
		setWidgetTopHeight(loginButton, 245.0, Unit.PX, 27.0, Unit.PX);
		
		Image cloudCoderLogoImage = new Image(GWT.getModuleBaseURL() + "images/CloudCoderLogo-med.png");
		add(cloudCoderLogoImage);
		setWidgetLeftWidth(cloudCoderLogoImage, 301.0, Unit.PX, 240.0, Unit.PX);
		setWidgetTopHeight(cloudCoderLogoImage, 148.0, Unit.PX, 165.0, Unit.PX);
		
		InlineLabel promptLabel = new InlineLabel("Please enter your username and password.");
		add(promptLabel);
		setWidgetLeftWidth(promptLabel, 57.0, Unit.PX, 343.0, Unit.PX);
		setWidgetTopHeight(promptLabel, 328.0, Unit.PX, 20.0, Unit.PX);
		
		errorLabel = new InlineLabel("");
		errorLabel.setStylePrimaryName("cc-errorText");
		add(errorLabel);
		setWidgetLeftWidth(errorLabel, 57.0, Unit.PX, 484.0, Unit.PX);
		setWidgetTopHeight(errorLabel, 383.0, Unit.PX, 73.0, Unit.PX);
		
		pageTitleLabel = new InlineLabel("");
		pageTitleLabel.setStylePrimaryName("cc-pageTitle");
		add(pageTitleLabel);
		setWidgetLeftWidth(pageTitleLabel, 57.0, Unit.PX, 533.0, Unit.PX);
		setWidgetTopHeight(pageTitleLabel, 44.0, Unit.PX, 31.0, Unit.PX);
		
		InlineLabel welcomeLabel = new InlineLabel("Welcome to CloudCoder at");
		add(welcomeLabel);
		setWidgetLeftWidth(welcomeLabel, 57.0, Unit.PX, 313.0, Unit.PX);
		setWidgetTopHeight(welcomeLabel, 23.0, Unit.PX, 15.0, Unit.PX);
		
		loggingInLabel = new InlineLabel("");
		add(loggingInLabel);
		setWidgetLeftWidth(loggingInLabel, 57.0, Unit.PX, 343.0, Unit.PX);
		setWidgetTopHeight(loggingInLabel, 353.0, Unit.PX, 20.0, Unit.PX);
	}

	protected void attemptLogin() {
		String username = usernameTextBox.getText();
		String password = passwordTextBox.getText();
		if (username.equals("") || password.equals("")) {
			errorLabel.setText("Please enter your username and password");
		}
		
		loggingInLabel.setText("Logging in...");
		RPC.loginService.login(username, password, new AsyncCallback<User>() {
			@Override
			public void onFailure(Throwable caught) {
				loggingInLabel.setText("");
				errorLabel.setText("Error communicating with server (are you connected to the network?)");
			}
			
			@Override
			public void onSuccess(User result) {
				// Successful login!
				getSession().add(result);
				getSession().notifySubscribers(Session.Event.LOGIN, result);
			}
		});
	}

	@Override
	public void activate() {
		RPC.configurationSettingService.getConfigurationSettingValue(ConfigurationSettingName.PUB_TEXT_INSTITUTION, new AsyncCallback<String>() {
			@Override
			public void onFailure(Throwable caught) {
			}
			
			@Override
			public void onSuccess(String result) {
				pageTitleLabel.setText(result);
			}
		});
	}

	@Override
	public void deactivate() {
	}
}<commit_msg>added keypress handlers for username and password boxes<commit_after>package org.cloudcoder.app.client.page;

import org.cloudcoder.app.client.Session;
import org.cloudcoder.app.client.rpc.RPC;
import org.cloudcoder.app.shared.model.ConfigurationSettingName;
import org.cloudcoder.app.shared.model.User;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;

public class LoginPage extends CloudCoderPage {
	private InlineLabel pageTitleLabel;
	private TextBox usernameTextBox;
	private PasswordTextBox passwordTextBox;
	private InlineLabel errorLabel;
	private InlineLabel loggingInLabel;
	public LoginPage() {
		setSize("640px", "480px");
		
		InlineLabel usernameLabel = new InlineLabel("User name:");
		add(usernameLabel);
		setWidgetLeftWidth(usernameLabel, 57.0, Unit.PX, 91.0, Unit.PX);
		setWidgetTopHeight(usernameLabel, 127.0, Unit.PX, 15.0, Unit.PX);
		
		usernameTextBox = new TextBox();
		usernameTextBox.addKeyPressHandler(new KeyPressHandler() {
			@Override
			public void onKeyPress(KeyPressEvent event) {
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
					passwordTextBox.setFocus(true);
				}
			}
		});
		add(usernameTextBox);
		setWidgetLeftWidth(usernameTextBox, 57.0, Unit.PX, 200.0, Unit.PX);
		setWidgetTopHeight(usernameTextBox, 148.0, Unit.PX, 31.0, Unit.PX);
		
		InlineLabel passwordLabel = new InlineLabel("Password:");
		add(passwordLabel);
		setWidgetLeftWidth(passwordLabel, 57.0, Unit.PX, 91.0, Unit.PX);
		setWidgetTopHeight(passwordLabel, 185.0, Unit.PX, 15.0, Unit.PX);
		
		passwordTextBox = new PasswordTextBox();
		passwordTextBox.addKeyPressHandler(new KeyPressHandler() {
			@Override
			public void onKeyPress(KeyPressEvent event) {
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
					attemptLogin();
				}
			}
		});
		add(passwordTextBox);
		setWidgetLeftWidth(passwordTextBox, 57.0, Unit.PX, 200.0, Unit.PX);
		setWidgetTopHeight(passwordTextBox, 206.0, Unit.PX, 33.0, Unit.PX);
		
		Button loginButton = new Button("Log in");
		loginButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				attemptLogin();
			}
		});
		add(loginButton);
		setWidgetLeftWidth(loginButton, 176.0, Unit.PX, 81.0, Unit.PX);
		setWidgetTopHeight(loginButton, 245.0, Unit.PX, 27.0, Unit.PX);
		
		Image cloudCoderLogoImage = new Image(GWT.getModuleBaseURL() + "images/CloudCoderLogo-med.png");
		add(cloudCoderLogoImage);
		setWidgetLeftWidth(cloudCoderLogoImage, 301.0, Unit.PX, 240.0, Unit.PX);
		setWidgetTopHeight(cloudCoderLogoImage, 148.0, Unit.PX, 165.0, Unit.PX);
		
		InlineLabel promptLabel = new InlineLabel("Please enter your username and password.");
		add(promptLabel);
		setWidgetLeftWidth(promptLabel, 57.0, Unit.PX, 343.0, Unit.PX);
		setWidgetTopHeight(promptLabel, 328.0, Unit.PX, 20.0, Unit.PX);
		
		errorLabel = new InlineLabel("");
		errorLabel.setStylePrimaryName("cc-errorText");
		add(errorLabel);
		setWidgetLeftWidth(errorLabel, 57.0, Unit.PX, 484.0, Unit.PX);
		setWidgetTopHeight(errorLabel, 383.0, Unit.PX, 73.0, Unit.PX);
		
		pageTitleLabel = new InlineLabel("");
		pageTitleLabel.setStylePrimaryName("cc-pageTitle");
		add(pageTitleLabel);
		setWidgetLeftWidth(pageTitleLabel, 57.0, Unit.PX, 533.0, Unit.PX);
		setWidgetTopHeight(pageTitleLabel, 44.0, Unit.PX, 31.0, Unit.PX);
		
		InlineLabel welcomeLabel = new InlineLabel("Welcome to CloudCoder at");
		add(welcomeLabel);
		setWidgetLeftWidth(welcomeLabel, 57.0, Unit.PX, 313.0, Unit.PX);
		setWidgetTopHeight(welcomeLabel, 23.0, Unit.PX, 15.0, Unit.PX);
		
		loggingInLabel = new InlineLabel("");
		add(loggingInLabel);
		setWidgetLeftWidth(loggingInLabel, 57.0, Unit.PX, 343.0, Unit.PX);
		setWidgetTopHeight(loggingInLabel, 353.0, Unit.PX, 20.0, Unit.PX);
	}

	protected void attemptLogin() {
		String username = usernameTextBox.getText();
		String password = passwordTextBox.getText();
		if (username.equals("") || password.equals("")) {
			errorLabel.setText("Please enter your username and password");
		}
		
		loggingInLabel.setText("Logging in...");
		RPC.loginService.login(username, password, new AsyncCallback<User>() {
			@Override
			public void onFailure(Throwable caught) {
				loggingInLabel.setText("");
				errorLabel.setText("Error communicating with server (are you connected to the network?)");
			}
			
			@Override
			public void onSuccess(User result) {
				if (result == null) {
					errorLabel.setText("Username and password not found");
				} else {
					// Successful login!
					getSession().add(result);
					getSession().notifySubscribers(Session.Event.LOGIN, result);
				}
			}
		});
	}

	@Override
	public void activate() {
		RPC.configurationSettingService.getConfigurationSettingValue(ConfigurationSettingName.PUB_TEXT_INSTITUTION, new AsyncCallback<String>() {
			@Override
			public void onFailure(Throwable caught) {
			}
			
			@Override
			public void onSuccess(String result) {
				pageTitleLabel.setText(result);
				usernameTextBox.setFocus(true);
			}
		});
	}

	@Override
	public void deactivate() {
	}
}
{'fraction_non_alphanumeric': 0.13076406864154924, 'fraction_numerical': 0.030294315022529, 'mean_word_length': 4.854096520763187, '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': '6718464', 'n_tokens_mistral': 4063, 'n_tokens_neox': 3477, 'n_words': 657}