UsersController.java 2.65 KB
package com.cnlive.shenhe.controller;

import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.utils.CommonUtils;
import org.jasig.cas.client.authentication.AttributePrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * @Auther: 周伟鹏
 * @Date: 2018/11/29 14:22
 * @Description:
 */
@Controller
@RequestMapping("/users")
public class UsersController {

    @Autowired
    UsersServiceImpl usersService;

    @GetMapping(value = "/{id}")
    @ResponseBody
    public Object getTest(@PathVariable Integer id) {
        return usersService.get(id);
    }

    @RequestMapping("/login")
    public String index(HttpServletRequest request) {
        AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
        if (CommonUtils.isNull(principal)) {
            return "redirect:https://user.cnlive.com/OpenSSO2/login?service=http://test.shen.cnlive.com/users/login";
        }
        //用户ID
        String id = principal.getName();
        if (CommonUtils.isNotEmpty(id)) {
            ShyUsers user = usersService.get(Integer.parseInt(id));
            if (CommonUtils.isNotNull(user) && user.getState()) {
                SessionUser sessionUser = new SessionUser();
                sessionUser.setUserId(user.getUser_id());
                sessionUser.setSpid(Integer.parseInt(principal.getAttributes().get("new_sp_id").toString()));
                sessionUser.setUserName(user.getUsername());
                sessionUser.setCompany(user.getCompany_brief());
                sessionUser.setEmail(user.getEmail());
                sessionUser.setLogo(user.getUser_logo());
                sessionUser.setMaster(user.getMaster());
                request.getSession().setAttribute(SessionUser.SESSION_KEY, sessionUser);
                return "redirect:http://test.shen.cnlive.com/videos/page?video_title=&start_date=&end_date=&state=0&receive=0&video_priority=";
            }
        }
        return "page/error.html";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "redirect:https://user.cnlive.com/OpenSSO2/logout?service=http://test.shen.cnlive.com/users/login";
    }


}