独立项目
This commit is contained in:
		@@ -2,14 +2,16 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-12-15 11:11:21
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2023-01-17 23:28:21
 | 
			
		||||
 * @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\controllers\account\P13AccountCheckController.java
 | 
			
		||||
 * @LastEditTime: 2023-03-25 17:28:39
 | 
			
		||||
 * @FilePath: /后端-用户验证/src/main/java/com/cpic/xim/web/controllers/account/P13AccountCheckController.java
 | 
			
		||||
 * @Description: P13账号验证用Controller。
 | 
			
		||||
 * 
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved.
 | 
			
		||||
 */
 | 
			
		||||
package com.cpic.xim.web.controllers.account;
 | 
			
		||||
 | 
			
		||||
import com.cpic.xim.myutils.account.CpicXIMStaffInfo;
 | 
			
		||||
import com.cpic.xim.myutils.account.LdapAccountCheck;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.nio.channels.IllegalSelectorException;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
@@ -21,94 +23,84 @@ import org.springframework.stereotype.Controller;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.ResponseBody;
 | 
			
		||||
import com.cpic.xim.myutils.account.CpicXIMStaffInfo;
 | 
			
		||||
import com.cpic.xim.myutils.account.LdapAccountCheck;
 | 
			
		||||
 | 
			
		||||
@Controller
 | 
			
		||||
@RequestMapping( path = "/account" )
 | 
			
		||||
@SuppressWarnings( "unused" )
 | 
			
		||||
public class P13AccountCheckController
 | 
			
		||||
{
 | 
			
		||||
    /*****************************************************
 | 
			
		||||
     * 根据用户提供的P09工号或者P13账号密码,查找用户信息,并AD域服务器验证p13账号密码。
 | 
			
		||||
     * 验证通过即返回人员信息。
 | 
			
		||||
     * 验证不通过result.success值为false,并在message提供失败原因。
 | 
			
		||||
     * @param param 由json格式转换的请求参数
 | 
			
		||||
     * @param request
 | 
			
		||||
     * @param response
 | 
			
		||||
     * @return 返回一个P13AccountCheckResult对象,其中提供验证结果
 | 
			
		||||
     *****************************************************/
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    @RequestMapping( path = "/p13_account_check" )
 | 
			
		||||
    public P13AccountCheckResult checkP13Account( @RequestBody P13AccountCheckRequest param,
 | 
			
		||||
            HttpServletRequest request, HttpServletResponse response )
 | 
			
		||||
            throws IllegalSelectorException, IOException
 | 
			
		||||
    {
 | 
			
		||||
        P13AccountCheckResult result = new P13AccountCheckResult();
 | 
			
		||||
        ServletContext context = request.getServletContext();
 | 
			
		||||
@RequestMapping(path = "/account")
 | 
			
		||||
@SuppressWarnings("unused")
 | 
			
		||||
public class P13AccountCheckController {
 | 
			
		||||
 | 
			
		||||
        // context.getAttribute( null );
 | 
			
		||||
        CpicXIMStaffInfo staff = null;
 | 
			
		||||
  /*****************************************************
 | 
			
		||||
   * 根据用户提供的P09工号或者P13账号密码,查找用户信息,并AD域服务器验证p13账号密码。
 | 
			
		||||
   * 验证通过即返回人员信息。
 | 
			
		||||
   * 验证不通过result.success值为false,并在message提供失败原因。
 | 
			
		||||
   * @param param 由json格式转换的请求参数
 | 
			
		||||
   * @param request
 | 
			
		||||
   * @param response
 | 
			
		||||
   * @return 返回一个P13AccountCheckResult对象,其中提供验证结果
 | 
			
		||||
   *****************************************************/
 | 
			
		||||
  @ResponseBody
 | 
			
		||||
  @RequestMapping(path = "/p13_account_check")
 | 
			
		||||
  public P13AccountCheckResult checkP13Account(
 | 
			
		||||
    @RequestBody P13AccountCheckRequest param,
 | 
			
		||||
    HttpServletRequest request,
 | 
			
		||||
    HttpServletResponse response
 | 
			
		||||
  ) throws IllegalSelectorException, IOException {
 | 
			
		||||
    P13AccountCheckResult result = new P13AccountCheckResult();
 | 
			
		||||
    ServletContext context = request.getServletContext();
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 先根据用户输入的09工号或p13账号获得p13账号,确定账号存在
 | 
			
		||||
            staff = CpicXIMStaffInfo.getStaffInfo( param.getP13Account() );
 | 
			
		||||
        }
 | 
			
		||||
        catch ( SQLException error )
 | 
			
		||||
        {
 | 
			
		||||
            staff = null;
 | 
			
		||||
            result.setMessage( "人员工号或P13账号不存在!" );
 | 
			
		||||
            result.setSuccess( false );
 | 
			
		||||
        }
 | 
			
		||||
        catch ( ClassNotFoundException error )
 | 
			
		||||
        {
 | 
			
		||||
            staff = null;
 | 
			
		||||
            result.setMessage( "加载Oracle驱动失败!" );
 | 
			
		||||
            result.setSuccess( false );
 | 
			
		||||
        }
 | 
			
		||||
    CpicXIMStaffInfo staff = null;
 | 
			
		||||
 | 
			
		||||
        // 查询结果是null,说明没有查询到结果,工号或p13账号不存在,返回结果。
 | 
			
		||||
        if ( staff == null )
 | 
			
		||||
        {
 | 
			
		||||
            result.setMessage( "人员工号或P13账号不存在!" );
 | 
			
		||||
            result.setSuccess( false );
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 判断一下p13是否存在,如果不存在就结束过程
 | 
			
		||||
        if ( staff.getP13UID().isEmpty() == true )
 | 
			
		||||
        {
 | 
			
		||||
            result.setMessage( "P13账号不存在,请联系信息技术部申请账号!" );
 | 
			
		||||
            result.setSuccess( false );
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 进行ldap验证
 | 
			
		||||
        boolean ldapCheckResult =
 | 
			
		||||
                LdapAccountCheck.ldapLogin( staff.getP13UID(), param.getPassword() );
 | 
			
		||||
 | 
			
		||||
        if ( ldapCheckResult == true )
 | 
			
		||||
        {
 | 
			
		||||
            result.setSuccess( true );
 | 
			
		||||
            result.setMessage( "验证成功!" );
 | 
			
		||||
            result.setStaffInfo( staff );
 | 
			
		||||
 | 
			
		||||
            // 将获取到的人员信息保存到会话中
 | 
			
		||||
            HttpSession session = request.getSession();
 | 
			
		||||
 | 
			
		||||
            session.setAttribute( "staff_info", staff );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            result.setSuccess( false );
 | 
			
		||||
            result.setMessage( "密码错误!" );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        result.setToken( param.getP13Account() );
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
    try {
 | 
			
		||||
      // 先根据用户输入的09工号或p13账号获得p13账号,确定账号存在
 | 
			
		||||
      staff = CpicXIMStaffInfo.getStaffInfo(param.getP13Account());
 | 
			
		||||
    } catch (SQLException error) {
 | 
			
		||||
      staff = null;
 | 
			
		||||
      result.setMessage("人员工号或P13账号不存在!");
 | 
			
		||||
      result.setSuccess(false);
 | 
			
		||||
    } catch (ClassNotFoundException error) {
 | 
			
		||||
      staff = null;
 | 
			
		||||
      result.setMessage("加载Oracle驱动失败!");
 | 
			
		||||
      result.setSuccess(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 查询结果是null,说明没有查询到结果,工号或p13账号不存在,返回结果。
 | 
			
		||||
    if (staff == null) {
 | 
			
		||||
      result.setMessage("人员工号或P13账号不存在!");
 | 
			
		||||
      result.setSuccess(false);
 | 
			
		||||
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 判断一下p13是否存在,如果不存在就结束过程
 | 
			
		||||
    if (staff.getP13UID().isEmpty() == true) {
 | 
			
		||||
      result.setMessage("P13账号不存在,请联系信息技术部申请账号!");
 | 
			
		||||
      result.setSuccess(false);
 | 
			
		||||
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 进行ldap验证
 | 
			
		||||
    boolean ldapCheckResult = LdapAccountCheck.ldapLogin(
 | 
			
		||||
      staff.getP13UID(),
 | 
			
		||||
      param.getPassword()
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (ldapCheckResult == true) {
 | 
			
		||||
      result.setSuccess(true);
 | 
			
		||||
      result.setMessage("验证成功!");
 | 
			
		||||
      result.setStaffInfo(staff);
 | 
			
		||||
 | 
			
		||||
      // 将获取到的人员信息保存到会话中
 | 
			
		||||
      HttpSession session = request.getSession();
 | 
			
		||||
 | 
			
		||||
      session.setAttribute("staff_info", staff);
 | 
			
		||||
    } else {
 | 
			
		||||
      result.setSuccess(false);
 | 
			
		||||
      result.setMessage("密码错误!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    result.setToken(param.getP13Account());
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user