Skip to content

Commit

Permalink
Merge branch 'rama-de-union' of https://github.com/CodeURJC-DAW-2019-…
Browse files Browse the repository at this point in the history
…20/webapp9 into rama-de-union
  • Loading branch information
Avadem committed Feb 23, 2020
2 parents e938f38 + f350fef commit d2fd940
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 39 deletions.
91 changes: 57 additions & 34 deletions practica/src/main/java/com/practica/demo/WebController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

import com.practica.demo.data.Team;
import com.practica.demo.data.Tournament;
import com.practica.demo.data.player.Player;
import com.practica.demo.data.player.PlayerRepository;
import com.practica.demo.data.user.User;
import com.practica.demo.data.user.UserComponent;

Expand All @@ -53,6 +55,9 @@ public WebController() {

@Autowired
private RespositoryUser userRepository;

@Autowired
private PlayerRepository playerRepository;

@Autowired
private TeamRepository repositoryTeam;
Expand Down Expand Up @@ -98,29 +103,14 @@ public String goLeaderBoard(Model model) {
return "leaderBoard";
}

@GetMapping("/profile")
public String goProfile(Model model, @RequestParam(required = false) int id) {

Optional<User> usuario = userRepository.findById(id);

if(userComponent.getLoggedUser().getIduser()==usuario.get().getIduser()) {
model.addAttribute("myprofile", true);
}
model.addAttribute("user",usuario.get());


return "profile";
}

@RequestMapping("/teamCreation")
public String goTeamCreation(Model model) {
return "teamCreation";
}

@RequestMapping("/signIn")
public String goSigIn(Model model) {
return "signIn";
}


@RequestMapping("/team")
public String goTeam(Model model) {
Expand All @@ -138,23 +128,6 @@ public String goBrackets(Model model) {
}


/**
* Controller for lunching SingIn page
* @param model
* @return singIn.html
*/
@RequestMapping("/singIn")
public String singInPage(Model model) {
//Games games = new Games();
//model.addAttribute("games",games.getArray());
if(userComponent.isLoggedUser()) {
return index(model);
}

return "signIn";
}


@RequestMapping("/errorPage")
public String errorPage(Model model) {
return "error";
Expand All @@ -166,11 +139,61 @@ public String tournaments(Model model, @PathVariable String name) {
return "diamond";
}


/*
* USER PROFILE CONTROLLER
*
*/
@GetMapping("/profile")
public String goProfile(Model model, @RequestParam(required = false) int id) {

Optional<User> usuario = userRepository.findById(id);

if(userComponent.getLoggedUser().getIduser()==usuario.get().getIduser()) {
model.addAttribute("myprofile", true);
}
model.addAttribute("user",usuario.get());

Player player = playerRepository.findByuser(usuario.get());

model.addAttribute("player",player);



return "profile";
}

@RequestMapping("/editProfile")
public String tournaments(Model model) {
return "userConfig";
}



/*
* ****************************************************
* USER LOGIN CONTROLLER
*
*/
/**
* Controller for lunching SingIn page
* @param model
* @return singIn.html
*/
@RequestMapping("/login")
public String singInPage(Model model) {
//Games games = new Games();
//model.addAttribute("games",games.getArray());
if(userComponent.isLoggedUser()) {
return index(model);
}

return "userConfig";
return "signIn";
}

@RequestMapping("/signIn")
public String goSigIn(Model model) {
return "signIn";
}


Expand Down
45 changes: 45 additions & 0 deletions practica/src/main/java/com/practica/demo/data/player/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.practica.demo.data.player;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import com.practica.demo.data.user.User;

@Entity
public class Player {

@Id
private int idPlayer;

@OneToOne
private User user;

private String description;

public Player() {
// TODO Auto-generated constructor stub
}

public int getIdPlayer() {
return idPlayer;
}

public void setIdPlayer(int idPlayer) {
this.idPlayer = idPlayer;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}






}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.practica.demo.data.player;

import org.springframework.data.repository.CrudRepository;

import com.practica.demo.data.user.User;


public interface PlayerRepository extends CrudRepository<Player, Integer> {

Player findByuser(User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public void destroy() {

// Private pages (all other pages)
// http.authorizeRequests().antMatchers("/newbook").hasAnyRole("USER"); //a la espera de una pagina decente


http.authorizeRequests().antMatchers("/profile").hasAnyRole("user");
http.authorizeRequests().antMatchers("/profile").hasAnyRole("Admin");

// Login form
http.formLogin().loginPage("/login");
Expand Down
11 changes: 7 additions & 4 deletions practica/src/main/resources/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
<form action="login">
<input type="submit" class="nav-link" value="Sign In">
</form> {{/noloaded}} {{^noloaded}}
<form action="profile">
<input type="submit" class="nav-link" value="Profile">
</form> {{/noloaded}}
<form action="profile" method="get">
<input type="submit" class="nav-link" value="{{user.username}}">
<input type="hidden" name="_csrf" value="{{token}}"/>
<input type="hidden" name="id" value="{{user.iduser}}"/>
</form>
{{/noloaded}}
</li>
<li class="nav-item active">
<form action="leaderBoard">
Expand Down Expand Up @@ -99,7 +102,7 @@
<div class="col-lg-6">
<div class="hero-text">
<h2>{{user.username}}</h2>
<p>I'm a League og Legend player who plays casual games and his favourite champion is Thresh </p>
<p> {{player.description}}</p>
</div>
<div class="hero-info">
<h2>General Info</h2>
Expand Down

0 comments on commit d2fd940

Please sign in to comment.