package cn.com.qmth.stmms.api.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.qmth.stmms.biz.api.auth.annotation.AuthValidate;
import cn.com.qmth.stmms.biz.user.model.User;
import cn.com.qmth.stmms.common.utils.RequestUtils;
import net.sf.json.JSONObject;

@Controller("loginApiController")
@RequestMapping("/api")
public class LoginController extends BaseApiController {

    @AuthValidate("adminUser")
    @RequestMapping(value = "/user/login", method = RequestMethod.GET)
    @ResponseBody
    public JSONObject login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        User user = RequestUtils.getApiUser(request);
        JSONObject obj = new JSONObject();
        obj.accumulate("userId", user.getId());
        obj.accumulate("userName", user.getName());
        obj.accumulate("campusId", 0);
        obj.accumulate("schoolId", user.getSchoolId());
        return obj;
    }
}
