Beispiel #1
0
        public string Added(FormCollection form)
        {
            var stateInfo = GeneralHandler.StateSuccess;

            if (AddedByCheck(form, out stateInfo))
            {
                DawnAuthUserMDL dataInfo = new DawnAuthUserMDL();
                dataInfo.DptId       = TypeHelper.TypeToTinyInt(form["sltDepart"], 1);
                dataInfo.UserTime    = DateTime.Now;
                dataInfo.UserStatus  = 1;
                dataInfo.UserGrade   = TypeHelper.TypeToTinyInt(form["ddlGrade"], 1);
                dataInfo.UserSurname = form["txtSurname"];
                dataInfo.UserName    = form["txtName"];
                dataInfo.UserPwd     = CryptoHelper.MD5(form["txtPwd"], true);
                dataInfo.UserMobile  = form["txtMobile"];
                dataInfo.UserEmail   = form["txtEmail"];
                dataInfo.UserDesc    = form["txtDesc"];
                bool added = DawnAuthUserBLL.Exists(string.Format("user_name='{0}'", dataInfo.UserName));
                if (added)
                {
                    stateInfo = GeneralHandler.StateAdded;
                }
                else
                {
                    DawnAuthUserBLL.Insert(dataInfo);
                }
            }
            return(stateInfo);
        }
Beispiel #2
0
        public string Passworded(FormCollection form)
        {
            string oldPwd = form["txtOldPwd"] as string;
            string newPwd = form["txtNewPwd"] as string;
            string cifPwd = form["txtCifPwd"] as string;

            if (oldPwd == newPwd)
            {
                return("新密码不能与旧密码相同!");
            }
            oldPwd = CryptoHelper.MD5(oldPwd, true);
            if (oldPwd != DawnauthHandler.UserInfo.UserPwd)
            {
                return("您输入的旧密码有误,请重新输入。");
            }
            if (newPwd != cifPwd)
            {
                return("你输入的密码与确认密码不一致!");
            }
            var stateInfo = GeneralHandler.StateSuccess;

            cifPwd = CryptoHelper.MD5(newPwd, true);
            DawnAuthUserBLL.Update(DawnauthHandler.UserId, cifPwd);
            return(stateInfo);
        }
Beispiel #3
0
        /// <summary>
        /// 管理员信息数据编辑
        /// </summary>
        /// <param name="id">管理员编号</param>
        /// <param name="pager">页码</param>
        /// <returns>执行结果</returns>
        public ActionResult Editor(string id, string pager)
        {
            if (string.IsNullOrEmpty(id) || TypeHelper.TypeToInt32(id, -1) < 0)
            {
                return(RedirectToAction("List"));
            }
            var dataInfo = DawnAuthUserBLL.Select(int.Parse(id));

            ViewBag.PageCurrent = pager;
            return(View(dataInfo));
        }
Beispiel #4
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="userId">用户编号</param>
 /// <param name="userPwd">用户密码</param>
 public static void ChangePassword(int userId, string userPwd)
 {
     if (userId < 1 || string.IsNullOrEmpty(userPwd))
     {
         return;
     }
     if (userPwd.Length != 32)
     {
         userPwd = CryptoHelper.MD5(userPwd, true);
     }
     DawnAuthUserBLL.Update(userId, userPwd);
 }
Beispiel #5
0
        /// <summary>
        /// 管理员信息数据列表
        /// </summary>
        /// <param name="id">页码</param>
        /// <returns>执行结果</returns>
        public ActionResult List(string id)
        {
            var pager = new PagerHelperCHS();

            pager.PageSize    = GeneralHandler.PageSize;
            pager.PageCurrent = TypeHelper.TypeToInt32(id, 1);
            int pageCount, recordCount;
            var dataList = DawnAuthUserBLL.SelectPSPisAllPurposeRowNumber(pager.PageSize, pager.PageCurrent, null, out pageCount, out recordCount);

            pager.PageCount       = pageCount;
            pager.RecordCount     = recordCount;
            pager.PageRecordCount = dataList.Count;
            ViewBag.FPager        = pager;
            ViewBag.PageCurrent   = pager.PageCurrent;
            ViewBag.FDepartList   = DawnAuthDepartmentBLL.ISelect();
            return(View(dataList));
        }
Beispiel #6
0
        public string Delete(string id)
        {
            if (string.IsNullOrEmpty(id) || TypeHelper.TypeToInt32(id, -1) < 0)
            {
                return(GeneralHandler.FBaseInfo);
            }
            var stateInfo = GeneralHandler.StateSuccess;

            if (int.Parse(id) == DawnauthHandler.UserId)
            {
                stateInfo = "不可对当前登录管理员进行数据删除操作!";
            }
            else
            {
                //形象照片
                var picList = DawnAuthUserPicBLL.ISelect();
                foreach (var item in picList)
                {
                    DawnAuthUserPicBLL.Delete(item.PicId);
                }
                //登录日志
                var logList = DawnAuthUserLoginBLL.ISelect();
                foreach (var item in logList)
                {
                    DawnAuthUserLoginBLL.Delete(item.LogId);
                }
                //角色映射
                var roleList = DawnAuthUserRoleBLL.ISelect();
                foreach (var item in roleList)
                {
                    DawnAuthUserRoleBLL.Delete(item.MapId);
                }
                //状态机制
                var statList = DawnAuthUserStatusBLL.ISelect();
                foreach (var item in statList)
                {
                    DawnAuthUserStatusBLL.Delete(item.MapId);
                }
                //管理员数据
                DawnAuthUserBLL.Delete(int.Parse(id));
            }
            return(stateInfo);
        }
Beispiel #7
0
        public string Reset(string id)
        {
            if (string.IsNullOrEmpty(id) || TypeHelper.TypeToInt32(id, -1) < 0)
            {
                return(GeneralHandler.FBaseInfo);
            }
            var stateInfo = GeneralHandler.StateSuccess;

            if (int.Parse(id) == DawnauthHandler.UserId)
            {
                stateInfo = "不可对当前登录管理员进行密码重置操作!";
            }
            else
            {
                stateInfo  = "Dawn";
                stateInfo += CheckCodeHelper.GetEngAndNum(8);
                DawnAuthUserBLL.Update(int.Parse(id), CryptoHelper.MD5(stateInfo, true));
            }
            return(stateInfo);
        }
Beispiel #8
0
        /// <summary>
        /// 管理员登录信息数据列表
        /// </summary>
        /// <param name="id">管理员编号</param>
        /// <param name="pager">页码</param>
        /// <returns>执行结果</returns>
        public ActionResult LoginDetailed(string id, string pager)
        {
            if (string.IsNullOrEmpty(id) || TypeHelper.TypeToInt32(id, -1) < 0)
            {
                return(RedirectToAction("List"));
            }
            var dataPager = new PagerHelperCHS();

            dataPager.PageSize    = GeneralHandler.PageSize;
            dataPager.PageCurrent = TypeHelper.TypeToInt32(pager, 1);
            int pageCount, recordCount;
            var dataList = DawnAuthUserLoginBLL.SelectPSPisAllPurposeRowNumber(dataPager.PageSize, dataPager.PageCurrent, string.Format("user_id='{0}'", int.Parse(id)), out pageCount, out recordCount);

            dataPager.PageCount       = pageCount;
            dataPager.RecordCount     = recordCount;
            dataPager.PageRecordCount = dataList.Count;
            ViewBag.FPager            = dataPager;
            ViewBag.UserSurname       = DawnAuthUserBLL.Select(int.Parse(id)).UserSurname;
            return(View(dataList));
        }
Beispiel #9
0
        public string Editored(FormCollection form)
        {
            if (TypeHelper.TypeToInt32(form["hidUserId"], -1) < 0)
            {
                return(GeneralHandler.FBaseInfo);
            }
            var stateInfo = GeneralHandler.StateSuccess;

            if (EditoredByCheck(form, out stateInfo))
            {
                DawnAuthUserMDL dataInfo = new DawnAuthUserMDL();
                dataInfo.UserId      = int.Parse(form["hidUserId"]);
                dataInfo.DptId       = TypeHelper.TypeToTinyInt(form["sltDepart"], 1);
                dataInfo.UserGrade   = TypeHelper.TypeToTinyInt(form["ddlGrade"], 1);
                dataInfo.UserSurname = form["txtSurname"];
                dataInfo.UserMobile  = form["txtMobile"];
                dataInfo.UserEmail   = form["txtEmail"];
                dataInfo.UserDesc    = form["txtDesc"];
                DawnAuthUserBLL.UpdateEditor(dataInfo);
            }
            return(stateInfo);
        }
Beispiel #10
0
        /// <summary>
        /// 用户登录验证
        /// <para>返回的哈希表包含键值:</para>
        /// <para>Msg 消息正文,值为[refresh]时需要刷新整个页面</para>
        /// <para>Url 跳转的URL链接</para>
        /// <para>IsCode 刷新验证码</para>
        /// </summary>
        /// <param name="userName">帐号名称</param>
        /// <param name="userPwd">帐号密码</param>
        /// <param name="checkCode">验证码</param>
        /// <param name="returnUrl">登录跳转页面</param>
        /// <param name="outEx">异常信息对象</param>
        /// <returns>验证结果</returns>
        public static Hashtable VerifyLogin(string userName, string userPwd, string checkCode, string returnUrl, out Exception outEx)
        {
            outEx = null;
            Hashtable ht = new Hashtable();

            ht.Add("Msg", GeneralHandler.FBaseInfo);
            ht.Add("Url", GeneralHandler.SiteLoginUrl);
            ht.Add("IsCode", false);
            try
            {
                if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(userPwd) || string.IsNullOrEmpty(checkCode))
                {
                    return(ht);
                }
                userPwd   = CryptoHelper.MD5(userPwd, true);
                checkCode = checkCode.ToLower();
                string verifyCode = HttpContext.Current.Session["CheckCode"] as string;
                verifyCode = verifyCode.ToLower();
                if (checkCode.Length != 4 || !ValidHelper.EngIsEngAndNum(checkCode) || checkCode != verifyCode)
                {
                    ht["Msg"]    = "您输入的验证码不正确[4个字符]。";
                    ht["IsCode"] = true;
                }
                else if (userName.Length < 4 || userName.Length > 16 || !ValidHelper.EngIsRegisters(userName))
                {
                    ht["Msg"] = "您输入的用户名不正确[4-16个字符]。";
                }
                else if (ValidHelper.IsSqlFilter(userName))
                {
                    ht["Msg"] = "您输入的用户名不正确[4-16个字符]。IsSqlFilter";
                }
                else if (!DawnAuthUserBLL.ExistsOfName(userName))
                {
                    ht["Msg"] = "您输入的用户名不存在!";
                }
                else
                {
                    var userIList = DawnAuthUserBLL.ISelect(string.Format("[user_name]='{0}' and [user_pwd]='{1}'", userName, userPwd));
                    if (userIList.Count == 0)
                    {
                        ht["Msg"] = "您输入的用户名与密码不匹配!";
                    }
                    else if (userIList.Count > 1)
                    {
                        ht["Msg"] = "您的账号存在异常,请联系管理员!";
                    }
                    else
                    {
                        var userInfo = userIList.First();
                        if (userInfo.UserStatus == 0)
                        {
                            ht["Msg"] = "您的账号存已禁用,请联系管理员!";
                        }
                        else if (userInfo.UserGrade < 1)
                        {
                            ht["Msg"] = "对不起,您的管理级别不符合!";
                        }
                        else
                        {
                            userIList.Clear();
                            HttpContext.Current.Session["LoginName"] = userName;
                            HttpContext.Current.Session[userName]    = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userInfo), GeneralHandler.TokenKey);
                            var userAuth = DawnAuthUserBLL.GetUserAuthority(userInfo.UserId);
                            HttpContext.Current.Session["LoginAuthority"] = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userAuth), GeneralHandler.TokenKey);
                            var userStat = DawnAuthUserBLL.GetUserStatus(userInfo.UserId);
                            HttpContext.Current.Session["LoginStatus"] = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userStat), GeneralHandler.TokenKey);
                            var userExtent = DawnAuthUserExtentBLL.ISelect(string.Format("user_id='{0}'", userInfo.UserId));
                            HttpContext.Current.Session["LoginExtent"] = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userExtent), GeneralHandler.TokenKey);
                            FormsAuthentication.SetAuthCookie(CryptoHelper.Encrypt(userName, GeneralHandler.TokenKey), false);

                            #region 登录日志

                            DawnAuthUserLoginMDL dataInfo = new DawnAuthUserLoginMDL();
                            dataInfo.UserId      = userInfo.UserId;
                            dataInfo.LogTime     = DateTime.Now;
                            dataInfo.LogIp       = RequestHelper.GetIPAddress();
                            dataInfo.LogMac      = DawnXZ.PHYUtility.ManagementHelper.Instance().MacAddress.ToUpper();
                            dataInfo.LogComputer = "Unknown";
                            dataInfo.LogAttach   = null;
                            dataInfo.LogCount    = 1;
                            DawnAuthUserLoginBLL.Insert(dataInfo);

                            #endregion

                            ht["Msg"] = GeneralHandler.StateSuccess;
                            ht["Url"] = string.IsNullOrEmpty(returnUrl) ? GeneralHandler.SiteLoginedUrl : returnUrl;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outEx     = ex;
                ht["Msg"] = GeneralHandler.StateRefresh;
            }
            return(ht);
        }
Beispiel #11
0
        public JsonResult Logined(FormCollection form)
        {
            Hashtable ht = new Hashtable();

            ht.Add("Msg", GeneralHandler.FBaseInfo);
            ht.Add("Url", GeneralHandler.SiteLoginUrl);
            ht.Add("IsCode", false);
            try
            {
                string txtUname = form["txtUname"] as string;
                string txtUpwd  = form["txtUpwd"] as string;
                txtUpwd = CryptoHelper.MD5(txtUpwd, true);
                string txtCheckCode = form["txtCheckCode"] as string;
                txtCheckCode = txtCheckCode.ToLower();
                string strCheckCode = Session["CheckCode"] as string;
                strCheckCode = strCheckCode.ToLower();
                if (txtCheckCode.Length != 4 || !ValidHelper.EngIsEngAndNum(txtCheckCode) || txtCheckCode != strCheckCode)
                {
                    ht["Msg"]    = "您输入的验证码不正确[4个字符]。";
                    ht["IsCode"] = true;
                }
                else if (txtUname.Length < 4 || txtUname.Length > 16 || !ValidHelper.EngIsRegisters(txtUname))
                {
                    ht["Msg"] = "您输入的用户名不正确[4-16个字符]。";
                }
                else if (ValidHelper.IsSqlFilter(txtUname))
                {
                    ht["Msg"] = "您输入的用户名不正确[4-16个字符]。IsSqlFilter";
                }
                else if (!DawnAuthUserBLL.ExistsOfName(txtUname))
                {
                    ht["Msg"] = "您输入的用户名不存在!";
                }
                else
                {
                    var userIList = DawnAuthUserBLL.ISelect(string.Format("[user_name]='{0}' and [user_pwd]='{1}'", txtUname, txtUpwd));
                    if (userIList.Count == 0)
                    {
                        ht["Msg"] = "您输入的用户名与密码不匹配!";
                    }
                    else if (userIList.Count > 1)
                    {
                        ht["Msg"] = "您的账号存在异常,请联系管理员!";
                    }
                    else
                    {
                        var userInfo = userIList.First();
                        if (userInfo.UserStatus == 0)
                        {
                            ht["Msg"] = "您的账号存已禁用,请联系管理员!";
                        }
                        else if (userInfo.UserGrade < 2)
                        {
                            ht["Msg"] = "对不起,您的管理级别不符合!";
                        }
                        else
                        {
                            userIList.Clear();
                            Session["LoginName"] = txtUname;
                            Session[txtUname]    = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userInfo), GeneralHandler.TokenKey);
                            var userAuth = DawnAuthUserBLL.GetUserAuthority(userInfo.UserId);
                            Session["LoginAuthority"] = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userAuth), GeneralHandler.TokenKey);
                            var userStat = DawnAuthUserBLL.GetUserStatus(userInfo.UserId);
                            Session["LoginStatus"] = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userStat), GeneralHandler.TokenKey);
                            var userExtent = DawnAuthUserExtentBLL.ISelect(string.Format("user_id='{0}'", userInfo.UserId));
                            Session["LoginExtent"] = CryptoHelper.Encrypt(JsonConvert.SerializeObject(userExtent), GeneralHandler.TokenKey);
                            FormsAuthentication.SetAuthCookie(CryptoHelper.Encrypt(txtUname, GeneralHandler.TokenKey), false);

                            #region 登录日志

                            DawnAuthUserLoginMDL dataInfo = new DawnAuthUserLoginMDL();
                            dataInfo.UserId      = userInfo.UserId;
                            dataInfo.LogTime     = DateTime.Now;
                            dataInfo.LogIp       = RequestHelper.GetIPAddress();
                            dataInfo.LogMac      = "Unknown";
                            dataInfo.LogComputer = "Unknown";
                            dataInfo.LogAttach   = null;
                            dataInfo.LogCount    = 1;
                            DawnAuthUserLoginBLL.Insert(dataInfo);

                            #endregion

                            ht["Msg"] = GeneralHandler.StateSuccess;
                            ht["Url"] = GeneralHandler.SiteLoginedUrl;
                            //var hidReturnUrl = form["hidReturnUrl"] as string;
                            //ht["Url"] = string.IsNullOrEmpty(hidReturnUrl) ? GeneralHandler.SiteLoginedUrl : hidReturnUrl;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //ht["Msg"] = GeneralHandler.StateRefresh;
                ht["Msg"] = "对不起!无法与数据库建立连接!请联系管理员!";
                GeneralHandler.InsertByError(ex);
            }
            return(Json(ht));
        }
Beispiel #12
0
        /// <summary>
        /// 管理员个人详细信息
        /// </summary>
        /// <returns>执行结果</returns>
        public ActionResult MyProfile()
        {
            var dataInfo = DawnAuthUserBLL.Select(DawnauthHandler.UserId);

            return(View(dataInfo));
        }