Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Landi And Friends
Landi And Friends Adpro
Commits
48b5c68e
Commit
48b5c68e
authored
May 27, 2022
by
MUHAMMAD AAQIL ABDULLAH
Browse files
Create admin user
parent
728b4c67
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/id/ac/ui/cs/advprog/landiandfriends/service/UserServiceImpl.java
View file @
48b5c68e
...
...
@@ -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
);
...
...
src/main/resources/application.properties
View file @
48b5c68e
...
...
@@ -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
...
...
src/main/resources/templates/curator-dashboard.html
View file @
48b5c68e
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment