Fakultas Ilmu Komputer UI

Commit 48b5c68e authored by MUHAMMAD AAQIL ABDULLAH's avatar MUHAMMAD AAQIL ABDULLAH
Browse files

Create admin user

parent 728b4c67
......@@ -8,6 +8,8 @@ import id.ac.ui.cs.advprog.landiandfriends.repository.RoleRepository;
import id.ac.ui.cs.advprog.landiandfriends.repository.UserRepository;
import id.ac.ui.cs.advprog.landiandfriends.security.RyanUserDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
......@@ -18,20 +20,29 @@ import java.util.List;
@Service
@RequiredArgsConstructor
@ConfigurationProperties("admin")
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final RoleRepository roleRepository;
@Value("${admin.username}")
private String username;
@Value("${admin.password}")
private String password;
@Value("${admin.email}")
private String email;
@PostConstruct
private void createAdminIfNotCreated(){
User admin = userRepository.findByUsername("admin");
User admin = userRepository.findByUsername(username);
if(admin == null) {
admin = new User();
admin.setUsername("admin");
admin.setPassword(encodePassword("admin"));
admin.setEmail("admin");
admin.setUsername(username);
admin.setPassword(encodePassword(password));
admin.setEmail(email);
}
Role adminRole = roleRepository.findByName("ADMIN");
admin.setRoles(adminRole == null ? new Role("ADMIN") : adminRole);
......
......@@ -5,9 +5,13 @@ spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
spring.datasource.maximum-pool-size=100
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.url=jdbc:postgresql://postgres:5432/${POSTGRES_DB}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}
admin.username = ${ADMIN_USERNAME}
admin.password = ${ADMIN_PASSWORD}
admin.email = ${ADMIN_EMAIL}
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
......
......@@ -80,19 +80,16 @@
<a th:href ="${username.isBlank() ? '/login' : '/profile'}" class="sign-in-text" style="text-decoration: none; color: inherit" th:text="${username.isBlank()} ? 'Sign In' : ${username}"></a>
</div>
<div class="container">
<a href="/curator/book-list">
<h2 class="subtitle">Book List</h2>
</a>
<a href="/curator/create-article">
<h2 class="subtitle">Create Article</h2>
</a>
<a href="/curator/create-article">
<h2 class="subtitle">Create Article</h2>
<a href="/curator/genre-list">
<h2 class="subtitle">Genre List</h2>
</a>
<a href="/curator/create-article">
<h2 class="subtitle">Create Article</h2>
</a>
</div>
</div>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment