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.
 
 
 
 
 
 

53 lines
1.5 KiB

package org.ros.chatto.service;
import org.ros.chatto.model.ChatUser;
import org.ros.chatto.model.Role;
import org.ros.chatto.model.UserDTO;
import org.ros.chatto.model.UserRole;
import org.ros.chatto.repository.UserRepository;
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;
@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(UserDTO userDTO) {
// TODO Auto-generated method stub
ChatUser user = new ChatUser();
user.setUserName(userDTO.getUserName());
user.setPassword(passwordEncoder.encode(userDTO.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);
}
}