Commit c799f62f by Bogdan Andjelkovic

dodat grad za korisnika

parent 605dc3c8
......@@ -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");
}
......
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
......@@ -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
......@@ -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)
{
......
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.getInt("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.getString("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.getInt("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.getString("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");
......
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;
}
......@@ -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>
......
......@@ -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>
......
Markdown is supported
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