Example #1
0
        /// <summary>
        /// 用户登录实现
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <SysAdmin> > LoginAsync(SysAdminLogin parm)
        {
            var res = new ApiResult <SysAdmin>();

            try
            {
                parm.password = DES3Encrypt.EncryptString(parm.password);
                var model = Db.Queryable <SysAdmin>()
                            .Where(m => m.LoginName == parm.loginname).First();
                if (model != null)
                {
                    if (model.LoginPwd.Equals(parm.password))
                    {
                        //修改登录时间
                        model.LoginDate   = DateTime.Now;
                        model.UpLoginDate = model.LoginDate;
                        SysAdminDb.Update(model);

                        #region 保存操作日志
                        var logModel = new SysLog()
                        {
                            Guid        = Guid.NewGuid().ToString(),
                            LoginName   = model.LoginName,
                            DepartName  = model.DepartmentName,
                            OptionTable = "SysAdmin",
                            Summary     = "登录操作",
                            IP          = Utils.GetIp(),
                            LogType     = (int)LogEnum.Login,
                            Urls        = Utils.GetUrl(),
                            AddTime     = DateTime.Now
                        };
                        SysLogDb.Insert(logModel);
                        #endregion

                        res.success = true;
                        res.message = "获取成功!";
                        res.data    = model;
                    }
                    else
                    {
                        res.success    = false;
                        res.statusCode = (int)ApiEnum.Error;
                        res.message    = "密码错误~";
                    }
                }
                else
                {
                    res.success    = false;
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = "账号错误~";
                }
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
            }
            return(await Task.Run(() => res));
        }
Example #2
0
        /// <summary>
        /// 用户登录实现
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <SysAdminMenuDto> > LoginAsync(SysAdminLogin parm)
        {
            var res = new ApiResult <SysAdminMenuDto>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                var adminModel = new SysAdminMenuDto();
                parm.password = DES3Encrypt.EncryptString(parm.password);
                var model = await Db.Queryable <SysAdmin>()
                            .Where(m => m.LoginName == parm.loginname).FirstAsync();

                if (model == null)
                {
                    res.message = "账号错误";
                    return(res);
                }
                if (!model.LoginPwd.Equals(parm.password))
                {
                    res.message = "密码错误~";
                    return(res);
                }
                if (!model.Status)
                {
                    res.message = "登录账号被冻结,请联系管理员~";
                    return(res);
                }
                adminModel.menu = GetMenuByAdmin(model.Guid);
                if (adminModel == null)
                {
                    res.message = "当前账号没有授权功能模块,无法登录~";
                    return(res);
                }
                //修改登录时间
                model.LoginDate   = DateTime.Now;
                model.UpLoginDate = model.LoginDate;
                model.LoginSum    = model.LoginSum + 1;
                SysAdminDb.Update(model);



                res.statusCode   = (int)ApiEnum.Status;
                adminModel.admin = model;
                res.data         = adminModel;
            }
            catch (Exception ex)
            {
                res.message = ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(res);
        }
Example #3
0
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyAsync(SysAdmin parm)
        {
            if (!string.IsNullOrEmpty(parm.DepartmentGuid))
            {
                // 说明有父级  根据父级,查询对应的模型
                var model = SysOrganizeDb.GetById(parm.DepartmentGuid);
                parm.DepartmentGuidList = model.ParentGuidList;
            }
            var res = new ApiResult <string>
            {
                statusCode = 200,
                data       = SysAdminDb.Update(parm) ? "1" : "0"
            };

            return(await Task.Run(() => res));
        }
Example #4
0
        /// <summary>
        /// 用户登录实现
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <SysAdminMenuDto> > LoginAsync(SysAdminLogin parm)
        {
            var res = new ApiResult <SysAdminMenuDto>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                var adminModel = new SysAdminMenuDto();
                parm.password = DES3Encrypt.EncryptString(parm.password);
                var model = await Db.Queryable <SysAdmin>().Where(m => m.LoginName == parm.loginname).FirstAsync();

                if (model == null)
                {
                    res.message = "账号错误";
                    return(res);
                }
                if (!model.LoginPwd.Equals(parm.password))
                {
                    res.message = "密码错误~";
                    return(res);
                }
                if (!model.Status)
                {
                    res.message = "登录账号被冻结,请联系管理员~";
                    return(res);
                }
                var(isSystem, isAgent, isSubAdmin) = await roleService.GetRoleByAdminGuid(model.Guid);

                if (isSystem)
                {
                }
                else if (isAgent)
                {
                    var exist = await Db.Queryable <CmsAgent>().AnyAsync(p => p.Admin_Guid == model.Guid && p.Status);

                    if (!exist)
                    {
                        res.message = "代理商已经被冻结,请联系管理员";
                        return(res);
                    }
                }
                else if (isSubAdmin)
                {
                    var exist = await Db.Queryable <CmsMerchant>().AnyAsync(p => p.admin_guid == model.Guid && p.status);

                    if (!exist)
                    {
                        res.message = "商户已经被冻结,请联系管理员";
                        return(res);
                    }
                }
                else
                {
                    var exist = await Db.Queryable <CmsMerchant>().AnyAsync(p => p.admin_guid == model.CreateBy && p.status);

                    if (!exist)
                    {
                        res.message = "商户已经被冻结,请联系管理员";
                        return(res);
                    }
                }

                adminModel.menu = GetMenuByAdmin(model.Guid);
                if (adminModel == null)
                {
                    res.message = "当前账号没有授权功能模块,无法登录~";
                    return(res);
                }

                //修改登录时间
                model.LoginDate   = DateTime.Now;
                model.UpLoginDate = model.LoginDate;
                model.LoginSum    = model.LoginSum + 1;
                SysAdminDb.Update(model);

                var roleList = await Db.Queryable <SysRole>().Where(m => m.IsSystem).Select(m => m.Guid).ToListAsync();

                model.IsSystem = roleList.Intersect(model.RoleList.Select(p => p.guid)).Any();

                res.statusCode   = (int)ApiEnum.Status;
                adminModel.admin = model;
                res.data         = adminModel;
            }
            catch (Exception ex)
            {
                res.message = ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(res);
        }