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
068f3644
Commit
068f3644
authored
Sep 11, 2022
by
Nikola Markovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sql procedure: insertKorisnik, updateKorisnik
parent
1b92a3a7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
17 deletions
+35
-17
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
+29
-14
SkuciSe/src/main/resources/templates/password-edit.html
+3
-2
SkuciSe/src/main/resources/templates/profile-edit.html
+3
-1
No files found.
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
View file @
068f3644
...
@@ -22,10 +22,23 @@ public class KorisnikRepository
...
@@ -22,10 +22,23 @@ public class KorisnikRepository
public
void
insert
(
Korisnik
korisnik
,
MultipartFile
multipartFile
)
throws
EmailPostoji
{
public
void
insert
(
Korisnik
korisnik
,
MultipartFile
multipartFile
)
throws
EmailPostoji
{
if
(
this
.
findByEmail
(
korisnik
.
getEmail
())
==
null
)
if
(
this
.
findByEmail
(
korisnik
.
getEmail
())
==
null
)
{
{
CallableStatement
stmt
=
null
;
ResultSet
rs
=
null
;
try
{
try
{
String
slika
=
Base64
.
getEncoder
().
encodeToString
(
multipartFile
.
getBytes
());
String
slika
=
Base64
.
getEncoder
().
encodeToString
(
multipartFile
.
getBytes
());
String
sql
=
"insert into korisnik( ime, prezime, telefon, email, sifra, tipId, slika, gradid, enabled) values('"
+
korisnik
.
getIme
()+
"','"
+
korisnik
.
getPrezime
()+
"','"
+
korisnik
.
getTelefon
()+
"','"
+
korisnik
.
getEmail
()+
"','"
+
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
())+
"',1, '"
+
slika
+
"', "
+
korisnik
.
getGradId
()+
",false)"
;
String
sql
=
"{call insertKorisnik(?,?,?,?,?,?,?,?)}"
;
dataBase
.
statement
.
executeUpdate
(
sql
);
//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()+",false)";
stmt
=
dataBase
.
connection
.
prepareCall
(
sql
);
stmt
.
setString
(
1
,
korisnik
.
getIme
());
stmt
.
setString
(
2
,
korisnik
.
getPrezime
());
stmt
.
setString
(
3
,
korisnik
.
getTelefon
());
stmt
.
setString
(
4
,
korisnik
.
getEmail
());
stmt
.
setString
(
5
,
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
()));
stmt
.
setInt
(
6
,
1
);
stmt
.
setString
(
7
,
slika
);
stmt
.
setInt
(
8
,
korisnik
.
getGradId
());
stmt
.
addBatch
();
stmt
.
executeBatch
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
System
.
out
.
println
(
e
.
getMessage
());
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
...
@@ -40,17 +53,20 @@ public class KorisnikRepository
...
@@ -40,17 +53,20 @@ public class KorisnikRepository
public
void
update
(
Korisnik
korisnik
)
public
void
update
(
Korisnik
korisnik
)
{
{
String
sql
=
" update korisnik "
+
CallableStatement
stmt
=
null
;
" set ime = '"
+
korisnik
.
getIme
()
+
String
sql
=
"{call updateKorisnik(?,?,?,?,?,?)}"
;
"',prezime = '"
+
korisnik
.
getPrezime
()
+
"',email = '"
+
korisnik
.
getEmail
()
+
"',sifra = '"
+
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
())
+
"',telefon = '"
+
korisnik
.
getTelefon
()
+
"',gradId = '"
+
korisnik
.
getGradId
()
+
"' where korisnikid = "
+
korisnik
.
getKorisnikId
();
try
{
try
{
dataBase
.
statement
.
executeUpdate
(
sql
);
stmt
=
dataBase
.
connection
.
prepareCall
(
sql
);
}
catch
(
SQLException
e
)
{
stmt
.
setString
(
1
,
korisnik
.
getIme
());
stmt
.
setString
(
2
,
korisnik
.
getPrezime
());
stmt
.
setString
(
3
,
korisnik
.
getEmail
());
stmt
.
setString
(
4
,
korisnik
.
getTelefon
());
stmt
.
setInt
(
5
,
korisnik
.
getGradId
());
stmt
.
setInt
(
6
,
korisnik
.
getKorisnikId
());
System
.
out
.
println
(
stmt
.
toString
());
stmt
.
execute
();
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
...
@@ -61,8 +77,7 @@ public class KorisnikRepository
...
@@ -61,8 +77,7 @@ public class KorisnikRepository
String
sql
=
null
;
String
sql
=
null
;
try
{
try
{
slika
=
Base64
.
getEncoder
().
encodeToString
(
file
.
getBytes
());
slika
=
Base64
.
getEncoder
().
encodeToString
(
file
.
getBytes
());
sql
=
" update korisnik "
+
sql
=
" update korisnik "
+
" set slika = '"
+
slika
+
"' where korisnikid = "
+
korisnik
.
getKorisnikId
();
" set slika = '"
+
slika
+
"' where korisnikid = "
+
korisnik
.
getKorisnikId
();
dataBase
.
statement
.
executeUpdate
(
sql
);
dataBase
.
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
SkuciSe/src/main/resources/templates/password-edit.html
View file @
068f3644
<!DOCTYPE html>
<!DOCTYPE html>
<html
lang=
"en"
>
<html
lang=
"en"
xmlns:th=
"http://www.w3.org/1999/xhtml"
>
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
/>
...
@@ -93,7 +93,8 @@
...
@@ -93,7 +93,8 @@
<form
class=
"requires-validation"
novalidate
th:object=
"${editUser}"
method=
"POST"
<form
class=
"requires-validation"
novalidate
th:object=
"${editUser}"
method=
"POST"
th:action=
"@{/profile/password-edit-save}"
enctype=
"multipart/form-data"
th:action=
"@{/profile/password-edit-save}"
enctype=
"multipart/form-data"
onsubmit=
"return validateForm()"
>
onsubmit=
"return validateForm()"
>
<input
th:field=
"${editUser.korisnikId}"
class=
"form-control"
type=
"hidden"
name=
"name"
placeholder=
"Ime"
required
>
<div
class=
"col-md-12"
>
<div
class=
"col-md-12"
>
<span
style=
"color:white;"
>
Unesite novu sifru
</span>
<span
style=
"color:white;"
>
Unesite novu sifru
</span>
<input
th:field=
"${editUser.sifra}"
type=
"password"
<input
th:field=
"${editUser.sifra}"
type=
"password"
...
...
SkuciSe/src/main/resources/templates/profile-edit.html
View file @
068f3644
<!DOCTYPE html>
<!DOCTYPE html>
<html
lang=
"en"
>
<html
lang=
"en"
xmlns:th=
"http://www.w3.org/1999/xhtml"
>
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
/>
...
@@ -94,6 +94,8 @@
...
@@ -94,6 +94,8 @@
<div
class=
"form-items"
>
<div
class=
"form-items"
>
<form
class=
"requires-validation"
novalidate
th:object=
"${editUser}"
method=
"POST"
<form
class=
"requires-validation"
novalidate
th:object=
"${editUser}"
method=
"POST"
th:action=
"@{/profile/edit-save}"
enctype=
"multipart/form-data"
>
th:action=
"@{/profile/edit-save}"
enctype=
"multipart/form-data"
>
<input
th:field=
"${editUser.korisnikId}"
class=
"form-control"
type=
"hidden"
name=
"name"
placeholder=
"Ime"
required
>
<div
class=
"col-md-12"
>
<div
class=
"col-md-12"
>
<input
th:field=
"${editUser.ime}"
class=
"form-control"
type=
"text"
<input
th:field=
"${editUser.ime}"
class=
"form-control"
type=
"text"
name=
"name"
placeholder=
"Ime"
required
>
name=
"name"
placeholder=
"Ime"
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