Compare commits
4 Commits
fcfeaf0979
...
merge
| Author | SHA1 | Date | |
|---|---|---|---|
| 095dd861c5 | |||
| 5cdab5b434 | |||
| 43c967638b | |||
| 24794e2085 |
@@ -2,9 +2,6 @@ package com.vpr.server.controller;
|
||||
|
||||
import com.vpr.server.data.User;
|
||||
import com.vpr.server.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
public class AuthController {
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.vpr.server.controller;
|
||||
|
||||
import com.vpr.server.dao.interfaces.EventDAO;
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import com.vpr.server.data.UserEvent;
|
||||
import com.vpr.server.dao.interfaces.EventDAO;
|
||||
import com.vpr.server.json.JSONMapper;
|
||||
import com.vpr.server.json.Validator;
|
||||
import com.vpr.server.repository.EventRepository;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.vpr.server.controller;
|
||||
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import com.vpr.server.data.UserEvent;
|
||||
import com.vpr.server.repository.EventRepository;
|
||||
import com.vpr.server.repository.UserEventRepository;
|
||||
import com.vpr.server.repository.UserRepository;
|
||||
@@ -10,25 +7,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@Controller // This means that this class is a Controller
|
||||
@RequestMapping(path = "/vpr") // This means URL's start with /demo (after Application path)
|
||||
public class MainController {
|
||||
|
||||
// This means to get the bean called userRepository
|
||||
// Which is auto-generated by Spring, we will use it to handle the data
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@Autowired
|
||||
private EventRepository eventRepository;
|
||||
@Autowired
|
||||
private UserEventRepository userEventRepository;
|
||||
|
||||
@GetMapping(path = "/status-test")
|
||||
public String statusTest(){
|
||||
throw new ResponseStatusException(HttpStatus.I_AM_A_TEAPOT, "TestTestTest");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.vpr.server.controller;
|
||||
|
||||
import com.vpr.server.dao.interfaces.UserDAO;
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import com.vpr.server.json.JSONMapper;
|
||||
import com.vpr.server.repository.UserRepository;
|
||||
@@ -84,6 +83,27 @@ public class UserController {
|
||||
@RequestParam String login,
|
||||
@RequestParam String password
|
||||
) {
|
||||
if(userRepository.findAllUsernames().length == 0){
|
||||
byte[] salt = Hasher.GenerateSalt();
|
||||
byte[] hash;
|
||||
try {
|
||||
hash = Hasher.HashPassword(password, salt);
|
||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>("Fehler beim hashen", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
User user = new User();
|
||||
user.setName("Admin");
|
||||
user.setForename(login);
|
||||
user.setLogin(login);
|
||||
user.setPassword(hash);
|
||||
user.setSalt(salt);
|
||||
user.setToken("");
|
||||
user.setAdmin(true);
|
||||
|
||||
userRepository.save(user);
|
||||
}
|
||||
System.out.println(login + " tries to login.");
|
||||
User user = userRepository.findByLogin(login);
|
||||
if (user == null) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.vpr.server.dao.implementation;
|
||||
|
||||
import com.vpr.server.dao.interfaces.UserDAO;
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.vpr.server.data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Date;
|
||||
import java.util.Calendar;
|
||||
|
||||
// @Entity creates a table out of this class with Hibernate
|
||||
// @Table defines the table-name
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.vpr.server.data.User;
|
||||
import com.vpr.server.data.UserEvent;
|
||||
|
||||
import java.sql.Time;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.vpr.server.json;
|
||||
|
||||
import com.vpr.server.data.UserEvent;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Time;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
package com.vpr.server.repository;
|
||||
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.UserEvent;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import javax.persistence.ColumnResult;
|
||||
import javax.persistence.ConstructorResult;
|
||||
import javax.persistence.NamedNativeQuery;
|
||||
import javax.persistence.SqlResultSetMapping;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
// This will be AUTO IMPLEMENTED by Spring into a Bean called eventRepository
|
||||
// CRUD refers Create, Read, Update, Delete
|
||||
|
||||
@@ -4,11 +4,12 @@ import io.jsonwebtoken.JwtException;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
|
||||
import java.security.Key;
|
||||
|
||||
public class Token {
|
||||
|
||||
private static Key KEY = Keys.secretKeyFor(SignatureAlgorithm.HS256);
|
||||
private static final Key KEY = Keys.secretKeyFor(SignatureAlgorithm.HS256);
|
||||
|
||||
public static String Generate(String subject){
|
||||
return Jwts.builder().setSubject(subject).signWith(KEY).compact();
|
||||
|
||||
Reference in New Issue
Block a user