Beispiel #1
0
        /// <summary>
        /// 验证验证码的正确性
        /// </summary>
        /// <param name="tel">账号</param>
        /// <param name="code">待验证的code</param>
        /// <param name="key">秘钥(用于加解密)</param>
        /// <returns></returns>
        public async Task <bool> VerifyCode(string tel, string code, string key)
        {
            var staffId = GetSTaffInfoByTel(tel).Id;

            using (IAuthCodeService authCodeService = new AuthCodeService())
            {
                var authCode = await authCodeService.GetAllOrder(false).FirstOrDefaultAsync();

                if (StringEncryptAndDecrypt.AESEncrypt(code, key) == authCode.Code)
                {
                    if (DateTime.Now.AddMinutes(-3) <= authCode.CreatTime)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 增加多个职员
        /// </summary>
        /// <param name="staffInfos">职员信息</param>
        /// <param name="operatorId">操作员id</param>
        /// <param name="key">秘钥</param>
        /// <param name="originalRoleName">角色名</param>
        /// <returns></returns>
        public async Task AddGroupStaff(List <StaffBsicInfoDto> staffInfos, Guid operatorId, string key, string originalRoleName)
        {
            List <Guid> modifyIds = new List <Guid>();

            using (IStaffInfoService staffInfoService = new StaffInfoService())
            {
                foreach (var staffInfo in staffInfos)
                {
                    var staff = new Model.StaffInfo()
                    {
                        Name      = staffInfo.Name,
                        Tel       = staffInfo.Tel,
                        Password  = StringEncryptAndDecrypt.AESEncrypt(staffInfo.Tel, key),
                        Email     = staffInfo.Email,
                        Address   = staffInfo.Address,
                        IdCard    = staffInfo.IdCard,
                        ImagePath = staffInfo.ImagePath,
                        SectionId = staffInfo.SectionId,
                        Position  = staffInfo.Position
                    };
                    await staffInfoService.CreateAsync(staff, false);

                    modifyIds.Add(staff.Id);
                }
                await staffInfoService.Save();
            }

            using (IAccountOperateLogService accountOperateLogService = new AccountOperateLogService())
            {
                using (IStaffPowerInfoService staffPowerInfoService = new StaffPowerInfoService())
                {
                    using (IRoleInfoService roleInfoService = new RoleInfoService())
                    {
                        foreach (var modifyId in modifyIds)
                        {
                            await accountOperateLogService.CreateAsync(new Model.AccountOperateLog()
                            {
                                OperatorId  = operatorId,
                                ModifiedId  = modifyId,
                                OPerateType = ('1').ToString()
                            }, false);

                            //初始权限
                            await staffPowerInfoService.CreateAsync(new Model.StaffPowerInfo()
                            {
                                StaffId = modifyId,
                                RoleId  = (await roleInfoService.GetAll().Where(p => p.Name == originalRoleName).FirstAsync()).Id //得到对应权限的Id
                            }, false);
                        }

                        //一起更新
                        await accountOperateLogService.Save();

                        await staffPowerInfoService.Save();
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="tel">账号(电话)</param>
        /// <param name="password">新密码</param>
        /// <param name="key">秘钥(用于加解密)</param>
        /// <returns></returns>
        public async Task ChangePwd(string tel, string password, string key)
        {
            using (IStaffInfoService staffInfoService = new StaffInfoService())
            {
                var staff = await staffInfoService.GetAll().Where(p => p.Tel == tel).FirstAsync();

                staff.Password = StringEncryptAndDecrypt.AESEncrypt(password, key);
                await staffInfoService.EditAsync(staff);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 增加一个职员
        /// </summary>
        /// <param name="staffInfo">职员信息</param>
        /// <param name="operatorId">操作员id</param>
        /// <param name="key">秘钥</param>
        /// <param name="originalRoleName">角色名</param>
        /// <returns></returns>
        public async Task AddOneStaff(StaffBsicInfoDto staffInfo, Guid operatorId, string key, string originalRoleName)
        {
            using (IStaffInfoService staffInfoService = new StaffInfoService())
            {
                var staff = new Model.StaffInfo()
                {
                    Name      = staffInfo.Name,
                    Tel       = staffInfo.Tel,
                    Password  = StringEncryptAndDecrypt.AESEncrypt(staffInfo.Tel, key),
                    Email     = staffInfo.Email,
                    Address   = staffInfo.Address,
                    IdCard    = staffInfo.IdCard,
                    ImagePath = staffInfo.ImagePath,
                    SectionId = staffInfo.SectionId,
                    Position  = staffInfo.Position
                };
                await staffInfoService.CreateAsync(staff);

                using (IAccountOperateLogService accountOperateLogService = new AccountOperateLogService())
                {
                    await accountOperateLogService.CreateAsync(new Model.AccountOperateLog()
                    {
                        OperatorId  = operatorId,
                        ModifiedId  = staff.Id,
                        OPerateType = "1"
                    });
                }

                //初始权限
                using (IStaffPowerInfoService staffPowerInfoService = new StaffPowerInfoService())
                {
                    using (IRoleInfoService roleInfoService = new RoleInfoService())
                    {
                        await staffPowerInfoService.CreateAsync(new Model.StaffPowerInfo()
                        {
                            StaffId = staff.Id,
                            RoleId  = (await roleInfoService.GetAll().Where(p => p.Name == "一级权限").FirstAsync()).Id
                        });
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 职员登陆
        /// </summary>
        /// <param name="account">账号(电话)</param>
        /// <param name="password">密码</param>
        /// <param name="key">秘钥(用于加解密)</param>
        /// <param name="userId">职员id(用于返回)</param>
        /// <returns></returns>
        public bool Login(string account, string password, string key, out Guid userId)
        {
            var pwd = StringEncryptAndDecrypt.AESEncrypt(password, key);

            using (IStaffInfoService staffInfoService = new StaffInfoService())
            {
                var user = staffInfoService.GetAll().FirstOrDefaultAsync(p => p.Tel == account && p.Password == pwd); //user在此是一个异步方法
                user.Wait();                                                                                          //等待user执行结束
                var data = user.Result;                                                                               //拿到user执行的结果
                if (data != null)
                {
                    userId = data.Id;
                    return(true);
                }
                else
                {
                    userId = new Guid();
                    return(false);
                }
            }
        }
Beispiel #6
0
        public ActionResult SendAuthCode(string tel)
        {
            IStaffManager staffManager = new StaffManager();
            var           staff        = staffManager.GetSTaffInfoByTel(tel);
            var           code         = StringEncryptAndDecrypt.GenerateAESKey(5);

            try
            {
                string key = ConfigurationManager.AppSettings["EncryptAndDecryptPwdString"];
                staffManager.CreateAuthCode(staff.Id, StringEncryptAndDecrypt.AESEncrypt(code, key));
                if (SendEmail.Send(code, tel, staff.Email))
                {
                    return(Json(new { status = "ok" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { status = "false" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new { status = "false" }, JsonRequestBehavior.AllowGet));
            }
        }