<commit_before>package com.github.vovas11.courses.command;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.github.vovas11.courses.dao.*;

/**
 * {@code LoginCommand} handles access for the existing user
 * 
 * @author vovas11
 * @see DaoFactory
 * @see UserDao
 * @see CourseDao
 * 
 */
public class LoginCommand implements Command {
    /**
     * Defines if the name and password of the user exists in the database and if yes,
     * returns the page for the user. If not, returns the home page
     *
     * @param   request   HTTP request
     * @return the the name of the page the server returns to the client
     */
    @Override
    public String execute(HttpServletRequest request) {
	
	/* gets parameters from the HTTP request */
	String login = request.getParameter("login");
	String password = request.getParameter("password");
	
	/* gets the link to the DaoFactory and UserDao and CourseDao */
	DaoFactory daoFactory = DaoFactory.getInstance();
	UserDao users = daoFactory.getUserDao();
	CourseDao courses = daoFactory.getCourseDao();
	
	/* gets the link to the current session or creates new one */
	HttpSession session = request.getSession();
	
	/* gets the link to the current user and if one does not exists yet
	 * creates new user instance and updates all fields */
	User user = (User) session.getAttribute(session.getId());
	
	// FIXME check the user credential after checking existence of the login
	
	if (user == null) {
	    user = new User();
	    user.setLogin(login);
	    user.setPassword(password);
	    
	    // gets all fields for the object from the database
	    users.getFieldsForUser(user);
	    session.setAttribute(session.getId(), user);
	}
	
	/* Checks if the user already Prepares the data for the JSP page:
	 * current user, subscribed courses and available courses */
	if (users.isExist(user)) {
	    // Information about the logged user
	    request.setAttribute("user", user);
	    // Getting subscribed courses
	    List<Course> subscribedCourses = courses.getSubscribedCourses(user);
	    request.setAttribute("subscrcourses", subscribedCourses);
	    
	    // Getting all courses from the DB
	    List<Course> courseList = courses.getAvailableCourses(user);
	    request.setAttribute("courses", courseList);
	    return "/courses.jsp";
	} else {
	    return "/index.html";
	}
    }
}<commit_msg>fix signing in with wrong credentials<commit_after>package com.github.vovas11.courses.command;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.github.vovas11.courses.dao.*;

/**
 * {@code LoginCommand} handles access for the existing user
 * 
 * @author vovas11
 * @see DaoFactory
 * @see UserDao
 * @see CourseDao
 * 
 */
public class LoginCommand implements Command {
    /**
     * Defines if the name and password of the user exists in the database and if yes,
     * returns the page for the user. If not, returns the starting page
     *
     * @param   request   HTTP request
     * @return the the name of the page the server returns to the client
     */
    @Override
    public String execute(HttpServletRequest request) {
	
	/* gets parameters from the HTTP request */
	String login = request.getParameter("login");
	String password = request.getParameter("password");
	
	/* gets the link to the DaoFactory and UserDao and CourseDao */
	DaoFactory daoFactory = DaoFactory.getInstance();
	UserDao users = daoFactory.getUserDao();
	CourseDao courses = daoFactory.getCourseDao();
	
	/* creates new user and sets the fields received from the user form via HTTP request */
	User user = new User();
	user.setLogin(login);
	user.setPassword(password);
	
	/* checks if the user with entered credentials exists in the database:
	 * yes - proceed, no - forwards to the starting page */
	if (users.isExist(user)) {
	    /* gets the link to the current session or creates new one */
	    HttpSession session = request.getSession();
	    
	    /* gets all fields for the user from the database and set the link to the session */
	    users.getFieldsForUser(user);
	    session.setAttribute(session.getId(), user);
	    
	    /* prepares the data for the JSP page:
	     * current user, subscribed courses and available courses */
	    request.setAttribute("user", user);
	    
	    /* gets subscribed courses from the database and set the link to the HTTP request */
	    List<Course> subscribedCourses = courses.getSubscribedCourses(user);
	    request.setAttribute("subscrcourses", subscribedCourses);
	    
	    /* gets available courses from the database and set the link to the HTTP request */
	    List<Course> courseList = courses.getAvailableCourses(user);
	    request.setAttribute("courses", courseList);
	    return "/courses.jsp";
	    
	} else {
	    return "/index.html";
	}
    }
}
{'fraction_non_alphanumeric': 0.0925281473899693, 'fraction_numerical': 0.0024564994882292734, 'mean_word_length': 3.385996409335727, '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': '3016073', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1336, 'n_words': 486}