Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SkuciSe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tim 2 - 2022
SkuciSe
Commits
c799f62f
Commit
c799f62f
authored
Sep 02, 2022
by
Bogdan Andjelkovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dodat grad za korisnika
parent
605dc3c8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
48 additions
and
56 deletions
+48
-56
SkuciSe/src/main/java/com/example/SkuciSe/controller/AppController.java
+5
-2
SkuciSe/src/main/java/com/example/SkuciSe/controller/AppRestController.java
+14
-6
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/Korisnik.java
+4
-6
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/KorisnikDetails.java
+1
-0
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
+16
-23
SkuciSe/src/main/java/com/example/SkuciSe/repository/OglasRepository.java
+3
-17
SkuciSe/src/main/resources/templates/profile.html
+1
-1
SkuciSe/src/main/resources/templates/register.html
+4
-1
No files found.
SkuciSe/src/main/java/com/example/SkuciSe/controller/AppController.java
View file @
c799f62f
...
...
@@ -3,12 +3,11 @@ package com.example.SkuciSe.controller;
import
com.example.SkuciSe.model.korisnik.Korisnik
;
import
com.example.SkuciSe.model.korisnik.KorisnikDetails
;
import
com.example.SkuciSe.repository.KorisnikRepository
;
import
com.example.SkuciSe.repository.LokacijaRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -20,6 +19,8 @@ public class AppController
{
@Autowired
KorisnikRepository
kRepo
;
@Autowired
LokacijaRepository
lRepo
;
@GetMapping
({
"/"
,
""
,
"/index"
})
public
String
getIndex
(
Model
model
,
@AuthenticationPrincipal
KorisnikDetails
korisnik
)
...
...
@@ -42,6 +43,7 @@ public class AppController
if
(
loggedUser
!=
null
)
return
"redirect:/index"
;
model
.
addAttribute
(
"newUser"
,
new
Korisnik
());
model
.
addAttribute
(
"lokacije"
,
lRepo
.
findAll
());
return
(
"register"
);
}
...
...
@@ -63,6 +65,7 @@ public class AppController
model
.
addAttribute
(
"loggedUser"
,
loggedUser
);
model
.
addAttribute
(
"editUser"
,
loggedUser
.
getKorisnik
());
model
.
addAttribute
(
"profileRole"
,
kRepo
.
findRoleById
(
loggedUser
.
getKorisnik
().
getTipId
()));
model
.
addAttribute
(
"grad"
,
lRepo
.
findById
(
loggedUser
.
getKorisnik
().
getGradId
()));
return
(
"profile"
);
}
...
...
SkuciSe/src/main/java/com/example/SkuciSe/controller/AppRestController.java
View file @
c799f62f
package
com
.
example
.
SkuciSe
.
controller
;
import
com.example.SkuciSe.model.korisnik.Korisnik
;
import
com.example.SkuciSe.model.korisnik.KorisnikDetails
;
import
com.example.SkuciSe.model.lokacija.Lokacija
;
import
com.example.SkuciSe.repository.KorisnikRepository
;
import
com.example.SkuciSe.repository.LokacijaRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
public
class
AppRestController
{
@Autowired
KorisnikRepository
kRepo
;
@Autowired
LokacijaRepository
lRepo
;
@GetMapping
(
"/listLokacija"
)
public
List
<
Lokacija
>
getRegister
()
{
return
(
lRepo
.
findAll
()
);
}
}
\ No newline at end of file
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/Korisnik.java
View file @
c799f62f
...
...
@@ -19,9 +19,9 @@ public class Korisnik {
String
email
;
String
sifra
;
String
telefon
;
int
tipId
;
private
String
slika
;
int
tipId
;
int
gradId
;
@Override
public
String
toString
()
{
...
...
@@ -33,9 +33,8 @@ public class Korisnik {
", sifra='"
+
sifra
+
'\''
+
", telefon='"
+
telefon
+
'\''
+
", tipId="
+
tipId
+
", slika="
+
slika
+
", gradId="
+
gradId
+
", slika='"
+
slika
+
'\''
+
'}'
;
}
}
\ No newline at end of file
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/KorisnikDetails.java
View file @
c799f62f
...
...
@@ -58,6 +58,7 @@ public class KorisnikDetails implements UserDetails {
this
.
korisnik
.
setPrezime
(
korisnik
.
getPrezime
());
this
.
korisnik
.
setEmail
(
korisnik
.
getEmail
());
this
.
korisnik
.
setTelefon
(
korisnik
.
getTelefon
());
this
.
korisnik
.
setGradId
(
korisnik
.
getGradId
());
}
public
void
setKorisnikSlika
(
String
slika
)
{
...
...
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
View file @
c799f62f
package
com
.
example
.
SkuciSe
.
repository
;
import
com.example.SkuciSe.model.korisnik.Korisnik
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.sql.*
;
import
java.util.Base64
;
import
java.util.Optional
;
@Component
public
class
KorisnikRepository
{
Connection
connection
=
null
;
Statement
statement
=
null
;
public
KorisnikRepository
()
{
try
{
connection
=
DriverManager
.
getConnection
(
"jdbc:mariadb://localhost/skucise"
,
"root"
,
""
);
statement
=
connection
.
createStatement
();
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Autowired
DataBase
dataBase
;
@Autowired
LokacijaRepository
lRepo
;
public
void
insert
(
Korisnik
korisnik
,
MultipartFile
multipartFile
)
throws
IOException
{
String
slika
=
Base64
.
getEncoder
().
encodeToString
(
multipartFile
.
getBytes
());
System
.
out
.
println
(
slika
);
String
sql
=
"insert into korisnik( ime, prezime, telefon, email, sifra, tipId, slika
) values('"
+
korisnik
.
getIme
()+
"','"
+
korisnik
.
getPrezime
()+
"','"
+
korisnik
.
getTelefon
()+
"','"
+
korisnik
.
getEmail
()+
"','"
+
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
())+
"',1, '"
+
slika
+
"'
)"
;
String
sql
=
"insert into korisnik( ime, prezime, telefon, email, sifra, tipId, slika
, gradid) values('"
+
korisnik
.
getIme
()+
"','"
+
korisnik
.
getPrezime
()+
"','"
+
korisnik
.
getTelefon
()+
"','"
+
korisnik
.
getEmail
()+
"','"
+
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
())+
"',1, '"
+
slika
+
"', "
+
korisnik
.
getGradId
()+
"
)"
;
System
.
out
.
println
(
sql
);
try
{
statement
.
executeUpdate
(
sql
);
dataBase
.
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
@@ -47,10 +39,11 @@ public class KorisnikRepository
"',email = '"
+
korisnik
.
getEmail
()
+
"',sifra = '"
+
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
())
+
"',telefon = '"
+
korisnik
.
getTelefon
()
+
"',gradId = '"
+
korisnik
.
getGradId
()
+
"' where korisnikid = "
+
korisnik
.
getKorisnikId
();
try
{
System
.
out
.
println
(
sql
);
statement
.
executeUpdate
(
sql
);
dataBase
.
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
@@ -64,7 +57,7 @@ public class KorisnikRepository
slika
=
Base64
.
getEncoder
().
encodeToString
(
file
.
getBytes
());
sql
=
" update korisnik "
+
" set slika = '"
+
slika
+
"' where korisnikid = "
+
korisnik
.
getKorisnikId
();
statement
.
executeUpdate
(
sql
);
dataBase
.
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
...
...
@@ -77,10 +70,10 @@ public class KorisnikRepository
String
sql
=
"select * from korisnik where email = '"
+
email
+
"'"
;
ResultSet
rs
=
null
;
try
{
rs
=
statement
.
executeQuery
(
sql
);
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
{
return
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
get
Int
(
"tipid"
),
rs
.
getString
(
"slika
"
)));
return
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
get
String
(
"slika"
),
rs
.
getInt
(
"tipid"
),
rs
.
getInt
(
"gradid
"
)));
}
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
@@ -91,10 +84,10 @@ public class KorisnikRepository
String
sql
=
"select * from korisnik where KorisnikId = "
+
id
;
ResultSet
rs
=
null
;
try
{
rs
=
statement
.
executeQuery
(
sql
);
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
{
return
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
get
Int
(
"tipid"
),
rs
.
getString
(
"slika
"
)));
return
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
get
String
(
"slika"
),
rs
.
getInt
(
"tipid"
),
rs
.
getInt
(
"gradid
"
)));
}
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
@@ -107,7 +100,7 @@ public class KorisnikRepository
String
sql
=
"select * from tipkorisnika where tipId = "
+
tipid
;
ResultSet
rs
=
null
;
try
{
rs
=
statement
.
executeQuery
(
sql
);
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
{
return
rs
.
getString
(
"naziv"
);
...
...
SkuciSe/src/main/java/com/example/SkuciSe/repository/OglasRepository.java
View file @
c799f62f
package
com
.
example
.
SkuciSe
.
repository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
@Component
public
class
OglasRepository
{
Connection
connection
=
null
;
Statement
statement
=
null
;
public
OglasRepository
()
{
try
{
connection
=
DriverManager
.
getConnection
(
"jdbc:mariadb://localhost/skucise"
,
"root"
,
""
);
statement
=
connection
.
createStatement
();
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Autowired
DataBase
dataBase
;
}
SkuciSe/src/main/resources/templates/profile.html
View file @
c799f62f
...
...
@@ -100,7 +100,7 @@
</div>
<div
class=
"d-flex align-items-center justify-content-between"
>
<p
class=
"py-2"
>
Grad
</p>
<p
class=
"py-2 text-muted"
>
Kragujevac
</p>
<p
class=
"py-2 text-muted"
th:object=
"${grad}"
th:text=
"${grad.naziv}"
>
</p>
</div>
</div>
</div>
...
...
SkuciSe/src/main/resources/templates/register.html
View file @
c799f62f
...
...
@@ -71,7 +71,10 @@
<div
class=
"invalid-feedback"
>
Email ne sme biti prazan!
</div>
</div>
<select
th:field=
"${newUser.gradId}"
>
<option
th:each=
"lokacija: ${lokacije}"
th:value=
"${lokacija.getLokacijaId()}"
th:text=
"${lokacija.getNaziv()}"
>
</option>
</select>
<div
class=
"col-md-12"
>
<input
th:field=
"${newUser.sifra}"
class=
"form-control"
type=
"password"
name=
"password"
placeholder=
"Sifra"
required
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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