using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Text;
namespace DSWeb.Accounts
{
public partial class AccountService : System.Web.UI.Page
{
private string strHandle;
private string strUserID;
private string strPassWord;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if (Request.QueryString["pwd"] != null)
{
strPassWord = Request.QueryString["pwd"].ToString().Trim();
}
if (strHandle != null)
{
if (strHandle == "getbaseinfo" && strUserID != null)
{
Response.Write(GetUserBaseInfo(strUserID));
}
if (strHandle == "validatepwd" && strUserID != null && strPassWord != null)
{
Response.Write(ValidatePassWord(strUserID, strPassWord));
}
}
}
#region 验证请求密码是否与原始密码一致
///
/// 验证请求密码是否与原始密码一致
///
/// 用户GID
/// 请求密码
/// 值1表示验证通过 值不等于1表示验证失败
private int ValidatePassWord(string tempUserID,string tempPassWord)
{
int iResult = 0;
UserDA userDA = new UserDA();
UserEntity userEntity = new UserEntity();
userEntity = userDA.GetUserSignByID(tempUserID);
if (userEntity != null)
{
if (userEntity.Gid != null)
{
if (userEntity.PassWord.Trim().Equals(tempPassWord))
{
iResult = 1;//验证通过
}
else
{
iResult = -1;//密码验证失败,与原密码不一致
}
}
}
return iResult;
}
#endregion
#region 获取用户个人信息
///
/// 获取用户个人信息
///
/// 用户GID
/// 返回JSON数据
private string GetUserBaseInfo(string tempUserID)
{
UserDA userDA = new UserDA();
string strSql = String.Format(" SELECT USERNAME,FAX,OFFICEPHONE,MOBILE,EMAIL1,EMAIL2,MSN,QQ FROM [user] as A INNER JOIN user_baseinfo as B ON A.GID = B.USERID WHERE A.GID = '{0}'", tempUserID);
DataTable sourceTable = userDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("base:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{uname:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("\"fax\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"office\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
sourceBuilder.Append("\"mobile\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"em1\":\"" + sourceTable.Rows[i][4].ToString() + "\",");
sourceBuilder.Append("\"em2\":\"" + sourceTable.Rows[i][5].ToString() + "\",");
sourceBuilder.Append("\"msn\":\"" + sourceTable.Rows[i][6].ToString() + "\",");
sourceBuilder.Append("\"qq\":\"" + sourceTable.Rows[i][7].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
}
}