br.com.arduinoweb.controller.UserController.java Source code

Java tutorial

Introduction

Here is the source code for br.com.arduinoweb.controller.UserController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.arduinoweb.controller;

import br.com.arduinoweb.model.User;
import br.com.arduinoweb.service.ArduinoService;
import br.com.arduinoweb.model.SystemProperties;
import br.com.arduinoweb.service.UserService;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 *
 * @author Rodolfo
 */
@Controller
public class UserController {

    @RequestMapping("/")
    public String Login(HttpSession session) {
        session.removeAttribute("usuarioLogado");
        return "redirect:/Login";
    }

    @RequestMapping("/Login")
    public String Login(HttpSession session, HttpServletResponse response, HttpServletRequest request) {
        session.removeAttribute("usuarioLogado");
        session.removeAttribute("ip");
        session.removeAttribute("porta");
        session.removeAttribute("conexao");
        return "User/Login";
    }

    @RequestMapping("actions/Login")
    public String UserAuthentication(User user, HttpSession session, HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        User logado = new UserService().Authentic(user);
        if (logado != null) {
            new SystemProperties().setAttributeSession(session);

            if (new ArduinoService(session).TestaConexao()) {
                session.setAttribute("conexao", "btn-success");
            } else {
                session.setAttribute("conexao", "btn-danger");
            }
            session.setAttribute("usuarioLogado", logado);

        } else {
            session.setAttribute("erro", "Usurio/Senha Incorretos!");
            return "redirect:/Login";
        }
        return "redirect:/Home";
    }
}