예제 #1
0
        public bool Register(UserRegistrationDTO request, string Role)
        {
            if (userRepository.CheckEmailExists(request.Email.ToLower()))
            {
                return(false);
            }
            User u = new User
            {
                Email    = request.Email.ToLower(),
                Password = passwordManager.HashPassword(request.Password)
            };

            userRepository.Insert(u).Wait();
            rolesRepository.AssignRoleToUser(Role, u.Id);
            Customer customer = new Customer {
                Name = request.Name
            };

            if (Enum.TryParse(typeof(Districts), request.District, false, out object?district) && district != null)
            {
                customer.Residence = (Districts)district;
            }
            else
            {
                customer.Residence = Districts.Ryad;
            }

            customer.UserId = u.Id;
            customerRepository.Insert(customer);
            return(true);
        }
예제 #2
0
        public User Create(User user, int advertiserId)
        {
            var existingUser = _userRepository.FindByEmail(user.Email);

            if (existingUser != null)
            {
                throw new CustomHttpException(422, "This username is not available");
            }
            user.Password = _passwordManager.HashPassword(user.Password);
            var transaction = _context.Database.BeginTransaction();

            try
            {
                var createdUserId = _userRepository.Save(user);

                transaction.Commit();
                return(_userRepository.FindById(createdUserId));
            }
            catch (Exception ex)
            {
                //TODO: Log ex
                transaction.Rollback();
                throw new CustomHttpException(500, "Internal server error");
            }
        }
예제 #3
0
        public async Task <Unit> Handle(RegisterNewUserCommand request, CancellationToken cancellationToken)
        {
            var userRegistration = User.RegisterNewUser(
                request.Login,
                _passwordManager.HashPassword(request.Password),
                request.Email,
                request.FirstName,
                request.LastName,
                _usersCounter);

            await _userRepository.AddAsync(userRegistration);

            return(Unit.Value);
        }
예제 #4
0
        public bool Register(UserAuthenticationRequest request, string Role)
        {
            if (UserRepository.CheckUsernameExists(request.Username))
            {
                return(false);
            }
            User u = new User
            {
                UserName = request.Username,
                Password = PasswordManager.HashPassword(request.Password)
            };

            UserRepository.Insert(u).Wait();
            RolesRepository.AssignRoleToUser(Role, u.Id);
            return(true);
        }
예제 #5
0
        public int Register(UserAuthenticationRequest request, UserRole Role)
        {
            if (UserRepository.CheckUsernameExists(request.Username))
            {
                return(-1);
            }
            User user = new User
            {
                UserName = request.Username,
                Password = PasswordManager.HashPassword(request.Password),
                Role     = Role
            };

            UserRepository.Insert(user).Wait();
            return(user.Id);
        }
예제 #6
0
        public void MakeNewAccount(string username, string password)
        {
            var hashPassword = passwordManager.HashPassword(password);

            using (var db = new LockdownContext())
            {
                db.Users.Add(new User
                {
                    Username   = username,
                    Password   = hashPassword,
                    CreatedOn  = DateTime.Now,
                    ModifiedOn = DateTime.Now
                });

                db.SaveChanges();
            }
        }
예제 #7
0
        public models.Instructor Save(VMInstructor entity)
        {
            var existingUser = _userRepository.FindByEmail(entity.Email);

            if (existingUser != null)
            {
                throw new CustomHttpException(422, " Esse “E-mail” já existe na base de dados.");
            }
            var existingUserWithCpf = _userRepository.FindByCPF(entity.cpf);

            if (existingUserWithCpf != null)
            {
                throw new CustomHttpException(422, " Esse “CPF” já existe na base de dados.");
            }
            var existingUserWithRG = _userRepository.FindByRg(entity.RG);

            if (existingUserWithRG != null)
            {
                throw new CustomHttpException(422, " Esse “RG” já existe na base de dados.");
            }
            var user = _mapper.Map <User>(entity);

            user.UserTypeId = 3;
            user.Password   = _passwordManager.HashPassword(user.Password);
            var transaction = _context.Database.BeginTransaction();

            try
            {
                var createdUser = _userRepository.Save(user);
                var instructor  = _mapper.Map <models.Instructor>(entity);
                instructor.userId = createdUser;
                var createdInstructor = _instructorRepository.Save(instructor);
                transaction.Commit();
                return(_instructorRepository.FindById(createdInstructor));
            }
            catch (Exception ex)
            {
                //TODO: Log ex
                transaction.Rollback();
                throw new CustomHttpException(500, "Internal server error");
            }
        }
예제 #8
0
        public void Configure(EntityTypeBuilder <User> builder)
        {
            builder.ToTable("user");

            builder.Property(p => p.Id)
            .HasColumnName("id")
            .IsRequired();

            builder.Property(p => p.Name)
            .HasColumnName("name")
            .HasMaxLength(250)
            .IsRequired();

            builder.Property(p => p.Email)
            .HasColumnName("email")
            .HasMaxLength(255)
            .IsRequired();

            builder.Property(p => p.Password)
            .HasColumnName("password")
            .HasMaxLength(250)
            .IsRequired();

            builder.Property(p => p.Rg)
            .HasColumnName("rg")
            .HasMaxLength(15)
            .IsRequired();
            builder.Property(p => p.Cpf)
            .HasColumnName("cpf")
            .HasMaxLength(15)
            .IsRequired();

            builder.Property(p => p.UserTypeId)
            .HasColumnName("userTypeId")
            .IsRequired();

            builder.Property(p => p.CreatedAt)
            .HasColumnName("createdAt")
            .HasColumnType("datetime")
            .ValueGeneratedOnAdd();

            builder.Property(p => p.UpdatedAt)
            .HasColumnName("updatedAt")
            .HasColumnType("datetime")
            .ValueGeneratedOnAddOrUpdate();

            builder.Property(p => p.DeletedAt)
            .HasColumnName("deletedAt")
            .HasColumnType("datetime")
            .IsRequired(false);

            builder
            .Ignore(p => p.Token);

            builder
            .HasKey(p => p.Id);

            builder
            .HasOne(e => e.UserType)
            .WithMany(e => e.Users)
            .HasForeignKey(e => e.UserTypeId);

            builder
            .HasData(
                new User
            {
                Id         = 1,
                Name       = "GymClub",
                Email      = "*****@*****.**",
                Password   = _passwordManager.HashPassword("GymclubSenha"),
                Rg         = "17.979.066-3",
                Cpf        = "288.789.134-05",
                UserTypeId = 1
            },
                new User
            {
                Id         = 2,
                Name       = "Fernanda Abreu",
                Email      = "*****@*****.**",
                Password   = _passwordManager.HashPassword("GymclubSenha"),
                Rg         = "29.003.656-2",
                Cpf        = "037.467.048-04",
                UserTypeId = 5
            },
                new User
            {
                Id         = 3,
                Name       = "Instrutor  teste",
                Email      = "*****@*****.**",
                Password   = _passwordManager.HashPassword("GymclubSenha"),
                Rg         = "16.224.837-4",
                Cpf        = "276.267.434-40",
                UserTypeId = 3
            },
                new User
            {
                Id         = 4,
                Name       = "Recepcionista  teste",
                Email      = "*****@*****.**",
                Password   = _passwordManager.HashPassword("GymclubSenha"),
                Rg         = "37.088.796-7",
                Cpf        = "897.552.694-10",
                UserTypeId = 2
            },
                new User
            {
                Id         = 5,
                Name       = "Usuário 2",
                Email      = "*****@*****.**",
                Password   = _passwordManager.HashPassword("GymclubSenha"),
                Rg         = "42.970.977-8",
                Cpf        = "802.671.886-09",
                UserTypeId = 5
            }
                );
        }
예제 #9
0
 string IPasswordHasher <User> .HashPassword(User user, string password)
 {
     return(_passwordManager.HashPassword(password));
 }
예제 #10
0
 public string HashPassword(string password)
 {
     return(_passwordManager.HashPassword(password));
 }