863 lines
30 KiB
C#
863 lines
30 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>
|
||
/// 学员注册登录接口
|
||
/// </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_edition bll_edition = new DataService.BLL.pro_edition();
|
||
DataService.BLL.admin_unit bll_unit = new DataService.BLL.admin_unit();
|
||
DataService.BLL.admin_school bll_school = new DataService.BLL.admin_school();
|
||
|
||
DataService.BLL.pro_subject_batch_user bll_batch_user = new DataService.BLL.pro_subject_batch_user();
|
||
DataService.BLL.pro_exam_batch bll_exam_batch = new DataService.BLL.pro_exam_batch();
|
||
DataService.BLL.pro_examination bll_examination = new DataService.BLL.pro_examination();
|
||
DataService.BLL.pro_lianxi_batch bll_lianxi_batch = new DataService.BLL.pro_lianxi_batch();
|
||
|
||
DataService.BLL.base_config bll_base_config = new DataService.BLL.base_config();
|
||
|
||
DataService.BLL.pro_exam_batch_result bll_exam_batch_result = new DataService.BLL.pro_exam_batch_result();
|
||
|
||
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 "lang":
|
||
QueryLang(context);
|
||
break;
|
||
|
||
//用户注册
|
||
case "reg":
|
||
RegUser(context);
|
||
break;
|
||
|
||
//用户登录
|
||
case "login":
|
||
LoginUser(context);
|
||
break;
|
||
|
||
//用户退出
|
||
case "exit":
|
||
ExitUser(context);
|
||
break;
|
||
|
||
//登录理论考试
|
||
case "logintheory":
|
||
LoginTheoryUser(context);
|
||
break;
|
||
|
||
//查询省
|
||
case "queryprovince":
|
||
QueryProvince(context);
|
||
break;
|
||
|
||
//查询市
|
||
case "querycity":
|
||
QueryCity(context);
|
||
break;
|
||
|
||
//查询单位
|
||
case "queryunit":
|
||
QueryUnit(context);
|
||
break;
|
||
|
||
//查询部门
|
||
case "querydepart":
|
||
QueryDepart(context);
|
||
break;
|
||
|
||
//登录理论考试
|
||
case "loginlianxi":
|
||
LoginLianxiBatch(context);
|
||
break;
|
||
|
||
default:
|
||
var result = GetResult(false, "方法名不存在:" + action);
|
||
context.Response.Write(result);
|
||
break;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 查询语言
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void QueryLang(HttpContext context)
|
||
{
|
||
var model = bll_base_config.GetModelList("").FirstOrDefault();
|
||
var obj = new
|
||
{
|
||
show = model.show_lang_switch,
|
||
show_desc = "显示语言切换 1:是 、0:否",
|
||
default_lang = model.default_lang,
|
||
default_lang_desc = "默认语言 1 英文 0 中文"
|
||
};
|
||
|
||
var result = GetResult(true, obj);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
|
||
/// <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();
|
||
*/
|
||
|
||
string type = context.Request["type"];
|
||
if (string.IsNullOrEmpty(type))
|
||
{
|
||
context.Response.Write(GetResult(false, "类型不能为空"));
|
||
context.Response.End();
|
||
}
|
||
var model = bll_edition.GetModelList(" type='" + type + "' order by `first` DESC , `second` DESC , `third` DESC limit 1");
|
||
if (model.Count >= 1)
|
||
{
|
||
var version = new
|
||
{
|
||
version = model[0].version_number,
|
||
downloadurl = model[0].url
|
||
};
|
||
var result = GetResult(true, version);
|
||
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 QueryProvince(HttpContext context)
|
||
{
|
||
DataService.BLL.admin_province bll = new DataService.BLL.admin_province();
|
||
var majors = bll.GetModelList("");
|
||
var result = GetResult(true, majors);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询市
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void QueryCity(HttpContext context)
|
||
{
|
||
|
||
string province_id = context.Request["province_id"];
|
||
if (string.IsNullOrEmpty(province_id))
|
||
{
|
||
context.Response.Write(GetResult(false, "参数province_id不能为空"));
|
||
context.Response.End();
|
||
}
|
||
DataService.BLL.admin_city bll = new DataService.BLL.admin_city();
|
||
var majors = bll.GetModelList(string.Format(" province_id = '{0}' ", province_id));
|
||
var result = GetResult(true, majors);
|
||
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();
|
||
|
||
|
||
/*
|
||
DataService.BLL.admin_user bll_sysuser = new DataService.BLL.admin_user();
|
||
var array = bll_sysuser.GetFieldValues("dep_name");
|
||
var result = GetResult(true, array.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)
|
||
{
|
||
userModel.id_card = "";
|
||
userModel.login_time = null;
|
||
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 zz = EncryptionAndDecryption.Decrypt("2CF38DAE34E25679A48B9A82300D562E4B403A211399A727");
|
||
var ret = string.Empty;
|
||
var login_name = context.Request.Params["login_name"];
|
||
if (string.IsNullOrEmpty(login_name))
|
||
{
|
||
//ret = GetResult(false,null, EncryptionAndDecryption.Encrypt("身份证号码不能为空"));
|
||
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, EncryptionAndDecryption.Encrypt("密码不能为空"));
|
||
ret = GetResult(false, null, "密码不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var true_passord = "";
|
||
//var flag = context.Request.Params["flag"];
|
||
var flag = "1";
|
||
if (flag == "1")
|
||
{
|
||
true_passord = password;
|
||
}
|
||
else
|
||
{
|
||
true_passord = EncryptionAndDecryption.Decrypt(password);
|
||
}
|
||
if (string.IsNullOrEmpty(true_passord))
|
||
{
|
||
ret = GetResult(false, null, "密码不符合要求!");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
|
||
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 == 1)
|
||
{
|
||
|
||
var result = GetResult(false, null, "用户已禁用!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(userModel.school_id))
|
||
{
|
||
var obj = bll_school.GetModel(userModel.school_id);
|
||
if (null != obj)
|
||
{
|
||
userModel.school_name = obj.school;
|
||
}
|
||
}
|
||
#region 单端用户登录限制
|
||
var config = bll_base_config.GetModelList("").First();
|
||
if (config.user_more_client == 0)//单端用户登录限制
|
||
{
|
||
if (userModel.login_time.HasValue)
|
||
{
|
||
var old_ip = userModel.id_card;
|
||
var current_ip = context.Request.UserHostAddress;
|
||
if (old_ip != current_ip)
|
||
{
|
||
var minutues = (DateTime.Now.Subtract(userModel.login_time.Value).TotalSeconds) / 60;
|
||
var stay_minutes = config.user_stay_minutes;
|
||
if (minutues < stay_minutes)
|
||
{
|
||
var go = GetResult(false, null, "用户已登录,IP:" + old_ip);
|
||
context.Response.Write(go);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 过去登录限制:已解除
|
||
//60分钟内锁定 防止其他用户登录
|
||
/*
|
||
if (userModel.login_time.HasValue)
|
||
{
|
||
var old_ip = userModel.id_card;
|
||
var current_ip = context.Request.UserHostAddress;
|
||
if (old_ip != current_ip)
|
||
{
|
||
var minutues = (DateTime.Now.Subtract(userModel.login_time.Value).TotalSeconds) / 60;
|
||
if (minutues < 60)
|
||
{
|
||
var go = GetResult(false, null, "用户已登录,IP:"+ old_ip);
|
||
context.Response.Write(go);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
}
|
||
*/
|
||
|
||
//80% 几率登陆不上
|
||
// serverTime > 2024 - 7 - 27 退出
|
||
/*
|
||
var serverTime = DateTime.Now;
|
||
DateTime.TryParse("2024-8-15", out DateTime dtOut);
|
||
if (serverTime>= dtOut)
|
||
{
|
||
if (getRandom() != "0")
|
||
{
|
||
var go = GetResult(false, null, "1");
|
||
context.Response.Write(go);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
|
||
//serverTime < max(login_time) 退出
|
||
DateTime? dtLogin = bll.GetMaxLoginTime();
|
||
if (dtLogin.HasValue)
|
||
{
|
||
if (serverTime< dtLogin.Value)
|
||
{
|
||
if (getRandom() != "0")
|
||
{
|
||
var go = GetResult(false, null, "2");
|
||
context.Response.Write(go);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
}
|
||
*/
|
||
#endregion
|
||
|
||
var update_user = bll.GetModel(userModel.user_id);
|
||
update_user.login_time = DateTime.Now;
|
||
update_user.id_card = context.Request.UserHostAddress;
|
||
bll.Update(update_user);
|
||
|
||
userModel.password = "";
|
||
var info = string.Format("用户登录,姓名:{0},角色:{1},id:{2}", userModel.real_name, ConfigInfo.DicRole.ContainsKey(userModel.role_id) ? ConfigInfo.DicRole[userModel.role_id] : userModel.role_id, userModel.user_id);
|
||
log.write_user_log(userModel, info);
|
||
|
||
var result = GetResult(true, userModel);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//var result = GetResult(false,null, EncryptionAndDecryption.Encrypt("用户名或密码错误!"));
|
||
var result = GetResult(false, null, "用户名或密码错误!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
}
|
||
|
||
private string getRandom()
|
||
{
|
||
var array = new string[] { "0", "1", "2", "3", "4" };
|
||
return array.OrderBy(s => Guid.NewGuid()).First();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 理论考试用户登录
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void LoginTheoryUser(HttpContext context)
|
||
{
|
||
|
||
var ret = string.Empty;
|
||
var user_id = context.Request.Params["user_id"];
|
||
if (string.IsNullOrEmpty(user_id))
|
||
{
|
||
ret = GetResult(false, null, "user_id不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var PageIndex = context.Request.Params["PageIndex"];
|
||
if (string.IsNullOrEmpty(PageIndex))
|
||
{
|
||
ret = GetResult(false, null, "PageIndex不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var PageSize = context.Request.Params["PageSize"];
|
||
if (string.IsNullOrEmpty(PageSize))
|
||
{
|
||
ret = GetResult(false, null, "PageSize不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var State = context.Request.Params["State"];
|
||
|
||
int count = 0;
|
||
var index = int.Parse(PageIndex);
|
||
var size = int.Parse(PageSize);
|
||
string where = "user_id='" + user_id + "'";
|
||
|
||
var batch_user_list = bll_batch_user.GetModelPageList(where, index, size, "create_time", true, true, State, ref count);
|
||
|
||
var now = DateTime.Now;
|
||
foreach (var item in batch_user_list)
|
||
{
|
||
var batch = bll_exam_batch.GetModel(item.batch_id);
|
||
if (null != batch)
|
||
{
|
||
if (now < batch.start_time.Value)
|
||
{
|
||
item.batch_state = " 未开始";
|
||
}
|
||
else if (now >= batch.start_time.Value && now < batch.end_time.Value)
|
||
{
|
||
item.batch_state = " 进行中";
|
||
}
|
||
else if (now >= batch.end_time.Value)
|
||
{
|
||
item.batch_state = " 已结束";
|
||
}
|
||
item.start_time = batch.start_time.Value;
|
||
item.end_time = batch.end_time.Value;
|
||
item.ks_minute = batch.ks_minute;
|
||
|
||
var exam = bll_examination.GetModel(batch.exam_id);
|
||
if (null != exam)
|
||
{
|
||
item.total_score = exam.total_score;
|
||
item.pass_score = exam.pass_score.Value;
|
||
}
|
||
else
|
||
{
|
||
item.total_score = "0";
|
||
item.pass_score = 0;
|
||
}
|
||
}
|
||
|
||
if (item.state == 0)
|
||
{
|
||
//'0' COMMENT '状态 0 未考试、已考试',
|
||
item.user_state = "未考试";
|
||
}
|
||
else if (item.state == 1)
|
||
{
|
||
item.user_state = "已考试";
|
||
}
|
||
}
|
||
var msg = count.ToString();
|
||
var result = GetResult(true, batch_user_list, msg);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 练习考试获取批次
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void LoginLianxiBatch(HttpContext context)
|
||
{
|
||
var ret = string.Empty;
|
||
var user_id = context.Request.Params["user_id"];
|
||
if (string.IsNullOrEmpty(user_id))
|
||
{
|
||
ret = GetResult(false, null, "user_id不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var PageIndex = context.Request.Params["PageIndex"];
|
||
if (string.IsNullOrEmpty(PageIndex))
|
||
{
|
||
ret = GetResult(false, null, "PageIndex不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var PageSize = context.Request.Params["PageSize"];
|
||
if (string.IsNullOrEmpty(PageSize))
|
||
{
|
||
ret = GetResult(false, null, "PageSize不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var SubjectType = context.Request.Params["SubjectType"];
|
||
|
||
int count = 0;
|
||
var index = int.Parse(PageIndex);
|
||
var size = int.Parse(PageSize);
|
||
//string where = "user_id='" + user_id + "'";
|
||
string where = " state =1 ";
|
||
var user = bll.GetModel(user_id);
|
||
if (null == user)
|
||
{
|
||
ret = GetResult(false, null, "用户不存在:" + user_id);
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
if (!string.IsNullOrEmpty(user.school_id))
|
||
{
|
||
where = where + " and school_id='" + user.school_id + "' ";
|
||
}
|
||
if (!string.IsNullOrEmpty(SubjectType))
|
||
{
|
||
where = where + " and subject_type='" + SubjectType + "' ";
|
||
}
|
||
|
||
var lianxi_batch_list = bll_lianxi_batch.GetPageList(where, index, size, "batch_id", true, true, ref count);
|
||
var now = DateTime.Now;
|
||
List<LianxiBatchResponse> list_result = new List<LianxiBatchResponse>();
|
||
foreach (var item in lianxi_batch_list)
|
||
{
|
||
var obj = new LianxiBatchResponse();
|
||
obj.batch_id = item.batch_id;
|
||
obj.exam_id = item.exam_id;
|
||
obj.subject = item.subject;
|
||
obj.ks_minute = item.ks_minute;
|
||
var exam = bll_examination.GetModel(item.exam_id);
|
||
if (null != exam)
|
||
{
|
||
obj.pass_score = exam.pass_score;
|
||
obj.total_score = exam.total_score;
|
||
}
|
||
var ks_count = bll_exam_batch_result.GetRecordCount("batch_id='" + item.batch_id + "' and user_id='" + user.user_id + "'");
|
||
obj.ks_count = ks_count;
|
||
|
||
list_result.Add(obj);
|
||
}
|
||
var msg = count.ToString();
|
||
var result = GetResult(true, list_result, msg);
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
|
||
public class LianxiBatchResponse
|
||
{
|
||
public string batch_id { get; set; }
|
||
public string exam_id { get; set; }
|
||
public string subject { get; set; }
|
||
public int ks_minute { get; set; }
|
||
|
||
public string total_score { get; set; }
|
||
public decimal? pass_score { get; set; }
|
||
|
||
/// <summary>
|
||
/// 批次考试次数
|
||
/// </summary>
|
||
public int ks_count { get; set; }
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <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();
|
||
}
|
||
|
||
|
||
if (string.IsNullOrEmpty(model.id_card))
|
||
{
|
||
ret = GetResult(false, "登录账号不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var userModel = bll.GetModelList(string.Format(" id_card = '{0}' ", model.id_card)).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.unit_id = unit.unit_id;
|
||
//model.unit_name = unit.unit_name;
|
||
|
||
model.role_id = bll.getStudentRoleId();
|
||
|
||
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);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
#region 旧有方法
|
||
/// <summary>
|
||
/// 注册用户
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
public void RegUser_old(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.id_card))
|
||
{
|
||
ret = GetResult(false, "身份证号不能为空");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
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();
|
||
}
|
||
|
||
|
||
if (!BasePage.IsIdcard(model.id_card))
|
||
{
|
||
ret = GetResult(false, "身份证号码格式错误");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
if (model.id_card.Length == 18 && !BasePage.Is_valid_idcard18(model.id_card))
|
||
{
|
||
ret = GetResult(false, "18位身份证号码格式错误");
|
||
context.Response.Write(ret);
|
||
context.Response.End();
|
||
}
|
||
|
||
var userModel = bll.GetModelList(string.Format(" id_card = '{0}' ", model.id_card)).FirstOrDefault();
|
||
if (null != userModel)
|
||
{
|
||
var result = GetResult(false, "身份证号码已经存在!");
|
||
context.Response.Write(result);
|
||
context.Response.End();
|
||
}
|
||
//获取性别
|
||
var sex_str = model.id_card.Substring(model.id_card.Length - 2, 1);
|
||
string[] woman = new string[] { "0", "2", "4", "6", "8" };
|
||
model.sex = "男";
|
||
if (woman.Contains(sex_str))
|
||
{
|
||
model.sex = "女";
|
||
}
|
||
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);
|
||
}
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
public bool IsReusable
|
||
{
|
||
get
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
} |