<commit_before>package conferenceOrganisation.managers;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.Singleton;
import javax.inject.Inject;

import conferenceOrganisation.database.connection.DatabaseConnection;
import conferenceOrganisation.models.User;
import conferenceOrganisation.utils.Utils;

@Singleton
public class UserManager {

	@Inject
	HallManager hallManager;

	@Inject
	TicketManager ticketManager;

	@Inject
	EventManager eventManager;

	@Inject
	LectureManager lectureManager;

	@Inject
	DatabaseConnection dbConnection;

	public void addUser(User user) throws SQLException, IOException {
		String firstName = user.getFirstName();
		String lastName = user.getLastName();
		String email = user.getEmail();
		String password = <PASSWORD>();
		String txtQuery = String.format(
				"insert into users(firstName, lastName, email, password) values ('%s', '%s', '%s', '%s')", firstName,
				lastName, email, Utils.getHashedPassword(password));
		Statement statement = dbConnection.createStatement();
		statement.executeUpdate(txtQuery);
		statement.close();
	}

	public List<User> getAllUsers() throws SQLException, IOException {
		String txtQuery = "select * from users u";
		Statement statement = dbConnection.createStatement();
		ResultSet rs = statement.executeQuery(txtQuery);
		List<User> users = new ArrayList<User>();
		while (rs.next()) {
			User user = new User();
			user.setFirstName(rs.getString("firstName"));
			user.setLastName(rs.getString("lastName"));
			user.setEmail(rs.getString("email"));
			user.setUserId(Integer.parseInt(rs.getString("userId")));
			user.setIsAdmin(rs.getInt("isAdmin"));
			user.setEvents(eventManager.getAllEventsByUserId(user.getUserId()));
			user.setLectures(lectureManager.getAllLecturesByUserId(user.getUserId()));
			user.setTickets(ticketManager.getAllTicketsByUserId(user.getUserId()));
			users.add(user);
		}
		statement.close();
		return users;
	}

	public User getUserById(int userId) throws SQLException, IOException {
		User user = new User();
		String txtQuery = String.format("select * from users where users.userId=%d", userId);
		Statement statement = dbConnection.createStatement();
		ResultSet rs = statement.executeQuery(txtQuery);

		while (rs.next()) {
			user.setUserId(rs.getInt("userId"));
			user.setFirstName(rs.getString("firstName"));
			user.setLastName(rs.getString("lastName"));
			user.setEmail(rs.getString("email"));
			user.setIsAdmin(rs.getInt("isAdmin"));
			user.setEvents(eventManager.getAllEventsByUserId(user.getUserId()));
			user.setLectures(lectureManager.getAllLecturesByUserId(user.getUserId()));
			user.setTickets(ticketManager.getAllTicketsByUserId(user.getUserId()));
		}
		statement.close();
		return user;
	}

	public User getUserByEmailAndPassword(String email, String password) throws SQLException, IOException {
		User user = new User();
		String txtQuery = String.format("select * from users where users.email='%s' and users.password='%s'", email,
				Utils.getHashedPassword(password));
		Statement statement = dbConnection.createStatement();
		ResultSet rss = statement.executeQuery(txtQuery);

		while (rss.next()) {
			user.setUserId(rss.getInt("userId"));
			user.setFirstName(rss.getString("firstName"));
			user.setLastName(rss.getString("lastName"));
			user.setEmail(rss.getString("email"));<commit_msg>fix login problem<commit_after>package conferenceOrganisation.managers;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.Singleton;
import javax.inject.Inject;

import conferenceOrganisation.database.connection.DatabaseConnection;
import conferenceOrganisation.models.User;
import conferenceOrganisation.utils.Utils;

@Singleton
public class UserManager {

	@Inject
	HallManager hallManager;

	@Inject
	TicketManager ticketManager;

	@Inject
	EventManager eventManager;

	@Inject
	LectureManager lectureManager;

	@Inject
	DatabaseConnection dbConnection;

	public void addUser(User user) throws SQLException, IOException {
		String firstName = user.getFirstName();
		String lastName = user.getLastName();
		String email = user.getEmail();
		String password = <PASSWORD>();
		String txtQuery = String.format(
				"insert into users(firstName, lastName, email, password) values ('%s', '%s', '%s', '%s')", firstName,
				lastName, email, Utils.getHashedPassword(password));
		Statement statement = dbConnection.createStatement();
		statement.executeUpdate(txtQuery);
		statement.close();
	}

	public List<User> getAllUsers() throws SQLException, IOException {
		String txtQuery = "select * from users u";
		Statement statement = dbConnection.createStatement();
		ResultSet rs = statement.executeQuery(txtQuery);
		List<User> users = new ArrayList<User>();
		while (rs.next()) {
			User user = new User();
			user.setFirstName(rs.getString("firstName"));
			user.setLastName(rs.getString("lastName"));
			user.setEmail(rs.getString("email"));
			user.setUserId(Integer.parseInt(rs.getString("userId")));
			user.setIsAdmin(rs.getInt("isAdmin"));
			user.setEvents(eventManager.getAllEventsByUserId(user.getUserId()));
			user.setLectures(lectureManager.getAllLecturesByUserId(user.getUserId()));
			user.setTickets(ticketManager.getAllTicketsByUserId(user.getUserId()));
			users.add(user);
		}
		statement.close();
		return users;
	}

	public User getUserById(int userId) throws SQLException, IOException {
		User user = new User();
		String txtQuery = String.format("select * from users where users.userId=%d", userId);
		Statement statement = dbConnection.createStatement();
		ResultSet rs = statement.executeQuery(txtQuery);

		while (rs.next()) {
			user.setUserId(rs.getInt("userId"));
			user.setFirstName(rs.getString("firstName"));
			user.setLastName(rs.getString("lastName"));
			user.setEmail(rs.getString("email"));
			user.setIsAdmin(rs.getInt("isAdmin"));
			user.setEvents(eventManager.getAllEventsByUserId(user.getUserId()));
			user.setLectures(lectureManager.getAllLecturesByUserId(user.getUserId()));
			user.setTickets(ticketManager.getAllTicketsByUserId(user.getUserId()));
		}
		statement.close();
		return user;
	}

	public User getUserByEmailAndPassword(String email, String password) throws SQLException, IOException {
		User user = null;
		String txtQuery = String.format("select * from users where users.email='%s' and users.password='%s'", email,
				Utils.getHashedPassword(password));
		Statement statement = dbConnection.createStatement();
		ResultSet rss = statement.executeQuery(txtQuery);

		while (rss.next()) {
			user = new User();
			user.setUserId(rss.getInt("userId"));
			user.setFirstName(rss.getString("firstName"));
			user.setLastName(rss.getString("lastName"));
			user.setEmail(rss.getString("email"));
{'fraction_non_alphanumeric': 0.13170028818443805, 'fraction_numerical': 0.0, 'mean_word_length': 5.906467661691543, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1692597', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2076, 'n_words': 401}