Skip to content

Commit

Permalink
Bad credentials response & localization
Browse files Browse the repository at this point in the history
  • Loading branch information
icreated committed Jun 23, 2021
1 parent 7d19116 commit c040497
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/co/icreated/portal/controller/CommonController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public class CommonController {
CommonService commonService;


@GetMapping("/reference/docstatus/{value}")
public String getReferenceDocStatus(@PathVariable String value) {
@GetMapping("/reference/docstatus/{language}/{value}")
public String getReferenceDocStatus(@PathVariable String language, @PathVariable String value) {
// AD_Reference_ID = 131 _DocStatus
return commonService.getReferenceValue(131, value);
return commonService.getReferenceValue(language, 131, value);
}

@GetMapping("/reference/tendertype/{value}")
public String getReferenceTenderType(@PathVariable String value) {
@GetMapping("/reference/tendertype/{language}/{value}")
public String getReferenceTenderType(@PathVariable String language, @PathVariable String value) {
// AD_Reference_ID = 214 C_Payment TenderType
return commonService.getReferenceValue(214, value);
return commonService.getReferenceValue(language, 214, value);
}

@GetMapping("/reference/creditcardtypes")
public List<ValueLabelBean> getReferenceCreditCard() {
// AD_Reference_ID = 149 CreditCardType
return commonService.getValueLabelList(149);
return commonService.getValueLabelList("en_US", 149);
}

}
14 changes: 8 additions & 6 deletions src/co/icreated/portal/service/CommonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public class CommonService {
JdbcTemplate jdbcTemplate;


public String getReferenceValue(int AD_Reference_ID, String value) {
public String getReferenceValue(String AD_Language, int AD_Reference_ID, String value) {

return MRefList.getListName(ctx, AD_Reference_ID, value);
return MRefList.getListName(AD_Language, AD_Reference_ID, value);
}


public List<ValueLabelBean> getValueLabelList(int AD_Reference_ID) {
public List<ValueLabelBean> getValueLabelList(String AD_Language, int AD_Reference_ID) {

String sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID = ? AND isActive='Y'";
String sql = "SELECT Value, COALESCE(trl.Name, l.Name) FROM AD_Ref_List l "
+ "LEFT JOIN AD_Ref_List_Trl trl ON l.AD_Ref_List_ID=trl.AD_Ref_List_ID AND trl.AD_Language = ? "
+ "WHERE l.AD_Reference_ID = ? AND l.isActive='Y'";
return jdbcTemplate.query(sql,
new Object[]{AD_Reference_ID},
new Object[]{AD_Language, AD_Reference_ID},
(rs, rowNum) ->
new ValueLabelBean(rs.getString("Name"), rs.getString("Value"))
new ValueLabelBean(rs.getString(2), rs.getString(1))
);
}
}
20 changes: 12 additions & 8 deletions src/co/icreated/portal/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.compiere.util.CLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand Down Expand Up @@ -40,15 +41,18 @@ public SessionUser findSessionUserByValue(String value) {
"INNER JOIN C_BPartner bp ON bp.C_BPartner_ID = u.C_BPartner_ID " +
"WHERE u.Value LIKE ?";



SessionUser sessionUser = jdbcTemplate.queryForObject(sql,
new Object[]{value},
(rs, rowNum) ->
new SessionUser(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4),
rs.getString(5), rs.getString(6), rs.getInt(7), rs.getString(8).equals("N"),
rs.getString(9).equals("N"), true, rs.getString(10).equals("Y") && rs.getString(11).equals("Y"))
);
SessionUser sessionUser = null;
try {
sessionUser = jdbcTemplate.queryForObject(sql,
new Object[]{value},
(rs, rowNum) ->
new SessionUser(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4),
rs.getString(5), rs.getString(6), rs.getInt(7), rs.getString(8).equals("N"),
rs.getString(9).equals("N"), true, rs.getString(10).equals("Y") && rs.getString(11).equals("Y"))
);
} catch (EmptyResultDataAccessException e) {}


List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Expand Down

0 comments on commit c040497

Please sign in to comment.