if (true == isCaptchaCorrect(request)) {
final String login = (String) request.getParameter("login");
final String password = (String) request.getParameter("password");
final SystemUsers sysUsers = (SystemUsers) request.getServletContext().getAttribute("sysUsers");
User user = (User) request.getSession().getAttribute ("user");
final UserImpl adminUser = (UserImpl) request.getServletContext().getAttribute ("adminUser");
if (true == adminUser.getLogin().equals(login) && true == adminUser.getPassword().equals(password)) {
user.setLogin (login);
user.setPassword (password);
user.setIsAdmin (true);
response.sendRedirect ("protected/index.jsp");
} else {
final User sysUser = sysUsers.getUserByLogin (login);
if (null == sysUser) {
UserImpl newUser = new UserImpl();
newUser.setLogin (login);
newUser.setPassword (password);
newUser.setIsAdmin (false);
request.getSession().setAttribute("user", newUser);
sysUsers.addUser(newUser);
} else {
if (true == sysUser.getLogin().equals(login) && true == sysUser.getPassword().equals(password)) {
if (true == user.isNewUser()) {
user.setLogin (login);
user.setPassword (password);