550 lines
18 KiB
C#
550 lines
18 KiB
C#
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using System.Web;
|
||
using VRS.Util;
|
||
|
||
namespace VRS.Handler
|
||
{
|
||
/// <summary>
|
||
/// User 的摘要说明
|
||
/// </summary>
|
||
public class User : BaseHandler, IHttpHandler
|
||
{
|
||
DataService.BLL.admin_user bll = new DataService.BLL.admin_user();
|
||
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
|
||
|
||
DataService.BLL.pro_app bll_app = new DataService.BLL.pro_app();
|
||
|
||
public void ProcessRequest(HttpContext context)
|
||
{
|
||
//context.Response.ContentType = "text/plain";
|
||
baseContext = context;
|
||
context.Response.ContentType = "application/json";
|
||
CrossDomain();
|
||
if (null == context.Request["action"])
|
||
{
|
||
var result = GetResult(false, "缺少参数:action");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
string action = context.Request["action"];
|
||
switch (action)
|
||
{
|
||
//版本
|
||
case "version":
|
||
QueryVersion(context);
|
||
break;
|
||
|
||
|
||
|
||
//用户注册
|
||
case "reg":
|
||
RegUser(context);
|
||
break;
|
||
|
||
//用户登录
|
||
case "login":
|
||
LoginUser(context);
|
||
break;
|
||
|
||
//用户退出
|
||
case "exit":
|
||
ExitUser(context);
|
||
break;
|
||
|
||
//修改密码
|
||
case "changepassword":
|
||
ChangePassword(context);
|
||
break;
|
||
|
||
//修改用户资料
|
||
case "edituser":
|
||
EditUser(context);
|
||
break;
|
||
|
||
|
||
//查询单位
|
||
case "queryunit":
|
||
QueryUnit(context);
|
||
break;
|
||
|
||
//查询部门
|
||
case "querydepart":
|
||
QueryDepart(context);
|
||
break;
|
||
|
||
//上传应用情况
|
||
case "updatedsc":
|
||
UpdateDsc(context);
|
||
break;
|
||
|
||
default:
|
||
var result = GetResult(false, "方法名不存在:" + action);
|
||
context.Response.Write(result);
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查询版本
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void QueryVersion(HttpContext context)
|
||
{
|
||
|
||
|
||
var version = new
|
||
{
|
||
version = 1.0,
|
||
downloadurl = "www.baidu.com"
|
||
};
|
||
var result = GetResult(true, version);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询版本
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void UpdateDsc(HttpContext context)
|
||
{
|
||
string id = context.Request["id"];
|
||
string soft_dsc = context.Request["soft_dsc"];
|
||
string yw_dsc = context.Request["yw_dsc"];
|
||
string func_dsc = context.Request["func_dsc"];
|
||
|
||
var model = bll_app.GetModel(id);
|
||
if (null == model)
|
||
{
|
||
var result = GetResult(false, null, "对象不存在");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
model.soft_dsc = soft_dsc;
|
||
model.yw_dsc = yw_dsc;
|
||
model.func_dsc = func_dsc;
|
||
if (bll_app.Update(model))
|
||
{
|
||
var result = GetResult(true, null);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, null, "保存失败!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 查询单位
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void QueryUnit(HttpContext context)
|
||
{
|
||
/*
|
||
string city_id = context.Request["city_id"];
|
||
if (string.IsNullOrEmpty(city_id))
|
||
{
|
||
context.Response.Write(GetResult(false, "参数city_id不能为空"));
|
||
context.Response.End();
|
||
}
|
||
DataService.BLL.admin_unit bll = new DataService.BLL.admin_unit();
|
||
var majors = bll.GetModelList(string.Format(" city_id = '{0}' ", city_id));
|
||
var result = GetResult(true, majors);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
*/
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查询部门
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void QueryDepart(HttpContext context)
|
||
{
|
||
/*
|
||
DataService.BLL.pro_type_manage bll = new DataService.BLL.pro_type_manage();
|
||
var majors = bll.GetModelList(string.Format(" parent_id = 'sign_dep' "));
|
||
List<string> list_result = new List<string>();
|
||
if (majors.Count > 0)
|
||
{
|
||
majors.ForEach(s => { list_result.Add(s.type_name); });
|
||
}
|
||
var result = GetResult(true, list_result.ToArray());
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
*/
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void QueryUser(HttpContext context)
|
||
{
|
||
var ret = string.Empty;
|
||
var id_card = context.Request.Params["id_card"];
|
||
if (string.IsNullOrEmpty(id_card))
|
||
{
|
||
ret = GetResult(false, "身份证号码不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var userModel = bll.GetModelList(string.Format(" id_card = '{0}' ", id_card)).FirstOrDefault();
|
||
if (null != userModel)
|
||
{
|
||
userModel.password = "";
|
||
var result = GetResult(true, userModel);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, "身份证号码错误!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户退出
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void ExitUser(HttpContext context)
|
||
{
|
||
var ret = string.Empty;
|
||
var login_name = context.Request.Params["login_name"];
|
||
if (string.IsNullOrEmpty(login_name))
|
||
{
|
||
ret = GetResult(false, null, "登录账号不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var userModel = bll.GetModelList(string.Format(" login_name = '{0}' ", login_name)).FirstOrDefault();
|
||
if (null != userModel)
|
||
{
|
||
|
||
if (bll.Update(userModel))
|
||
{
|
||
var result = GetResult(true);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, null, "账号不存在!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, null, "账号不存在!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户登录
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void LoginUser(HttpContext context)
|
||
{
|
||
var ret = string.Empty;
|
||
var login_name = context.Request.Params["login_name"];
|
||
if (string.IsNullOrEmpty(login_name))
|
||
{
|
||
|
||
ret = GetResult(false, null, "登录账号不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var password = context.Request.Params["password"];
|
||
if (string.IsNullOrEmpty(password))
|
||
{
|
||
|
||
ret = GetResult(false, null, "密码不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var true_passord = password;
|
||
var pwd = BasePage.GetMD5(true_passord);
|
||
var userModel = bll.GetModelList(string.Format(" login_name = '{0}' and password= '{1}' ", login_name, pwd)).FirstOrDefault();
|
||
if (null != userModel)
|
||
{
|
||
if (userModel.is_lock == "是")
|
||
{
|
||
var result = GetResult(false, null, "用户已禁用!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
var dic = BasePage.DicRole();
|
||
|
||
var info = string.Format("网站用户登录,姓名:{0},角色:{1},id:{2}", userModel.real_name, dic.ContainsKey(userModel.user_role) ? dic[userModel.user_role] : userModel.user_role, userModel.user_id);
|
||
log.write_user_log(userModel, info);
|
||
userModel.password = "******";
|
||
|
||
/*
|
||
var Authority = context.Request.Url.Authority;
|
||
if (!string.IsNullOrEmpty(userModel.photo))
|
||
{
|
||
var new_url = "http://" + Authority + userModel.photo.Replace("~", "");
|
||
userModel.photo = new_url;
|
||
}
|
||
*/
|
||
|
||
|
||
if (dic.ContainsKey(userModel.user_role))
|
||
{
|
||
userModel.user_role_dsc = dic[userModel.user_role];
|
||
}
|
||
|
||
var result = GetResult(true, userModel);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, null, "用户名或密码错误!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 注册用户
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void RegUser(HttpContext context)
|
||
{
|
||
var data = context.Request.Params["data"];
|
||
var ret = string.Empty;
|
||
if (string.IsNullOrEmpty(data))
|
||
{
|
||
ret = GetResult(false, "data参数不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var model = JsonConvert.DeserializeObject<DataService.Model.admin_user>(data);
|
||
if (string.IsNullOrEmpty(model.real_name))
|
||
{
|
||
ret = GetResult(false, "姓名不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
if (string.IsNullOrEmpty(model.password))
|
||
{
|
||
ret = GetResult(false, "密码不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var userModel = bll.GetModelList(string.Format(" login_name = '{0}' ", model.login_name)).FirstOrDefault();
|
||
if (null != userModel)
|
||
{
|
||
var result = GetResult(false, "登录账号已经存在!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.mobile))
|
||
{
|
||
ret = GetResult(false, "手机号码不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
model.user_id = "USER" + GetNewId();
|
||
model.create_time = DateTime.Now;
|
||
model.password = GetMD5(model.password);
|
||
var flag = bll.Add(model);
|
||
if (flag)
|
||
{
|
||
var result = GetResult(true, model);
|
||
context.Response.Write(result);
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, model, "添加失败");
|
||
context.Response.Write(result);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 修改用户资料
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void EditUser(HttpContext context)
|
||
{
|
||
//用户id
|
||
var user_id = context.Request.Params["user_id"];
|
||
if (string.IsNullOrEmpty(user_id))
|
||
{
|
||
var ret = GetResult(false, "user_id参数不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var user = bll.GetModel(user_id);
|
||
if (null == user)
|
||
{
|
||
var ret = GetResult(false, null, "用户不存在,user_id:" + user_id);
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
if (context.Request.Params.AllKeys.Contains("nick_name"))
|
||
{
|
||
string paramValue = context.Request.Params["nick_name"];
|
||
user.nick_name = paramValue;
|
||
}
|
||
|
||
if (context.Request.Params.AllKeys.Contains("real_name"))
|
||
{
|
||
string paramValue = context.Request.Params["real_name"];
|
||
user.real_name = paramValue;
|
||
|
||
}
|
||
if (context.Request.Params.AllKeys.Contains("sex"))
|
||
{
|
||
string paramValue = context.Request.Params["sex"];
|
||
user.sex = paramValue;
|
||
}
|
||
|
||
if (context.Request.Params.AllKeys.Contains("mobile"))
|
||
{
|
||
string paramValue = context.Request.Params["mobile"];
|
||
user.mobile = paramValue;
|
||
}
|
||
|
||
if (context.Request.Params.AllKeys.Contains("unit"))
|
||
{
|
||
string paramValue = context.Request.Params["unit"];
|
||
user.unit = paramValue;
|
||
}
|
||
var flag = bll.Update(user);
|
||
if (flag)
|
||
{
|
||
var result = GetResult(true, null,"");
|
||
context.Response.Write(result);
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(false, null, "修改失败");
|
||
context.Response.Write(result);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改密码
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void ChangePassword(HttpContext context)
|
||
{
|
||
//用户id
|
||
var user_id = context.Request.Params["user_id"];
|
||
if (string.IsNullOrEmpty(user_id))
|
||
{
|
||
var ret = GetResult(false, "user_id参数不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var user = bll.GetModel(user_id);
|
||
if (null == user)
|
||
{
|
||
var ret = GetResult(false, null, "用户不存在,user_id:" + user_id);
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var old_password = context.Request.Params["old_password"];
|
||
if (string.IsNullOrEmpty(old_password))
|
||
{
|
||
var ret = GetResult(false, null, "原密码不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
var pass_word = BasePage.GetMD5(old_password);
|
||
var list_exists = bll.GetModelList(string.Format(" user_id = '{0}' and password='{1}' ", user_id, pass_word));
|
||
if (list_exists.Count <= 0)
|
||
{
|
||
var ret = GetResult(false, null, "原密码错误!");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var new_password = context.Request.Params["new_password"];
|
||
if (string.IsNullOrEmpty(new_password))
|
||
{
|
||
var ret = GetResult(false, null, "新密码不能为空!");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
/*
|
||
var newpassword = new_password.Text.Trim();
|
||
var confirm = confirm_password.Text.Trim();
|
||
|
||
if (string.IsNullOrEmpty(new_password.Text.Trim()))
|
||
{
|
||
RadAjaxManager1.Alert("");
|
||
return;
|
||
}
|
||
|
||
if (newpassword != confirm)
|
||
{
|
||
RadAjaxManager1.Alert("新密码与确认密码不一致!");
|
||
return;
|
||
}
|
||
*/
|
||
|
||
user.password = GetMD5(new_password);
|
||
if (bll.Update(user))
|
||
{
|
||
log.write_log("修改密码成功。" + "账号:" + user.login_name + ",ID:" + user.user_id);
|
||
var ret = GetResult(true, null, "");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
var ret = GetResult(false, null, "修改密码失败!");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
|
||
|
||
public bool IsReusable
|
||
{
|
||
get
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
} |