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
bef7a9dc
Commit
bef7a9dc
authored
Sep 01, 2022
by
Bogdan Andjelkovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
profile picture upload - solved
parent
71ac5d4c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
20 deletions
+22
-20
SkuciSe/src/main/java/com/example/SkuciSe/controller/AppController.java
+4
-6
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/Korisnik.java
+1
-9
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
+16
-4
SkuciSe/src/main/resources/templates/register.html
+1
-1
No files found.
SkuciSe/src/main/java/com/example/SkuciSe/controller/AppController.java
View file @
bef7a9dc
...
@@ -7,10 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -7,10 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
@Controller
@Controller
public
class
AppController
public
class
AppController
...
@@ -43,10 +41,10 @@ public class AppController
...
@@ -43,10 +41,10 @@ public class AppController
}
}
@PostMapping
(
"/register-proccess"
)
@PostMapping
(
"/register-proccess"
)
public
String
postRegisterProccess
(
@ModelAttribute
Korisnik
korisnik
)
public
String
postRegisterProccess
(
@ModelAttribute
Korisnik
korisnik
,
@RequestParam
(
"image"
)
MultipartFile
multipartFile
)
{
{
System
.
out
.
println
(
korisnik
);
System
.
out
.
println
(
korisnik
);
kRepo
.
insert
(
korisnik
);
kRepo
.
insert
(
korisnik
,
multipartFile
);
return
(
"redirect:/login"
);
return
(
"redirect:/login"
);
}
}
...
...
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/Korisnik.java
View file @
bef7a9dc
...
@@ -18,15 +18,7 @@ public class Korisnik
...
@@ -18,15 +18,7 @@ public class Korisnik
String
sifra
;
String
sifra
;
String
telefon
;
String
telefon
;
int
tipId
;
int
tipId
;
String
slika
;
public
Korisnik
(
String
ime
,
String
prezime
,
String
email
,
String
sifra
,
String
telefon
,
int
tipId
)
{
this
.
ime
=
ime
;
this
.
prezime
=
prezime
;
this
.
email
=
email
;
this
.
sifra
=
sifra
;
this
.
telefon
=
telefon
;
this
.
tipId
=
tipId
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
...
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
View file @
bef7a9dc
package
com
.
example
.
SkuciSe
.
repository
;
package
com
.
example
.
SkuciSe
.
repository
;
import
com.example.SkuciSe.model.korisnik.Korisnik
;
import
com.example.SkuciSe.model.korisnik.Korisnik
;
import
com.example.SkuciSe.util.FileUploadUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Component
;
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.sql.*
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -23,9 +27,17 @@ public class KorisnikRepository
...
@@ -23,9 +27,17 @@ public class KorisnikRepository
}
}
}
}
public
void
insert
(
Korisnik
korisnik
)
public
void
insert
(
Korisnik
korisnik
,
MultipartFile
multipartFile
)
{
{
String
sql
=
"insert into korisnik( ime, prezime, telefon, email, sifra, tipId) values('"
+
korisnik
.
getIme
()+
"','"
+
korisnik
.
getPrezime
()+
"','"
+
korisnik
.
getTelefon
()+
"','"
+
korisnik
.
getEmail
()+
"','"
+
new
BCryptPasswordEncoder
().
encode
(
korisnik
.
getSifra
())+
"',1)"
;
String
fileName
=
StringUtils
.
cleanPath
(
multipartFile
.
getOriginalFilename
());
String
uploadDir
=
"user-photos"
;
try
{
FileUploadUtil
.
saveFile
(
uploadDir
,
fileName
,
multipartFile
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
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, '"
+
fileName
+
"')"
;
System
.
out
.
println
(
sql
);
try
{
try
{
statement
.
executeUpdate
(
sql
);
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
...
@@ -41,7 +53,7 @@ public class KorisnikRepository
...
@@ -41,7 +53,7 @@ public class KorisnikRepository
rs
=
statement
.
executeQuery
(
sql
);
rs
=
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
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
.
getInt
(
"tipid"
)));
return
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
getInt
(
"tipid"
)
,
rs
.
getString
(
"slika"
)
));
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
@@ -55,7 +67,7 @@ public class KorisnikRepository
...
@@ -55,7 +67,7 @@ public class KorisnikRepository
rs
=
statement
.
executeQuery
(
sql
);
rs
=
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
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
.
getInt
(
"tipid"
)));
return
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
getInt
(
"tipid"
)
,
rs
.
getString
(
"slika"
)
));
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
SkuciSe/src/main/resources/templates/register.html
View file @
bef7a9dc
...
@@ -80,7 +80,7 @@
...
@@ -80,7 +80,7 @@
</div>
</div>
<div
class=
"col-md-12 mt-2"
style=
"color:white;"
>
<div
class=
"col-md-12 mt-2"
style=
"color:white;"
>
<input
type=
"file"
name=
"
slika
"
accept=
"image/png, image/jpeg"
/>
<input
type=
"file"
name=
"
image
"
accept=
"image/png, image/jpeg"
/>
<div
class=
"invalid-feedback"
>
Unesite sliku!
</div>
<div
class=
"invalid-feedback"
>
Unesite sliku!
</div>
</div>
</div>
...
...
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