Admin.Admin/Login --- 后台项目中的管理员及登录模块

本文介绍了后台项目中管理员模块的设计,重点讲解了登录功能的实现。通过阅读,你可以了解到如何在PHP环境下构建一个管理员登录系统。
摘要由CSDN通过智能技术生成

 

管理员模块:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using DIDAO.BLL;
using DIDAO.Common;
using DIDAO.Model;

namespace DIDAO.Admin.Admin
{
    /// <summary>
    /// AdminController 的摘要说明
    /// </summary>
    public class AdminController : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            MyORM_BLL myORM_BLL = new MyORM_BLL();
            string btnSave = context.Request["btnSave"];
            string action = context.Request["action"];
            if (string.IsNullOrWhiteSpace(btnSave))
            {
                if (action == "list") //列表
                {
                    List<object> list = myORM_BLL.SelectModelByField(typeof(TD_ADMIN), "STATUS=1"); //查询正常的管理员
                    RazorHelper.RazorParse(context, "~/Admin/AdminList.cshtml", list);
                }
                else if (action == "addnew") //新增展示
                {
                    TD_ADMIN admin = new TD_ADMIN();
                    RazorHelper.RazorParse(context, "~/Admin/AdminAlter.cshtml", new { action = "addnew", admin = admin });
                }
                else if (action == "edit") //编辑展示
                {
                    #region 编辑展示
                    string idStr = context.Request["id"];
                    int id = VolidHelper.CheckStrToInt(idStr);
                    object obj = myORM_BLL.SelectModelById(typeof(TD_ADMIN), id);
                    if (obj == null)
                    {
                        RazorHelper.RazorParse(context, "~/error.cshtml", new { Msg = "未找到用户:" + id }); //出错
                        return;
                    }
                    TD_ADMIN admin = obj as TD_ADMIN;
                    RazorHelper.RazorParse(context, "~/Admin/AdminAlter.cshtml", new { action="edit",admin=admin});
                    #endregion
                }
                else if (action == "delete") //删除
                {
                    #region 删除
                    string idStr = context.Request["id"];
                    int id = VolidHelper.CheckStrToInt(idStr);
                    bool flag = myORM_BLL.DeleteOrDisableModelByUpdateStatus(typeof(TD_ADMIN),2, id); //status=2
                    if (flag)
                    {
                        context.Response.Redirect("/Admin/AdminController.ashx?action=list");
                    }
                    else
                    {
                        RazorHelper.RazorParse(context, "~/error.cshtml",  new { Msg = "删除操作失败:"+id }); //出错
                    }
                    #endregion
                }
                else if (action == "batchDelete") //批量删除
                {
                    string idStr = context.Request["idStr"].Trim(',');
                    if (!VolidHelper.CheckStringIsAllInt(idStr)) //判断idStr是否每一项都是数字
                    {
                        AjaxHelper.WriteJson(context, "error", "批量禁用失败:id字符串中含有非数字");
                    }
                    bool flag = myORM_BLL.DeleteOrDiableModelByIdList(typeof(TD_ADMIN), 2, idStr);
                    if (!flag)
                    {
                        AjaxHelper.WriteJson(context, "error", "批量禁用失败");
                    }
                    AjaxHelper.WriteJson(context, "ok", "成功");
                }
                else if (action == "disable") //禁用
                {
                    #region 禁用
                    string idStr = context.Request["id"];
                    int id = VolidHelper.CheckStrToInt(idStr);
                    bool flag = myORM_BLL.DeleteOrDisableModelByUpdateStatus(typeof(TD_ADMIN), 3, id); //status=3
                    if (flag)
                    {
                        context.Response.Redirect("/Admin/AdminController.ashx?action=list");
                    }
                    else
                    {
                        RazorHelper.RazorParse(context, "~/error.cshtml", new { Msg = "禁用操作失败:" + id }); //出错
                    }
                    #endregion
                }
                else
                {
                    throw new Exception("action错误:" + action);
                }
            }
            else //保存
            {
                string USERNAME = context.Request["USERNAME"];
                string PASSWORD = context.Request["PASSWORD"];
                string RePASSWORD = context.Request["RePASSWORD"];
                string REALNAME = context.Request["REALNAME"];
                string MOBILE = context.Request["MOBILE"];
                string EMAIL = context.Request["EMAIL"];
                string IDCARD = context.Request["IDCARD"];
                string ADDRESS = context.Request["ADDRESS"];

                #region 验证 非空,长度,是否符合格式
                //验证 非空,长度,是否符合格式
                if (string.IsNullOrWhiteSpace(USERNAME) || USERNAME.Length < 3)
                {
                    AjaxHelper.WriteJson(context, "error", "用户名至少3位");
                    return;
                }
                if (string.IsNullOrWhiteSpace(PASSWORD) || PASSWORD.Length < 6)
                {
                    AjaxHelper.WriteJson(context, "error", "密码至少6位");
                    return;
                }
                if (string.IsNullOrWhiteSpace(RePASSWORD) || RePASSWORD != PASSWORD)
                {
                    AjaxHelper.WriteJson(context, "error", "密码不一致");
                    return;
                }
                if (string.IsNullOrWhiteSpace(REALNAME) || REALNAME.Length < 2)
                {
                    AjaxHelper.WriteJson(context, "error", "必须是真是姓名");
                    return;
                }
                if (string.IsNullOrWhiteSpace(MOBILE) || MOBILE.Length != 11)
                {
                    AjaxHelper.WriteJson(context, "error", "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值