<commit_before>package bg.car_wash.controllers.userController;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

	@GetMapping("/status")
	public String getUserStatusPage() {
		return "user-status";
	}
}<commit_msg>update user controller<commit_after>package bg.car_wash.controllers.userController;

import bg.car_wash.configurations.SiteTitleNames;
import bg.car_wash.configurations.UserConfiguration;
import bg.car_wash.entities.User;
import bg.car_wash.entities.enumerations.UserType;
import bg.car_wash.models.bindingModels.UserLoginBindingModel;
import bg.car_wash.models.bindingModels.UserRegisterBindingModel;
import bg.car_wash.models.viewModels.UserSessionViewModel;
import bg.car_wash.services.UserService;
import bg.car_wash.utils.parser.interfaces.ModelParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;

	@Autowired
	private ModelParser modelParser;
//
//	@GetMapping("/status")
//	public String getUserStatusPage(HttpSession httpSession) {
//		if(httpSession.getAttribute("username") != null) {
//			return "user-status";
//		}
//
//		return "redirect:/login";
//	}

	@GetMapping("/login")
	public String getLoginPage(Model model, @ModelAttribute UserLoginBindingModel userLoginBindingModel) {
		model.addAttribute("pageTitle", SiteTitleNames.LOGIN_PAGE);
		return "user/user-login";
	}

	@PostMapping("/login")
	public String loginUser(@Valid @ModelAttribute UserLoginBindingModel userLoginBindingModel, BindingResult bindingResult, HttpSession httpSession) {
		if(bindingResult.hasErrors()) {
			return "user/user-login";
		}

		UserSessionViewModel user = this.userService.getUserByFullNameAndPassword(userLoginBindingModel);
		if(user != null) {
			httpSession.setAttribute("user-email", user.getEmail());
			httpSession.setAttribute("user-full-name", user.getFullName());

			return "redirect:/status";
		}

		//if not get user from database
		return "user/user-login";
	}

	@GetMapping("/register")
	public String getRegisterPage(Model model, @ModelAttribute UserRegisterBindingModel userRegisterBindingModel) {
		model.addAttribute("pageTitle", SiteTitleNames.REGISTER_PAGE);
		return "user/user-register";
	}

	@PostMapping("/register")
	public String registerUser(@Valid @ModelAttribute UserRegisterBindingModel userRegisterBindingModel, BindingResult bindingResult) {
		if(bindingResult.hasErrors()) {
			return "user/user-register";
		}

		User user = this.modelParser.convert(userRegisterBindingModel, User.class);
		List<User> usersFromDb = this.userService.findAllUsers();

		if(usersFromDb.isEmpty()) {
			user.setUserType(UserType.DIRECTOR);
			user.setRemuneration(new BigDecimal(UserConfiguration.DIRECTOR_REMUNERATION));
		} else if (usersFromDb.size() == 1) {
			user.setUserType(UserType.ADMIN);
			user.setRemuneration(new BigDecimal(UserConfiguration.ADMIN_REMUNERATION));
		} else {
			user.setUserType(UserType.WORKER);
			user.setRemuneration(new BigDecimal(UserConfiguration.WORKER_REMUNERATION));
		}

		this.userService.createUser(user);

		return "redirect:/user/login";
	}
}
{'fraction_non_alphanumeric': 0.11419672982091876, 'fraction_numerical': 0.0002595380223202699, 'mean_word_length': 6.369024856596559, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4557158', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1115, 'n_words': 183}