コード例 #1
0
 public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         //假如手机号已被注册,就返回-1
         if (commonService.GetAll().Any(a => a.PhoneNum == phoneNum))
         {
             return(-1);
         }
         //密码盐 可以用生成验证码的那个随机算一个出来
         string          pwdSalt      = CommonHelper.GenerateCaptchaCode(5);
         AdminUserEntity newAdminUser = new AdminUserEntity()
         {
             Name         = name,
             PhoneNum     = phoneNum,
             CityId       = cityId,
             PasswordSalt = pwdSalt,
             PasswordHash = CommonHelper.CalcMd5(password + pwdSalt),
             Email        = email,
         };
         ctx.AdminUsers.Add(newAdminUser);
         ctx.SaveChanges();
         return(newAdminUser.Id);
     }
 }
コード例 #2
0
ファイル: AdminUserService.cs プロジェクト: NextLoad/ZSZ
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity adminUser = new AdminUserEntity();

            adminUser.Name     = name;
            adminUser.PhoneNum = phoneNum;
            string salt = Web.Common.WebCommonHelper.CreateVerifyCode(5);

            adminUser.PasswordSalt = salt;
            adminUser.CityId       = cityId;
            adminUser.EMail        = email;
            adminUser.PasswordHash = Common.CommonHelper.CalcMD5(salt + password);
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(ctx);
                bool exists = cs.GetAll().Any(u => u.PhoneNum == phoneNum);
                if (exists)
                {
                    throw new ArgumentException("手机号已存在" + phoneNum);
                }
                ctx.AdminUsers.Add(adminUser);
                ctx.SaveChanges();
                return(adminUser.Id);
            }
        }
コード例 #3
0
        public BaseResponse InsertOrUpdateAdminUser(AdminUserEntity entity, string type)
        {
            var res = false;

            if (type == "insert")
            {
                var userEntity = adminUser.QueryAdminUserOne(new AdminUserRequest {
                    UserName = entity.UserName
                });
                if (userEntity != null)
                {
                    return(new BaseResponse {
                        IsSuccess = false, Msg = $"{entity.UserName}已经添加,请使用原账号"
                    });
                }
                res = adminUser.InsertAdminUser(entity);
            }
            else
            {
                res = adminUser.UpdateAdminUser(entity);
            }
            NLogHelper.Default.Info($"InsertAdminUser=>{type}用户结果:{res}");
            return(new BaseResponse
            {
                IsSuccess = res,
                Msg = res ? "成功" : "操作失败"
            });
        }
コード例 #4
0
 public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> serives = new BaseService <AdminUserEntity>(db);
         bool exists = serives.GetAll().Any(e => e.PhoneNum == phoneNum);
         if (exists)
         {
             throw new ArgumentException("账号已存在");
         }
         else
         {
             string          salt  = CommonHelper.CreateVerifyCode(4);
             string          pwd   = CommonHelper.CalcMD5(password + salt);
             AdminUserEntity admin = new AdminUserEntity()
             {
                 CityId          = cityId,
                 Email           = email,
                 Name            = name,
                 PhoneNum        = phoneNum,
                 LoginErrorTimes = 0,
                 PasswordSalt    = salt,
                 PasswordHash    = pwd
             };
             db.AdminUsers.Add(admin);
             db.SaveChanges();
             return(admin.Id);
         }
     }
 }
コード例 #5
0
        public ActionResult Login(string Name, string Pw)
        {
            HandleResult hr = new HandleResult();

            if (string.IsNullOrEmpty(Name) || Commons.IsIncludeSqlInjection(Name))
            {
                hr.StatsCode = 103;
                hr.Message   = "姓名不合法";
                return(Content(JsonConvert.SerializeObject(hr)));
            }

            if (string.IsNullOrEmpty(Pw) || Commons.IsIncludeSqlInjection(Pw))
            {
                hr.StatsCode = 104;
                hr.Message   = "密码不合法";
                return(Content(JsonConvert.SerializeObject(hr)));
            }

            AdminUserEntity model = AdminUserBLL.GetLoginByName(Name);

            if (model != null)
            {
                if (model.PassWord == Commons.GetMD5Hash(Pw))
                {
                    Authentication.SetAuthCookie(model.Id, HttpUtility.UrlEncode(model.UserName, Encoding.GetEncoding("UTF-8")));
                    hr.StatsCode = 200;
                    hr.Message   = "登陆成功";
                    return(Content(JsonConvert.SerializeObject(hr)));
                }
                hr.Message = "用户不存在或密码错误";
                return(Content(JsonConvert.SerializeObject(hr)));
            }
            hr.Message = "用户不存在或密码错误";
            return(Content(JsonConvert.SerializeObject(hr)));
        }
コード例 #6
0
        public AdminUserDTO DTO(AdminUserEntity entity)
        {
            string cityName;

            if (entity.City != null)
            {
                cityName = entity.City.Name;
            }
            else
            {
                cityName = "总部";
            }
            AdminUserDTO admin = new AdminUserDTO()
            {
                CityId             = entity.CityId,
                CityName           = cityName,
                Name               = entity.Name,
                CreateDateTime     = entity.CreateDateTime,
                Email              = entity.Email,
                PhoneNum           = entity.PhoneNum,
                Id                 = entity.Id,
                LoginErrorTimes    = entity.LoginErrorTimes,
                LastLoginErrorTime = entity.LastLoginErrorDateTime
            };

            return(admin);
        }
コード例 #7
0
        /// <summary>
        /// 添加一个后台用户
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phoneNum"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="cityId"></param>
        /// <returns></returns>
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.CityId   = cityId;
            user.Email    = email;
            user.Name     = name;
            user.PhoneNum = phoneNum;
            string salt = CommonHelper.CreateVerifyCode(5);//盐

            user.PasswordSalt = salt;
            //Md5(盐+用户密码)
            string pwdHash = CommonHelper.CalcMD5(salt + password);

            user.PasswordHash = pwdHash;
            using (PalmRentDbContext ctx = new PalmRentDbContext())
            {
                BaseService <AdminUserEntity> bs
                    = new BaseService <AdminUserEntity>(ctx);
                bool exists = bs.GetAll().Any(u => u.PhoneNum == phoneNum);
                if (exists)
                {
                    throw new ArgumentException("手机号已经存在" + phoneNum);
                }
                ctx.AdminUsers.Add(user);
                ctx.SaveChanges();
                return(user.Id);
            }
        }
コード例 #8
0
        public long AddNew(AdminUserAddDto model)
        {
            AdminUserEntity adminUser = model.EntityMap();

            string pwdHash = "123456".CalcMd5();

            adminUser.PasswordHash   = pwdHash;
            adminUser.CreateDateTime = DateTime.Now;

            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <AdminUserEntity> bs
                    = new BaseService <AdminUserEntity>(ctx);
                ctx.AdminUsers.Add(adminUser);

                bool exists = bs.GetAll().Any(u => u.LoginName == model.LoginName);

                if (exists)
                {
                    throw new ArgumentException("登录名已经存在" + model.LoginName);
                }

                ctx.AdminUsers.Add(adminUser);
                ctx.SaveChanges();
                return(adminUser.Id);
            }
        }
コード例 #9
0
        public async Task UpdateAsync(UpdateAdminUserDTO dto)
        {
            using (AdminUserContext ctx = new AdminUserContext())
            {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
                var phoneAdminUser = await bs.GetAll().SingleOrDefaultAsync(e => e.PhoneNum == dto.PhoneNum);

                if (phoneAdminUser != null)
                {
                    if (phoneAdminUser.Id != dto.Id)
                    {
                        throw new Exception("电话号码已存在");
                    }
                }

                AdminUserEntity entity = await bs.GetAll().SingleOrDefaultAsync(e => e.Id == dto.Id);

                if (entity == null)
                {
                    throw new ArgumentException($"管理员{dto.Id}不存在");
                }
                entity.Age      = dto.Age;
                entity.Gender   = dto.Gender;
                entity.Name     = dto.Name;
                entity.PhoneNum = dto.PhoneNum;
                await ctx.SaveChangesAsync();
            }
        }
コード例 #10
0
        public async Task <long> AddNewAsync(AddAdminUserDTO dto)
        {
            AdminUserEntity entity = new AdminUserEntity();

            entity.Age          = dto.Age;
            entity.Gender       = dto.Gender;
            entity.Name         = dto.Name;
            entity.PhoneNum     = dto.PhoneNum;
            entity.Salt         = MD5Helper.GetSalt(10);
            entity.PasswordHash = MD5Helper.CalcMD5(dto.Password + entity.Salt);
            using (AdminUserContext ctx = new AdminUserContext())
            {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
                var phoneAdminUser = await bs.GetAll().SingleOrDefaultAsync(e => e.PhoneNum == dto.PhoneNum);

                if (phoneAdminUser != null)
                {
                    throw new Exception("电弧号码已存在");
                }
                await ctx.AdminUsers.AddAsync(entity);

                await ctx.SaveChangesAsync();

                return(entity.Id);
            }
        }
コード例 #11
0
ファイル: AdminUserService.cs プロジェクト: NextLoad/ZSZ
        public bool HasPermission(long adminUserId, string permissionName)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(ctx);
                AdminUserEntity user = cs.GetById(adminUserId);
                if (user == null)
                {
                    throw new ArgumentException("用户不存在" + adminUserId);
                }

                return(user.RoleEntities.SelectMany(r => r.PermissionEntities).Any(p => p.Name == permissionName));

                //foreach (RoleEntity role in user.RoleEntities)
                //{
                //    foreach (PermissionEntity permission in role.PermissionEntities)
                //    {
                //        if (permission.Name == permissionName)
                //        {
                //            return true;
                //        }
                //    }
                //}

                //return false;
            }
        }
コード例 #12
0
ファイル: AdminUserService.cs プロジェクト: zxswola/ZH
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            using (MyDbContext ctx = new MyDbContext())
            {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
                bool exists = bs.GetAll().Any(a => a.PhoneNum == phoneNum);
                if (exists)
                {
                    throw new ArgumentException("此电话已经注册" + phoneNum);
                }

                string          passwordSalt = CommonHelper.CreateVerifyCode(5);
                string          passwordHash = CommonHelper.CalcMD5(passwordSalt + password);
                AdminUserEntity user         = new AdminUserEntity
                {
                    Name         = name,
                    PhoneNum     = phoneNum,
                    PasswordSalt = passwordSalt,
                    PasswordHash = passwordHash,
                    Email        = email,
                    CityId       = cityId
                };
                ctx.AdminUsers.Add(user);
                ctx.SaveChanges();
                return(user.Id);
            }
        }
コード例 #13
0
        public ServiceResult <int> Upsert(AdminUserEntity model)
        {
            var response = ServiceResult <int> .Instance.ErrorResult(ServiceResultCode.Error);

            var otherNo = Repository.FindBy(x => x.Id != model.Id && x.Email == model.Email).Select(x => x.Id).FirstOrDefault();

            if (otherNo > 0)
            {
                return(response.ErrorResult(ServiceResultCodeAdmin.DuplicateEmail));
            }

            if (model.Id == 0)
            {
                var responseAdd = Add(model);
                if (!responseAdd.Success)
                {
                    return(response.ErrorResult(responseAdd.Code));
                }
                model = responseAdd.Value;
            }
            else
            {
                response = Edit(model);
            }

            return(response.SuccessResult(model.Id));
        }
コード例 #14
0
        /// <summary>
        /// 保存管理员
        /// </summary>
        /// <param name="model">信息体</param>
        /// <returns></returns>
        public bool SubmitAdminUser(AdminUserEntity model)
        {
            //保存失败
            if (model == null)
            {
                return(false);
            }
            if (!string.IsNullOrEmpty(model.RoleSid))
            {
                RoleEntity roleEntity = _roleService.GetSingle(model.RoleSid);
                model.RoleName = roleEntity == null ? string.Empty : roleEntity.FullName;
            }
            if (string.IsNullOrEmpty(model.Sid))
            {
                model.PassWord = ApiHelper.MD5Encrypt(model.PassWord, "MD5");
            }

            if (!string.IsNullOrEmpty(model.Sid) && model.Sid.Length > 32)
            {
                AdminUserEntity adminEntity = _service.GetSingle(model.Sid);
                if (adminEntity != null)
                {
                    model.CreateDate = adminEntity.CreateDate;
                    model.EditDate   = DateTime.Now;
                    model.IsDelete   = adminEntity.IsDelete;
                    model.Sid        = adminEntity.Sid;
                }
            }
            _service.SaveFrom(model);
            return(true);
        }
コード例 #15
0
ファイル: UpdateEvent.cs プロジェクト: war-man/ddd
 public UpdateEvent(long id, AdminUserEntity user)
 {
     Id            = id;
     User          = user;
     AggregateId   = id;
     AggregateType = nameof(AdminUserEntity);
 }
コード例 #16
0
ファイル: AdminUserService.cs プロジェクト: 080779/Activity
        public long AddAdminUser(string name, string mobile, bool gender, string email, string password)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.Name   = name;
            user.Mobile = mobile;
            user.Gender = gender;
            string salt = CommonHelper.GetCaptcha(5);

            user.PasswordSalt    = salt;
            user.PasswordHash    = CommonHelper.GetMD5(salt + password);
            user.LoginErrorTimes = 0;
            user.Email           = email;
            using (MyDbContext dbc = new MyDbContext())
            {
                CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(dbc);
                bool exists = cs.GetAll().Any(a => a.Mobile == mobile);
                if (exists)
                {
                    return(-1);
                }
                else
                {
                    dbc.AdminUsers.Add(user);
                    dbc.SaveChanges();
                    return(user.Id);
                }
            }
        }
コード例 #17
0
ファイル: AdminUserService.cs プロジェクト: 080779/AMS
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.Name            = name;
            user.PhoneNum        = phoneNum;
            user.PasswordHash    = password;
            user.PasswordSalt    = password;
            user.LoginErrorTimes = 0;
            //user.LastLoginErrorTime = DateTime.Now;
            user.Email  = email;
            user.CityId = cityId;
            using (MyDbContext dbc = new MyDbContext())
            {
                CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(dbc);
                bool exists = cs.GetAll().Any(a => a.PhoneNum == phoneNum);
                if (exists)
                {
                    throw new ArgumentException("手机号:" + phoneNum + "已经存在");
                }
                else
                {
                    dbc.AdminUsers.Add(user);
                    dbc.SaveChanges();
                    return(user.Id);
                }
            }
        }
コード例 #18
0
        public int AddAdminUser(string name, string userName, string password, string email, string phoneNum)
        {
            using (var con = new OracleConnection(OracleHelper.connectionString))
            {
                con.Open();
                string sql   = "select userid from T_ADMINUSER where isDeleted=0 and username=:username";
                var    admin = con.Query(sql, new { username = userName });
                var    count = admin.Count();
                if (count > 0)
                {
                    throw new ArgumentException("此用户名已经注册" + userName);
                }

                string          passwordSalt = CommonHelper.CreateVerifyCode(5);
                string          passwordHash = CommonHelper.CalcMD5(passwordSalt + password);
                AdminUserEntity user         = new AdminUserEntity
                {
                    Name         = name,
                    UserName     = userName,
                    PasswordSalt = passwordSalt,
                    PasswordHash = passwordHash,
                    Email        = email,
                    PhoneNumber  = phoneNum
                };
                string sqlInsert =
                    @"insert into T_ADMINUSER(name,username,Passwordsalt,passwordhash,email,phonenumber,loginerrortimes,lastloginerrordatetime,isdeleted,createdatetime)
                    values(:name, :username, :Passwordsalt, :passwordhash, :email, :phonenumber,:loginerrortimes, :lastloginerrordatetime, :isdeleted, :createdatetime)";
                con.Execute(sqlInsert, user);
                return(con.ExecuteScalar <int>(sql, new { username = userName }));
            }
        }
コード例 #19
0
        public async Task <Response> HandleAsync(LoginRequest request)
        {
            if (!string.IsNullOrEmpty(request.UserName) && !string.IsNullOrEmpty(request.Password))
            {
                AdminUserEntity userEntity = await _userRepository.GetUserAsync(request.UserName, request.Password);

                if (userEntity != null)
                {
                    TokenInfo refreshToken = await _tokenFactory.GenerateRefreshToken(TokenConfiguration.RefreshTokenSize, TokenConfiguration.RefreshTokenExpiration);

                    userEntity.AddRefreshToken(refreshToken.Token, refreshToken.ExpiresIn);
                    await _userRepository.UpdateUser(userEntity);

                    AccessTokenParameters accessTokenParameters = new AccessTokenParameters
                                                                  (
                        userEntity.UserGuid,
                        userEntity.UserName,
                        TokenConfiguration.AccessTokenExpiration,
                        TokenConfiguration.SecretKey
                                                                  );
                    TokenInfo accessToken = await _tokenFactory.GenerateAccessToken(accessTokenParameters);

                    return(new Response(accessToken.Token, refreshToken.Token));
                }
            }

            return(null);
        }
コード例 #20
0
        private AdminUserEntity BuildAdminUserEntity(ProfileEditViewModel model)
        {
            var entity = new AdminUserEntity();

            entity.InjectFrom(model);

            return(entity);
        }
コード例 #21
0
        public AppStateProvider(IAdminUserService adminUserService, AuthenticationStateProvider authenticationStateProvider)
        {
            var user = authenticationStateProvider.GetAuthenticationStateAsync().Result.User;

            if (user.Identity.IsAuthenticated && int.TryParse(user.Claims.FirstOrDefault(m => m.Type.ToString() == "UserGuid").Value, out int userGuid))
            {
                _adminUserEntity = adminUserService.GetAdminUser(userGuid);
            }
        }
コード例 #22
0
ファイル: AdminUserService.cs プロジェクト: NextLoad/ZSZ
 public AdminUserDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(ctx);
         //AdminUserEntity adminUser = cs.GetAll().Include(u => u.CityEntity).SingleOrDefault(u => u.Id == id);
         AdminUserEntity adminUser = cs.GetById(id);
         return(ToDTO(adminUser));
     }
 }
コード例 #23
0
        public ActionResult SubmitForm(AdminUserEntity adminEntity)
        {
            bool result = adminUserApp.SubmitAdminUser(adminEntity);

            if (result)
            {
                return(Success("保存成功。。。"));
            }
            return(Error("保存失败。。。"));
        }
コード例 #24
0
        public AdminUserDTO ToDTO(AdminUserEntity ef)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CreateDateTime         = ef.CreateDateTime;
            dto.Id                     = ef.Id;
            dto.LastLoginErrorDateTime = ef.LastLoginErrorDateTime;
            dto.LoginErrorTimes        = ef.LoginErrorTimes;
            dto.Name                   = ef.Name;
            return(dto);
        }
コード例 #25
0
ファイル: AdminUserService.cs プロジェクト: 080779/Activity
        public AdminUserDTO ToDTO(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CreateDateTime = user.CreateDateTime;
            dto.Email          = user.Email;
            dto.Id             = user.Id;
            dto.Name           = user.Name;
            dto.Gender         = user.Gender;
            dto.Mobile         = user.Mobile;
            return(dto);
        }
コード例 #26
0
        /// <summary>
        /// 重置管理员登录密码
        /// </summary>
        /// <param name="adminUserSid">管理员Sid</param>
        /// <param name="passWord">密码</param>
        /// <returns></returns>
        public bool SubmitAdminUserResetPassWord(string adminUserSid, string passWord)
        {
            passWord = ApiHelper.MD5Encrypt(passWord, "MD5");
            AdminUserEntity adminEntity = GetEntityBySid(adminUserSid);

            if (adminEntity == null)
            {
                return(false);
            }
            adminEntity.PassWord = passWord;
            _service.SaveFrom(adminEntity);
            return(true);
        }
コード例 #27
0
ファイル: AdminUserService.cs プロジェクト: NextLoad/ZSZ
 public AdminUserDTO GetByPhoneNum(string phoneNum)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(ctx);
         AdminUserEntity adminUser          = cs.GetAll().SingleOrDefault(a => a.PhoneNum == phoneNum);
         if (adminUser == null)
         {
             return(null);
         }
         return(ToDTO(adminUser));
     }
 }
コード例 #28
0
        private ListAdminUserDTO TODTO(AdminUserEntity entity)
        {
            ListAdminUserDTO dto = new ListAdminUserDTO();

            dto.Age            = entity.Age;
            dto.CreateTime     = entity.CreateTime;
            dto.Gender         = entity.Gender;
            dto.Id             = entity.Id;
            dto.LoginErrorTime = entity.LoginErrorTime;
            dto.Name           = entity.Name;
            dto.PhoneNum       = entity.PhoneNum;
            return(dto);
        }
コード例 #29
0
        //private static string connectionString = ConfigurationManager.ConnectionStrings["oracleConStr"].ConnectionString;
        //private OracleConnection con = DbFactory.GetConnection();
        AdminUserDTO ToDto(AdminUserEntity adminUser)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.UserName               = adminUser.UserName;
            dto.Id                     = adminUser.UserId;
            dto.CreateDateTime         = adminUser.CreateDateTIme;
            dto.PhoneNum               = adminUser.PhoneNumber;
            dto.Email                  = adminUser.Email;
            dto.LastLoginErrorDateTime = adminUser.LastLoginErrorDateTime;
            dto.Name                   = adminUser.Name;
            // dto.PhoneNum = adminUser.PhoneNum;
            return(dto);
        }
コード例 #30
0
 public AdminUserDTO GetByPhoneNum(string phoneNum)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         AdminUserEntity adminUser = commonService.GetAll().SingleOrDefault(a => a.PhoneNum == phoneNum);
         //如果手机号不存在就返回null,如果有不止一个号码就抛出异常
         if (adminUser == null)
         {
             return(null);
         }
         return(Entity2DTO(adminUser));
     }
 }