コード例 #1
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);
        }
コード例 #2
0
        public void UpdateUser()
        {
            Assert.True(currentUser.Id != Guid.Empty);
            Assert.True(currentUser.Registered != new DateTime());
            Assert.True(currentUser.ServiceUrl == string.Empty);

            var adminUserDTO = new AdminUserDTO(currentUser);

            Assert.True(adminUserDTO.Id == currentUser.Id);
            Assert.True(adminUserDTO.Registered == currentUser.Registered);
            Assert.True(adminUserDTO.ServiceUrl == currentUser.ServiceUrl);
            Assert.True(adminUserDTO.ServiceUrl == string.Empty);
            Assert.True(adminUserDTO.DatabaseSize == null);

            adminUserDTO.Email        = @"test@localhost";
            adminUserDTO.DatabasePath = @"d:\New Path here.sdf";
            adminUserDTO.IsDisabled   = true;
            adminUserDTO.Login        = @"new_login";
            adminUserDTO.Password     = @"newPa$$w0rd!";
            adminUserDTO.ServiceUrl   = @"\\some\service_here.svc";

            adminService.UpdateUser(adminUserDTO);
            var users = adminService.GetUsers(new QueryFilter());

            Assert.True(users[0].Id == adminUserDTO.Id);
            Assert.True(Math.Abs(users[0].Registered.Ticks - adminUserDTO.Registered.Ticks) < 100000);
            Assert.True(users[0].ServiceUrl == adminUserDTO.ServiceUrl);
            Assert.True(users[0].DatabasePath == adminUserDTO.DatabasePath);
            Assert.True(users[0].IsDisabled == adminUserDTO.IsDisabled);
            Assert.True(users[0].Login == adminUserDTO.Login);
            Assert.True(users[0].Password == null);
            Assert.True(users[0].ServiceUrl == adminUserDTO.ServiceUrl);
        }
コード例 #3
0
 public AdminBillDTO(BillModel bill) : base(bill)
 {
     Buyer           = new AdminUserDTO(bill.User);
     Offer           = new AdminOfferDTO(bill.Offer);
     PaymentMade     = bill.PaymentMade;
     PaymentCanceled = bill.PaymentCanceled;
 }
コード例 #4
0
        public int CreateAdmin(AdminUserDTO user)
        {
            using (officehoursEntities officeHoursDB = new officehoursEntities())
            {
                officehours_Admin_Users userData = new officehours_Admin_Users()
                {
                    Admin_User_Id = user.AdminUserId,
                    Date_Created  = DateTime.Now,
                    Password      = user.Password,
                    User_Name     = user.UserName
                };

                officeHoursDB.officehours_Admin_Users.Add(userData);
                try
                {
                    officeHoursDB.SaveChanges();
                    return(userData.Admin_User_Id);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(0);
                }
            }
        }
コード例 #5
0
        public HttpResponseMessage DeleteUser([FromBody] AdminUserDTO adminUserDTO)
        {
            var response = new HttpResponseMessage();

            if (adminUserDTO.jwt == null)
            {
                response.Content    = new StringContent("JWT is null.");
                response.StatusCode = HttpStatusCode.Conflict;
                return(response);
            }

            using (var db = new DataBaseContext())
            {
                try
                {
                    TokenManager tokenManager = new TokenManager(db);

                    //Validate Token
                    string newJWT = tokenManager.ValidateToken(adminUserDTO.jwt);
                    //if jwt not valid redirect to SSO login
                    if (newJWT == null)
                    {
                        response         = Request.CreateResponse(HttpStatusCode.Moved);
                        response.Content = new StringContent("https://kfc-sso.com/#/login");
                        return(response);
                    }

                    AuthorizationManager authManager = new AuthorizationManager(db);

                    //authorize action
                    if (!authManager.AuthorizeUserToUser(adminUserDTO.jwt, new Guid(adminUserDTO.userID), Actions.DELETEUSER))
                    {
                        response.Content    = new StringContent("Unauthorized to add user.");
                        response.StatusCode = HttpStatusCode.Unauthorized;
                        return(response);
                    }

                    //delete user from db
                    UserManager userManager = new UserManager(db);
                    userManager.DeleteUser(new Guid(adminUserDTO.userID));

                    //return response
                    response.Content    = new StringContent(newJWT);
                    response.StatusCode = HttpStatusCode.OK;
                    return(response);
                }
                catch (UserDoesNotExistException e)
                {
                    response.Content    = new StringContent(e.Message);
                    response.StatusCode = HttpStatusCode.OK;
                    return(response);
                }
                catch (Exception e)
                {
                    response.Content    = new StringContent(e.Message);
                    response.StatusCode = HttpStatusCode.Conflict;
                    return(response);
                }
            }
        }
コード例 #6
0
 public ActionResult CheckPhoneExist(string phone, long?adminID)
 {
     if (!string.IsNullOrEmpty(phone))
     {
         AdminUserDTO userModel = AdminUserService.IsExitTelePhone(phone);
         bool         isOK      = false;
         //如果没有给adminID,则说明是“插入”,只要检查是不是存在这个手机号
         if (adminID == null)
         {
             isOK = (userModel == null);
         }
         else//如果有userId,则说明是修改,则要把自己排除在外
         {
             isOK = (userModel == null || userModel.Id == adminID);
         }
         return(Json(new AjaxResult {
             Status = isOK ? "ok" : "exists"
         }));
     }
     else
     {
         return(Json(new AjaxResult()
         {
             Status = "no"
         }));
     }
 }
コード例 #7
0
        public List <AdminUserDTO> GetAllAdminUsers()
        {
            List <AdminUserDTO> adminUsers = new List <AdminUserDTO>();

            using (officehoursEntities officeHoursDB = new officehoursEntities())
            {
                var adminUserData = from f in officeHoursDB.officehours_Admin_Users
                                    select f;

                foreach (officehours_Admin_Users usr in adminUserData)
                {
                    if (usr != null)
                    {
                        AdminUserDTO faculty = new AdminUserDTO()
                        {
                            AdminUserId = usr.Admin_User_Id,
                            UserName    = usr.User_Name,
                            Password    = usr.Password,
                            DateCreated = (DateTime)usr.Date_Created
                        };

                        adminUsers.Add(faculty);
                    }
                }
                return(adminUsers);
            }
        }
コード例 #8
0
        public IEnumerable <AdminUserDTO> GetAllAdmin()
        {
            return(GetDummyDB().Select(user =>
            {
                ////user.AccessType = EAccessType.Admin;
                ////user.Address.Access = EAccessType.Admin;
                //PublicUserDTO userDTO = new PublicUserDTO();
                //userDTO.Id = user.Id;
                //userDTO.Name = user.Name;

                AdminUserDTO adminUser = new AdminUserDTO()
                {
                    Id = user.Id,
                    Name = user.Name,
                    Email = user.Email,
                    DateOfBirth = user.DateOfBirth,
                    Address = new PrivateAddressDTO()
                    {
                        Id = user.Address.Id,
                        Street = user.Address.Street,
                        City = user.Address.City,
                        Country = user.Address.Country
                    }
                };

                return adminUser;
            }));
        }
コード例 #9
0
 public ActionResult AddAdmin(AddAdminModel model)
 {
     if (ModelState.IsValid)
     {
         //1服务端也也要校验手机是否被真正的注册过
         AdminUserDTO userModel = AdminUserService.IsExitTelePhone(model.PhoneNum);
         if (userModel == null)
         {
             long adminUserID = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.Pwd);
             RoleService.AddRoleIds(adminUserID, model.RoleIds);//添加用户角色的对应关系,此处应该启用事物
             return(Json(new AjaxResult()
             {
                 Status = "ok"
             }));
         }
         else
         {
             return(Json(new AjaxResult()
             {
                 Status = "exists"
             }));
         }
     }
     else
     {
         string errorMsg = CommonHelper.GetValidMsg(ModelState);//验证出错时候具体的错误信息
         return(Json(new AjaxResult()
         {
             Status = "no", ErrorMsg = errorMsg
         }));
     }
 }
コード例 #10
0
        private AdminUserDTO ToDTO(AdminUserEntity user)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                AdminUserDTO dto = new AdminUserDTO();
                dto.CityId = user.CityId;
                if (user.City != null)
                {
                    dto.CityName = user.City.Name;//需要Include提升性能
                }
                else
                {
                    dto.CityName = "总部";
                }

                dto.CreateDateTime         = user.CreateDateTime;
                dto.Email                  = user.Email;
                dto.Id                     = user.Id;
                dto.LastLoginErrorDateTime = user.LastLoginErrorDateTime;
                dto.LoginErrorTimes        = user.LoginErrorTimes;
                dto.Name                   = user.Name;
                dto.PhoneNum               = user.PhoneNum;
                return(dto);
            }
        }
コード例 #11
0
        private AdminUserDTO ToDto(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.RoleId = user.Roles.Select(u => u.Id).ToArray();
            dto.CityId = user.CityId;
            if (user.City != null)
            {
                dto.CityName = user.City.Name;//需要Include提升性能
                //总部(北京)、上海分公司、广州分公司、北京分公司
            }
            else
            {
                dto.CityName = "总部";
            }

            dto.CreateDateTime         = user.CreateDateTime;
            dto.Email                  = user.Email;
            dto.Id                     = user.Id;
            dto.LastLoginErrorDateTime = user.LastLoginErrorDateTime;
            dto.LoginErrorTimes        = user.LoginErroeTimes;
            dto.Name                   = user.Name;
            dto.PhoneNum               = user.PhoneNum;
            dto.RoleName               = user.Roles.Select(u => u.Name).ToArray();
            return(dto);
        }
コード例 #12
0
        private AdminUserDTO ToDTO(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CreateDateTime = user.CreateDateTime;
            dto.Id             = user.Id;
            dto.Name           = user.Name;
            dto.PhoneNum       = user.PhoneNum;
            return(dto);
        }
コード例 #13
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);
        }
コード例 #14
0
        public IHttpActionResult GetAdminUserById(string id)
        {
            AdminUserDTO adminDto = service.GetAdminUserById(id);

            if (adminDto == null)
            {
                return(NotFound());
            }

            return(Ok(adminDto));
        }
コード例 #15
0
        private AdminUserDTO ToDTO(AdminUser u)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CreateDateTime = u.CreateDateTime;
            dto.Id             = u.Id;
            dto.PhoneNum       = u.PhoneNum;
            dto.Email          = u.Email;
            dto.Name           = u.Name;
            return(dto);
        }
コード例 #16
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);
        }
コード例 #17
0
        public static AdminUserDTO ConvertAdminUserToDto(AdminUser admin)
        {
            AdminUserDTO adminDto = new AdminUserDTO();

            adminDto.UserId      = admin.Id;
            adminDto.FirstName   = admin.FirstName;
            adminDto.LastName    = admin.LastName;
            adminDto.Email       = admin.Email;
            adminDto.PhoneNumber = admin.PhoneNumber;

            return(adminDto);
        }
コード例 #18
0
        public async Task <IdentityResult> PostAdminUser(AdminUserDTO adminDto)
        {
            AdminUser admin = new AdminUser();

            admin.UserName    = Utils.CreateUserNameForAdminUser(adminDto, db);
            admin.FirstName   = adminDto.FirstName;
            admin.LastName    = adminDto.LastName;
            admin.Email       = adminDto.Email;
            admin.PhoneNumber = adminDto.PhoneNumber;

            logger.Info("Added new admin");
            return(await db.AuthRepository.RegisterAdminUser(admin, String.Concat(adminDto.FirstName, "123")));
        }
コード例 #19
0
        public async Task <IHttpActionResult> PostAdminUser(AdminUserDTO adminDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Parent postedParent = service.PostParent(parentDto);
            //return Created("", postedParent);

            var result = await service.PostAdminUser(adminDto);

            return(Ok());
        }
コード例 #20
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);
        }
コード例 #21
0
        public ActionResult LoadManager()
        {
            long?id = (long?)Session["AdminUserId"];

            if (id == null)
            {
                id = 0;
            }
            AdminUserDTO dto = adminService.GetById((long)id);

            return(Json(new AjaxResult {
                Status = "success", Data = dto.Name
            }));
        }
コード例 #22
0
        public AdminUserDTO ToDTO(AdminUserEntity adminUserEntity)
        {
            AdminUserDTO adminUserDTO = new AdminUserDTO();

            adminUserDTO.Id                     = adminUserEntity.Id;
            adminUserDTO.Name                   = adminUserEntity.Name;
            adminUserDTO.PhoneNum               = adminUserEntity.PhoneNum;
            adminUserDTO.Email                  = adminUserEntity.Emai;
            adminUserDTO.CreateDateTime         = adminUserEntity.CreateTime;
            adminUserDTO.LoginErrorTimes        = adminUserEntity.LoginErrorTimes;
            adminUserDTO.LastLoginErrorDateTime = adminUserEntity.LastLoginErrorDateTime;
            adminUserDTO.CityId                 = adminUserEntity.CityId;
            adminUserDTO.CityName               = adminUserEntity.CityEntity.Name;
            return(adminUserDTO);
        }
コード例 #23
0
        public AdminUserDTO GetAdminUserById(string id)
        {
            AdminUser admin = db.AdminUserRepository.Get(x => x.Id == id).FirstOrDefault();

            if (admin == null)
            {
                return(null);
            }

            AdminUserDTO adminDto = new AdminUserDTO();

            adminDto = Utils.ConvertAdminUserToDto(admin);

            return(adminDto);
        }
コード例 #24
0
        public Task <ApplicationUser> FindByIdAsync(long userId)
        {
            AdminUserDTO u = userService.GetById(userId);

            if (u != null)
            {
                Task <ApplicationUser> t = Task.Run(() => new ApplicationUser()
                {
                    Id       = u.Id,
                    UserName = u.UserName,
                    Password = u.Password
                });
            }

            return(Task.Run(() => (ApplicationUser)null));
        }
コード例 #25
0
        private AdminUserDTO Entity2DTO(AdminUserEntity adminUser)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CityId = adminUser.CityId;
            //这是我没想到的,。
            dto.CityName               = adminUser.City != null ? adminUser.City.Name : "总部";
            dto.CreateDateTime         = adminUser.CreateDateTime;
            dto.Email                  = adminUser.Email;
            dto.Id                     = adminUser.Id;
            dto.LastLoginErrorDateTime = adminUser.LastLoginErrorDateTime;
            dto.LoginErrorTimes        = adminUser.LoginErrorTimes;
            dto.Name                   = adminUser.Name;
            dto.PhoneNum               = adminUser.PhoneNum;
            return(dto);
        }
コード例 #26
0
        public IHttpActionResult PutAdminUser(string id, AdminUserDTO adminDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool done = service.PutAdminUser(id, adminDto);

            if (done == false)
            {
                return(BadRequest());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #27
0
        public Task <ApplicationUser> FindByNameAsync(string userName)
        {
            AdminUserDTO u = userService.GetByName(userName);

            if (u != null)
            {
                return(Task.Run(() => new ApplicationUser()
                {
                    Id = u.Id,
                    UserName = u.UserName,
                    Password = u.Password
                }));
            }

            return(Task.Run(() => (ApplicationUser)null));
        }
コード例 #28
0
        public IActionResult Login([FromForm] LoginModel model)
        {
            AdminUserDTO adminUser = _adminUserService.GetByUserName(model.UserName);

            //判断数据是否为null
            if (adminUser == null)
            {
                return(ApiResult(message: "用户名或密码错误,请重新登录!", httpStatusCode: (int)HttpStatusCode.Forbidden));
            }

            //判断用户是否为锁定状态
            if ((adminUser.LastLoginErrorDateTime - DateTime.Now)?.Minutes < 20 && adminUser.LoginErrorTimes > 5)
            {
                return(ApiResult(message: "当前用户为锁定状态,不可登陆!", httpStatusCode: (int)HttpStatusCode.Unauthorized));
            }

            bool result = _adminUserService.CheckLogin(model.UserName, model.Password);

            if (result)
            {
                //重置登陆错误次数
                if (adminUser.LoginErrorTimes > 0)
                {
                    _adminUserService.ResetLoginError(adminUser.Id);
                    adminUser.LoginErrorTimes        = 0;
                    adminUser.LastLoginErrorDateTime = null;
                }
                //将数据提交至redis
                //await StringSetAsync(RedisKeyPrefix.AdminUserId + adminUser.Id, JsonConvert.SerializeObject(adminUser));
                var data = JWTEnCode(JsonConvert.SerializeObject(adminUser));
                return(ApiResult(data, "登陆成功。", (int)HttpStatusCode.OK));
            }
            else
            {
                adminUser.LoginErrorTimes       += 1;
                adminUser.LastLoginErrorDateTime = DateTime.Now;
                //将数据提交至redis
                //await StringSetAsync(RedisKeyPrefix.AdminUserId + adminUser.Id, JsonConvert.SerializeObject(adminUser));

                var checkRes = _adminUserService.RecordLoginError(model.UserName);
                if (!checkRes)
                {
                    return(ApiResult(message: "出错!", httpStatusCode: (int)HttpStatusCode.Unauthorized));
                }
                return(ApiResult(message: "用户名或密码错误,请重新登录!", httpStatusCode: (int)HttpStatusCode.Unauthorized));
            }
        }
コード例 #29
0
ファイル: ShellViewModel.cs プロジェクト: sevenate/fab
 private static UserViewModel MapToViewModel(AdminUserDTO adminUserDto)
 {
     return(new UserViewModel
     {
         Id = adminUserDto.Id,
         Login = adminUserDto.Login,
         Registered = adminUserDto.Registered,
         LastAccess = adminUserDto.LastAccess,
         DatabaseSize = adminUserDto.DatabaseSize,
         DatabasePath = adminUserDto.DatabasePath,
         DisabledChanged = adminUserDto.DisabledChanged,
         Email = adminUserDto.Email,
         FreeDiskSpaceAvailable = adminUserDto.FreeDiskSpaceAvailable,
         IsDisabled = adminUserDto.IsDisabled,
         ServiceUrl = adminUserDto.ServiceUrl
     });
 }
コード例 #30
0
        public ActionResult Edit(long id)
        {
            CityDTO[]    cityDTOs     = cityService.GetAll();
            RoleDTO[]    roleDTOs     = roleService.GetAll();
            AdminUserDTO adminUserDTO = adminUserService.GetById(id);

            long[] UserRoleIds = roleService.GetByAdminUserId(id).Select(x => x.Id).ToArray();
            LongAdminUserEditViewModel longAdminUserEditViewModel = new LongAdminUserEditViewModel
            {
                AdminUser   = adminUserDTO,
                Cities      = cityDTOs,
                Roles       = roleDTOs,
                UserRoleIds = UserRoleIds
            };

            return(View(longAdminUserEditViewModel));
        }