package com.jw.app.common.action;

import java.util.HashMap;
import java.util.Map;

import com.gaowj.business.action.BasicAction;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.Encipher;
import com.gaowj.business.util.PropUtil;
import com.gaowj.business.util.RequestUtils;
import com.gaowj.business.util.Status;
import com.jw.app.business.UserBusiness;
import com.sun.xml.internal.messaging.saaj.util.Base64;

import net.sf.json.JSONObject;

public class mobileLoginActAction extends BasicAction{

	/**
	 * 整合到soologin里面
	 */
	private static final long serialVersionUID = 4065677491580537543L;
	private JSONObject jsonObject = new JSONObject();

	public JSONObject getJsonObject() {
		return jsonObject;
	}

	public void setJsonObject(JSONObject jsonObject) {
		this.jsonObject = jsonObject;
	}
    public String login() throws BusinessException{
    	UserBusiness business = BusinessManager.getBusiness(UserBusiness.class);
		Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
		String decodeflag = PropUtil.getValue("decodeflag","quartz_service","0");
		System.out.println("验证开始......");
			if(entity.get("PASSWORD") != null && entity.get("MOBILE") != null){
				String mobile = (String) entity.get("MOBILE");
				String password = null;
				if(decodeflag.equals("1")){
					password = Base64.base64Decode((String)entity.get("PASSWORD"));
				}else if (decodeflag.equals("0")){
					password = (String)entity.get("PASSWORD");
				}else{
					System.out.println("输出: 配置解码开关值错误");
					jsonObject.putAll(Status.getStatusErrorMessage("验证失败"));
				}
				System.out.println("密码： "+ password);
				Map<String, Object> query = new HashMap<String, Object>();
				query.put("MOBILE", mobile);
				System.out.println("输出：用户手机=" + mobile);
				Map<String, Object> map = business.listMobileUser(query);
				String userpass = Encipher.DecodePasswd((String)map.get("USER_PWD"));
				if(password.equals(userpass)){
					System.out.println("输出:密码正确，验证成功");
					jsonObject.putAll(Status.getStatusSuccessMessage("验证成功"));
				}else{
					System.out.println("输出:密码错误，验证失败");
					jsonObject.putAll(Status.getStatusErrorMessage("验证失败"));
				}
			}else{
				jsonObject.putAll(Status.getStatusErrorMessage("验证失败"));
				System.out.println("输出：参数错误....");
			}
			System.out.println("结束验证......");
		return "json";
    }
	
}
