Skip to content
Snippets Groups Projects
Commit 6f8abd83 authored by Thomas's avatar Thomas
Browse files

Added basic JWT auth

parent e94572fd
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,13 @@ public class User implements Serializable{
@Size(min = 1, max = 30)
private String username;
@Basic
@Column(nullable = false)
@NotNull
@Size(min = 1, max = 60)
//@Pattern(regexp="(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*-_=+])[a-zA-Z0-9!@#$%^&*-_=+](?=\\S+$).{8,35}")
private String password;
@Basic
@Column(nullable = false, unique = true)
@NotNull
......@@ -45,9 +52,7 @@ public class User implements Serializable{
@Basic
@Column(nullable = false)
@NotNull
@Size(min = 1, max = 60)
//@Pattern(regexp="(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*-_=+])[a-zA-Z0-9!@#$%^&*-_=+](?=\\S+$).{8,35}")
private String password;
private String role;
@Basic
@OneToMany(mappedBy = "author", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
......@@ -57,15 +62,15 @@ public class User implements Serializable{
public User() {
}
public User(Long id, String username, String email, String password, Set<Model> models) {
public User(Long id, String username, String email, String password, String role, Set<Model> models) {
this.id = id;
this.username = username;
this.email = email;
this.password = password;
this.role = role;
this.models = models;
}
public Long getId() {
return this.id;
}
......@@ -82,14 +87,6 @@ public class User implements Serializable{
this.username = username;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@JsonIgnore
public String getPassword() {
return this.password;
......@@ -99,6 +96,14 @@ public class User implements Serializable{
this.password = password;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@JsonIgnore
public Set<Model> getModels() {
return this.models;
......@@ -108,4 +113,14 @@ public class User implements Serializable{
this.models = models;
}
@JsonIgnore
public String getRole() {
return this.role;
}
public void setRole(String role) {
this.role = role;
}
}
\ No newline at end of file
package mozen.business;
package mozen.utils;
import java.util.HashSet;
import java.util.Set;
......@@ -9,9 +9,12 @@ import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import mozen.business.IModelDao;
import mozen.business.IUserDao;
import mozen.model.CustomLayer;
import mozen.model.Model;
import mozen.model.Tag;
import mozen.model.TagCategory;
import mozen.model.User;
@Service
......@@ -34,11 +37,13 @@ public class DatabaseFiller {
u1.setEmail("user1@email.com");
u1.setPassword("1234");
u1.setUsername("user 1");
u1.setRole("DEFAULT");
User u2 = new User();
u2.setEmail("user2@email.com");
u2.setPassword("1234");
u2.setUsername("user 2");
u2.setRole("ADMIN");
Model m1 = new Model();
m1.setAuthor(u1);
......@@ -46,14 +51,20 @@ public class DatabaseFiller {
m1.setShortDescription("short description 1");
m1.setLongDescription("# README \n model 1");
m1.setVotes(0);
m1.setAdded("1990-05-30");
m1.setLastModified("2010-10-24");
Set<Tag> m1tags = new HashSet<Tag>();
Tag t1 = new Tag();
t1.setCategory("Layers");
TagCategory ca1 = new TagCategory();
ca1.setName("Layer");
t1.setCategory(ca1);
t1.setName("Conv2D");
Tag t2 = new Tag();
t2.setCategory("Architecture");
TagCategory ca2 = new TagCategory();
ca2.setName("Architecture");
t2.setCategory(ca2);
t2.setName("VGG19");
m1tags.add(t1);
......
......@@ -14,7 +14,7 @@ import mozen.business.IModelManager;
import mozen.business.IUserManager;
import mozen.model.Model;
import mozen.model.ResponseMessage;
import mozen.model.Tag;
import mozen.model.TagCategory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/v1/models")
@RequestMapping("/models")
@CrossOrigin
public class ModelController {
@Autowired
......@@ -64,7 +64,7 @@ public class ModelController {
}
@GetMapping("/tags")
public Collection<Tag> getTags() {
public Collection<TagCategory> getTags() {
return modelManager.getTags();
}
}
\ No newline at end of file
......@@ -10,17 +10,17 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import mozen.business.IModelManager;
import mozen.model.Model;
import mozen.model.SearchResult;
@RestController
@RequestMapping("/v1/search")
@RequestMapping("/search")
@CrossOrigin
public class SearchController {
@Autowired
IModelManager modelManager;
@GetMapping("")
public Collection<Model> search(
public SearchResult search(
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "tag", required = false) Collection<String> tag,
@RequestParam(value = "param", required = false) Integer param,
......@@ -29,6 +29,10 @@ public class SearchController {
@RequestParam(value = "sort", required = false) String sort
)
{
return modelManager.findModel(name);
SearchResult result = new SearchResult();
result.setModels(modelManager.findModel(name));
result.setTotal(result.getModels().size());
result.setPage(page);
return result;
}
}
\ No newline at end of file
......@@ -13,12 +13,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import mozen.business.IUserManager;
import mozen.model.LoginMessage;
import mozen.model.ResponseMessage;
import mozen.model.SignupMessage;
import mozen.model.User;
@RestController
@RequestMapping("/v1/user")
@RequestMapping("/user")
@CrossOrigin
public class UserController {
@Autowired
......@@ -29,21 +29,12 @@ public class UserController {
return new User();
}
@PostMapping("")
public ResponseEntity<ResponseMessage> addUser(@RequestBody @Valid User user, BindingResult result) {
manager.addUser(user);
@PostMapping("/signup")
public ResponseEntity<ResponseMessage> addUser(@RequestBody @Valid SignupMessage message, BindingResult result) {
System.err.println("SIGNUP u:"+message.getUsername()+" e:"+message.getEmail()+" p:"+message.getPassword());
manager.addUser(message);
ResponseMessage response = new ResponseMessage(false, "");
return ResponseEntity.ok(response);
}
@PostMapping("/auth")
public ResponseEntity<ResponseMessage> authUser(@RequestBody LoginMessage message) {
ResponseMessage response = new ResponseMessage(false, "");
String token = manager.logUser(message.getEmail(), message.getPassword());
if(token == null) response.setError(true);
else response.setMessage(token);
return ResponseEntity.ok(response);
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ import mozen.business.IUserManager;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/v1/vote")
@RequestMapping("/vote")
@CrossOrigin
public class VoteController {
@Autowired
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment