Exemple #1
0
        private void SeedData(ModelBuilder modelBuilder)
        {
            // NOTE: We use ".HasData" here, this means this data will ONLY be seeded IF the table
            // is completley empty.

            const string usernameAdmin            = "admin";
            var          passwordAdmin            = SecurePasswordHasherHelperService.Hash("admin");
            const string emailAdmin               = "*****@*****.**";
            const string lastNameAdmin            = "Gigica";
            const string firstNameAdmin           = "Comanel";
            var          allowedRolesAdmin        = new[] { "admin" };
            var          birthDate                = DateTime.Now;
            var          defaultProfileImageAdmin = Photo.Create("/StaticFiles/Images/ProfileImages/DefaultProfileImage.png");
            var          userAdmin                = User.Create(usernameAdmin, passwordAdmin, emailAdmin, lastNameAdmin, firstNameAdmin, birthDate, allowedRolesAdmin);
            //userAdmin.SetProfileImage(defaultProfileImageAdmin);

            const string usernameModerator            = "moderator";
            var          passwordModerator            = SecurePasswordHasherHelperService.Hash("moderator");
            const string emailModerator               = "*****@*****.**";
            const string lastNameModerator            = "Jhony";
            const string firstNameModerator           = "Comanel";
            var          allowedRolesModerator        = new[] { "moderator" };
            var          defaultProfileImageModerator = Photo.Create("/StaticFiles/Images/ProfileImages/DefaultProfileImage.png");
            var          userModerator = User.Create(usernameModerator, passwordModerator, emailModerator, lastNameModerator, firstNameModerator, birthDate, allowedRolesModerator);
            //userModerator.SetProfileImage(defaultProfileImageModerator);

            const string usernameNormalUser            = "******";
            var          passwordNormalUser            = SecurePasswordHasherHelperService.Hash("user");
            const string emailNormalUser               = "******";
            const string lastNameNormalUser            = "******";
            const string firstNameNormalUser           = "******";
            var          allowedRolesNormalUser        = new[] { "user" };
            var          defaultProfileImageNormalUser = Photo.Create("/StaticFiles/Images/ProfileImages/DefaultProfileImage.png");
            var          userNormalUser = User.Create(usernameNormalUser, passwordNormalUser, emailNormalUser, lastNameNormalUser, firstNameNormalUser, birthDate, allowedRolesNormalUser);

            //userNormalUser.SetProfileImage(defaultProfileImageNormalUser);

            modelBuilder.Entity <Photo>()
            .HasData(
                defaultProfileImageAdmin,
                defaultProfileImageModerator,
                defaultProfileImageNormalUser
                );

            modelBuilder.Entity <User>()
            .HasData(
                userAdmin,
                userModerator,
                userNormalUser
                );
        }
Exemple #2
0
        public async Task <bool> CredentialsAreValidAsync(string username, string password)
        {
            var existingUser = await _unitOfWork.Users.FindByUsernameAsync(username);

            if (existingUser == null)
            {
                return(false);
            }

            if (SecurePasswordHasherHelperService.Verify(password, existingUser.Password))
            {
                return(true);
            }
            return(false);
        }
        public async Task<IActionResult> PostAsync([FromBody] SaveUserResource resource)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState.GetErrorMessages());

            var user = LocationMaster_API.Domain.Entities.User.Create(resource.Username,
                            SecurePasswordHasherHelperService.Hash(resource.Password), resource.Email, resource.LastName, resource.FirstName, resource.BirthDate, new[] { "user" });

            var result = await _userService.SaveAsync(user);

            if (!result.Success)
                return BadRequest(result.Message);

            var userResource = _mapper.Map<User, UserResource>(result.User);
            return Created($"/api/v1/users/{userResource.UserId}", userResource);
        }