package com.uas.platform.home.controller;

import java.io.IOException;

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

import com.uas.platform.home.core.support.SystemSession;
import com.uas.platform.home.web.BaseController;
import com.uas.sso.SSOHelper;

@Controller
public class AccountController extends BaseController {

	/**
	 * 账户信息、SSO配置
	 * 
	 * @return
	 */
	@RequestMapping(value = "/account", method = RequestMethod.GET)
	@ResponseBody
	public ModelMap getAccountInfo() {
		return success(SystemSession.getUser());
	}

	/**
	 * 跳转登录
	 *
	 * @throws IOException
	 */
	@RequestMapping(value = "/account/login", method = RequestMethod.GET)
	@ResponseBody
	public ModelMap getLoginPage() throws IOException {
		SSOHelper.clearLogin(request, response);
		return success(SSOHelper.getRedirectRefererLoginUrl(request));
	}

	/**
	 * 跳转登录
	 *
	 * @throws IOException
	 */
	@RequestMapping(value = "/account/logout", method = RequestMethod.GET)
	@ResponseBody
	public ModelMap logout() throws IOException {
		SSOHelper.clearLogin(request, response);
		return success();
	}

}
