-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5cb0ce
commit 6ffe0df
Showing
1,574 changed files
with
286 additions
and
114 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
src/main/java/br/unicap/cardgame/controller/CharController.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/main/java/br/unicap/cardgame/controller/CharsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package br.unicap.cardgame.controller; | ||
|
||
import br.unicap.cardgame.dao.CharsDAO; | ||
import br.unicap.cardgame.model.Chars; | ||
import javax.ejb.EJB; | ||
import javax.ejb.Stateless; | ||
|
||
|
||
@Stateless | ||
public class CharsController { | ||
|
||
@EJB | ||
private CharsDAO charDAO; | ||
|
||
public Chars getPlayerChar(String username) { | ||
return charDAO.getPlayerChar(username); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
src/main/java/br/unicap/cardgame/controller/UserController.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/main/java/br/unicap/cardgame/controller/UsersController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package br.unicap.cardgame.controller; | ||
|
||
import br.unicap.cardgame.dao.UsersDAO; | ||
import br.unicap.cardgame.model.Player; | ||
import br.unicap.cardgame.model.Users; | ||
import br.unicap.cardgame.util.Utils; | ||
import br.unicap.cardgame.ws.response.CardGameResponse; | ||
import javax.ejb.Stateless; | ||
import br.unicap.cardgame.ws.response.CardGameResponseToken; | ||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.SignatureAlgorithm; | ||
import javax.ejb.EJB; | ||
|
||
@Stateless | ||
public class UsersController { | ||
|
||
@EJB | ||
private UsersDAO usersDAO; | ||
|
||
public CardGameResponseToken authenticate(String username, String password) throws Exception { | ||
|
||
Users u = usersDAO.getUserByUsername(username); | ||
|
||
if(u == null || !verifyPassword(u, password)) { | ||
throw new Exception("password invalido"); | ||
} | ||
Player p = new Player(u.getId(), u.getUsername()); | ||
String token = Jwts.builder() | ||
.setSubject(p.toString()) | ||
.signWith(SignatureAlgorithm.HS512, Utils.APP_CLIENT_SECRET) | ||
.compact(); | ||
|
||
return new CardGameResponseToken(true, token); | ||
} | ||
|
||
private boolean verifyPassword(Users user, String password) { | ||
return user.getPassword().equals(password); | ||
} | ||
|
||
public Users getUserByUsername(String username) { | ||
return usersDAO.getUserByUsername(username); | ||
} | ||
|
||
public CardGameResponse changeUserChar(int user_id, int char_id) { | ||
boolean update = usersDAO.changeUserChar(user_id, char_id); | ||
if(update) { | ||
return new CardGameResponse(true, 2000, "Char alterado com sucesso"); | ||
} | ||
return new CardGameResponse(true, 2000, "Falha ao alterar char!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package br.unicap.cardgame.dao; | ||
|
||
import br.unicap.cardgame.model.Chars; | ||
import br.unicap.cardgame.model.Users; | ||
import javax.ejb.Stateless; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
@Stateless | ||
public class CharsDAO { | ||
|
||
@PersistenceContext(unitName = "cardgame") | ||
private EntityManager em; | ||
|
||
public Chars getPlayerChar(String username) { | ||
Users u = em.createNamedQuery("Users.findByUsername", Users.class) | ||
.setParameter("username", username) | ||
.getSingleResult(); | ||
Chars c = em.createNamedQuery("Chars.findById", Chars.class) | ||
.setParameter("id", u.getCharId().getId()) | ||
.getSingleResult(); | ||
return c; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package br.unicap.cardgame.dao; | ||
|
||
import br.unicap.cardgame.model.Cards; | ||
import br.unicap.cardgame.model.Users; | ||
import java.util.List; | ||
import javax.ejb.Stateless; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
@Stateless | ||
public class DecksDAO { | ||
|
||
@PersistenceContext(unitName = "cardgame") | ||
private EntityManager em; | ||
|
||
public List<Cards> getUserCards(Users u) { | ||
return em.createNativeQuery("select ca.id, ca.question_id, ca.attack, ca.defense, ca.life from users u, chars c, decks d, decks_cards dc, cards ca where \n" + | ||
"u.id = " + u.getId() + " and \n" + | ||
"u.char_id = c.id and \n" + | ||
"c.deck_id = d.id and \n" + | ||
"d.id = dc.deck_id and\n" + | ||
"dc.card_id = ca.id;", Cards.class).getResultList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package br.unicap.cardgame.dao; | ||
|
||
import br.unicap.cardgame.model.Users; | ||
import javax.ejb.Stateless; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import javax.persistence.Query; | ||
|
||
@Stateless | ||
public class UsersDAO { | ||
|
||
@PersistenceContext(unitName = "cardgame") | ||
private EntityManager em; | ||
|
||
public Users getUserByUsername(String username) { | ||
return em.createNamedQuery("Users.findByUsername", Users.class) | ||
.setParameter("username", username) | ||
.getSingleResult(); | ||
} | ||
|
||
public Boolean changeUserChar(int user_id, int char_id) { | ||
boolean status = false; | ||
try { | ||
String hql = "UPDATE Users SET charId.id = :char_id " + | ||
"WHERE id = :user_id"; | ||
Query query = em.createQuery(hql); | ||
query.setParameter("char_id", char_id) | ||
.setParameter("user_id", user_id); | ||
status = query.executeUpdate() > 0; | ||
} catch(Exception e) { | ||
System.err.println(e); | ||
} | ||
return status; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.