package com.chen.web.controller;

import com.chen.pojo.Users;
import com.chen.pojo.UsersExt;
import com.chen.service.UsersService;
import com.chen.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

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

@Controller
@RequestMapping("/user")
public class UsersController {
    @Autowired
    private UsersService usersService;

    /**
     * 处理用户登录请求
     */
    @RequestMapping("/userLogin")
    public String userLogin(UsersExt users, HttpSession session, HttpServletRequest request){
        String ip = request.getRemoteAddr();
        users.setIp(ip);
        Users user=this.usersService.userLogin(users);
        session.setAttribute("user",user);
        return "redirect:/page/index";
    }
}
