A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.9 KiB

package org.ros.chatto.service;
import java.util.List;
import org.ros.chatto.dto.UserRegistrationDTO;
import org.ros.chatto.model.ChatUser;
import org.ros.chatto.model.Role;
import org.ros.chatto.model.UserRole;
import org.ros.chatto.repository.UserRepository;
import org.ros.chatto.repository.UserRepositoryCustom;
import org.ros.chatto.repository.UserRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService{
@Autowired
UserRepository userRepository;
@Autowired
UserRoleRepository userRoleRepository;
@Autowired
PasswordEncoder passwordEncoder;
@Autowired
RoleService roleService;
@Autowired
UserRepositoryCustom userRepositoryCustom;
@Override
public void saveChatUser(ChatUser user) {
// TODO Auto-generated method stub
ChatUser changedUser = userRepository.save(user);
UserRole userRole = new UserRole();
userRole.setRole(roleService.getRole("USER"));
userRole.setUser(changedUser);
userRoleRepository.save(userRole);
}
@Override
public void registerUser(UserRegistrationDTO userRegistrationDTO) {
// TODO Auto-generated method stub
ChatUser user = new ChatUser();
user.setUserName(userRegistrationDTO.getUserName());
user.setPassword(passwordEncoder.encode(userRegistrationDTO.getPassword()));
ChatUser changedUser = userRepository.save(user);
UserRole userRole = new UserRole();
Role role = roleService.getRole("USER");
userRole.setRole(role);
userRole.setUser(changedUser);
System.out.println(role.getRoleId());
System.out.println(changedUser.getUserID());
userRoleRepository.save(userRole);
}
@Override
public List<String> findAllOtherUsers(String userName) {
// TODO Auto-generated method stub
return userRepositoryCustom.getAllUserNames(userName);
}
}