public async Task <LoginDTO> LoginAsync(string Email, string Password)
        {
            Core.Domain.User user = await _userRepository.GetAsync(Email);

            if (user == null)
            {
                throw new Exception("Invalid credentials.");
            }
            if (user.Password != Password.Hash())
            {
                throw new Exception("Invalid credentials.");
            }

            if (user.Blocked == true)
            {
                throw new Exception("Blocked account.");
            }

            string token = _jwtHandler.CreateToken(user.Id, user.Role);

            return(new LoginDTO
            {
                Token = token,
                Id = user.Id,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email,
                PhoneNumber = user.PhoneNumber,
                Role = user.Role
            });
        }
        public async Task DeleteAsync(Guid Id)
        {
            Core.Domain.User user = await _userRepository.GetAsync(Id);

            if (user == null)
            {
                throw new Exception($"Exception id: '{Id}' does not exists");
            }
            await _userRepository.DeleteAsync(user);
        }
Example #3
0
        public async Task RegisterAsync(Guid userId, string email, string name, string password, string role = "user")
        {
            var user = await _userRepository.GetAsync(email);

            if (user != null)
            {
                throw new Exception($"User with emial {email} already exists");
            }
            user = new Core.Domain.User(userId, role, name, email, password);
            await _userRepository.AddAsync(user);
        }
        public async Task ChangeOfUserStatus(Guid id)
        {
            Core.Domain.User user = await _adminRepository.GetUserAsync(id);

            if (user == null)
            {
                return;
            }

            user.ChangeStatus();
            await _adminRepository.UpdateUserAsync(user);
        }
 protected void rptUsers_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (Request.QueryString["Command"] != null && e.Item.DataItem is Core.Domain.User)
     {
         Core.Domain.User user        = (Core.Domain.User)e.Item.DataItem;
         string           command     = Request.QueryString["Command"];
         HtmlAnchor       processData = e.Item.FindControl("processData") as HtmlAnchor;
         if (processData != null)
         {
             processData.Attributes.Add("onClick", "window.opener." + command + "('" + user.Id + "','" + user.UserName + "'); self.close();");
         }
     }
 }
        public async Task UpdateAsync(Guid Id, UpdateUser command)
        {
            Core.Domain.User existUser = await _userRepository.GetAsync(Id);

            if (existUser == null)
            {
                throw new Exception($"Exception with id: '{Id}' does not exists");
            }
            if (existUser.Password != command.OldPassword.Hash())
            {
                throw new Exception("Exception password: The old password is incorrect");
            }

            Core.Domain.User user = await _userRepository.GetAsync(command.Email);

            if (user != null && user != existUser)
            {
                throw new Exception($"Exception with e-mail: '{command.Email}' already exists");
            }

            user = await _userRepository.GetByPhoneAsync(command.PhoneNumber);

            if (user != null && user != existUser)
            {
                throw new Exception($"Exception with this phone number: '{command.PhoneNumber}' already exists");
            }
            if (command.FirstName != null)
            {
                existUser.SetFirstName(command.FirstName);
            }
            if (command.LastName != null)
            {
                existUser.SetLastName(command.LastName);
            }
            if (command.PhoneNumber != null)
            {
                existUser.SetPhoneNumber(command.PhoneNumber);
            }
            if (command.Email != null)
            {
                existUser.SetEmail(command.Email);
            }
            if (command.Password != null)
            {
                existUser.SetPassword(command.Password.Hash());
            }
            await _userRepository.UpdateAsync(existUser);
        }
        public async Task RegisterAsync(Register data)
        {
            Core.Domain.User user = await _userRepository.GetAsync(data.Email);

            if (user != null)
            {
                throw new Exception($"User e-mail: '{data.Email}' already exists.");
            }
            user = await _userRepository.GetByPhoneAsync(data.PhoneNumber);

            if (user != null)
            {
                throw new Exception($"User phone number: '{data.PhoneNumber}' already exists.");
            }
            user = new Core.Domain.User(data.FirstName, data.LastName, data.PhoneNumber, data.Email, data.Password.Hash());
            SendEmailExtensions.SendEmail(data.Email);
            await _userRepository.AddAsync(user);
        }
        public async Task AddAdvertisementAsync(CreateAdvertisment Command, Guid UserId)
        {
            Guid advertisement_id = Guid.NewGuid();

            ISet <AdvertisementImage> Images = new HashSet <AdvertisementImage>();

            foreach (var Image in Command.Images)
            {
                Images.Add(new AdvertisementImage(advertisement_id, Image.Image, Image.Name, Image.Description));
            }

            Core.Domain.User user = await _userRepository.GetAsync(UserId);

            Advertisement advertisement = user.AddAdvertisement(advertisement_id, Command.Title,
                                                                Command.Description, Command.Price, Command.City, Command.Street,
                                                                Command.Size, Command.Category, Images, Command.Floor);
            await _userRepository.AddAdvertisementAsync(advertisement);
        }
Example #9
0
        public async Task <bool> RegisterUser(RegisterMessage message)
        {
            if (MailExists(message.Mail))
            {
                return(false);
            }

            var hashedPassword = BCrypt.Net.BCrypt.HashPassword(message.Password);

            var newUser = new Core.Domain.User()
            {
                Username = message.Username,
                Password = hashedPassword,
                Mail     = message.Mail,
                Role     = 3
            };

            _userRepository.Insert(newUser);

            return(true);
        }