Skip to content

Commit

Permalink
fix: misc updates and fixes #284
Browse files Browse the repository at this point in the history
Signed-off-by: jgomer2001 <[email protected]>
  • Loading branch information
jgomer2001 committed Jul 15, 2024
1 parent ba409ef commit d04143a
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 766 deletions.
8 changes: 0 additions & 8 deletions plugins/email_2fa_core/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions plugins/email_2fa_core/extras/README.md

This file was deleted.

770 changes: 262 additions & 508 deletions plugins/email_2fa_core/extras/email_2fa_core.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugins/email_2fa_core/extras/otp_email.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h:messages class="list dark-red tc pv2 ph0 ma0 f5" />

<div class="flex justify-center pa3">
<img src="#{request.contextPath}/img/email-ver.png" />
<i class="fas fa-envelope f1" />
</div>

<h:form id="OtpEmailLoginForm" class="pt2">
Expand All @@ -37,7 +37,7 @@
<ui:include src="/casa/casa.xhtml" />
<script>
//This is needed since JSF does not allow to set required attribute
$(".focused-text").attr("required", "true")
$(".focused-text").attr("required", "true")
</script>
</ui:define>

Expand Down
18 changes: 6 additions & 12 deletions plugins/email_2fa_core/extras/otp_email_prompt.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<h:messages class="list dark-red tc pv2 ph0 ma0 f5" />

<div class="flex flex-column justify-center items-center pa3">
<img src="#{request.contextPath}/img/email-ver.png" />
<span class="db w5 tc f7-cust pt2">#{msgs['casa.email.choose']}</span>
<i class="fas fa-envelope f1" />
<span class="db w5 tc f7-cust pt3">#{msgs['casa.email.choose']}</span>
</div>

<h:form id="OtpEmailLoginForm" class="pt2">
Expand All @@ -32,33 +32,27 @@
<h:commandButton class="f7-cust bw0 br1 ph4 pv2 bg-bsgreen-success white hover-bsgreen-success hover-white btn cust-primary-button"
value="#{msgs['casa.email.send']}" action="#{authenticator.authenticate}" />
</div>
<h:inputHidden id="indexOfEmail" value="0" />
</h:form>
</section>
<ui:include src="/casa/casa.xhtml" />

<script>
var numbs = "${identity.getWorkingParameter('emailIds')}"
numbs = numbs.split(",")
var numbs = "${identity.getWorkingParameter('emails')}"
numbs = numbs.split(", ")

for (let i=0; i &lt; numbs.length; i++) {
let checked = (i == 0) ? " checked" : ""
//very ugly... yes
var line = '&lt;li class="list-group-item hover-bg-light-gray gray hover-dark-gray pv1"> '
line = line + '&lt;label> '
line = line + '&lt;input type="radio" id="optionEmail" name="optionEmail" class="mr1" onchange="changeOption(' + i + ')"' + checked + '/> '
line = line + '&lt;input type="radio" name="sendTo" class="mr1" value="' + numbs[i] + '"' + checked + '/> '
line = line + '&lt;span class="mb1">'+ numbs[i] + '&lt;/span> '
line = line + '&lt;/label> '
line = line + '&lt;/li> '

var option = $(line)
$('#emails').append(option)
}

function changeOption(index) {
document.getElementById("OtpEmailLoginForm:indexOfEmail").value = index;
}

}

</script>

Expand Down
8 changes: 8 additions & 0 deletions plugins/email_2fa_core/extras/oxauth.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#casa plugin - email otp
casa.email.enter=Enter the code sent via e-mail
casa.email.choose=Choose an e-mail to send an OTP to
casa.email.send=Continue

#used by casa.xhtml selector page
casa.email_2fa.title= Email OTP
casa.email_2fa.text=Authenticate using a one-time password sent to your registered email address
2 changes: 1 addition & 1 deletion plugins/email_2fa_core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<Plugin-Provider>Gluu Inc.</Plugin-Provider>
<Plugin-Class>org.gluu.casa.plugins.emailotp.EmailOtpPlugin</Plugin-Class>
<Plugin-Description>
A plugin to enroll Email as a 2FA Credential for EmailOTP 2FA.
A plugin to enroll e-mail as a 2FA Credential.
</Plugin-Description>
<Plugin-License>Visit https://gluu.org/docs/casa/#license</Plugin-License>
<Logger-Name>org.gluu.casa.plugins</Logger-Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.gluu.casa.extension.AuthnMethod;
import org.gluu.casa.misc.Utils;
import org.gluu.casa.plugins.emailotp.EmailOTPService;
import org.gluu.casa.service.ISessionContext;
import org.pf4j.Extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,23 +18,15 @@ public class EmailOtpAuthnMethod implements AuthnMethod {

private static Logger logger = LoggerFactory.getLogger(EmailOtpAuthnMethod.class);

private ISessionContext sessionContext;

public EmailOtpAuthnMethod() {
sessionContext = Utils.managedBean(ISessionContext.class);
reloadConfiguration();
}

@Override
public String getPanelBottomTextKey() {
return "";
}

@Override
public boolean mayBe2faActivationRequisite() {
return Boolean.parseBoolean(Optional
.ofNullable(EmailOTPService.getInstance().getScriptPropertyValue("2fa_requisite")).orElse("false"));

return Boolean.parseBoolean(Optional.ofNullable(
EmailOTPService.getInstance().getScriptPropertyValue("2fa_requisite")).orElse("false"));
}

@Override
Expand All @@ -44,9 +35,9 @@ public String getAcr() {
}

@Override
public List<BasicCredential> getEnrolledCreds(String arg0) {
public List<BasicCredential> getEnrolledCreds(String id) {
try {
return EmailOTPService.getInstance().getCredentials(sessionContext.getLoggedUser().getId())
return EmailOTPService.getInstance().getCredentials(id)
.stream().map(dev -> new BasicCredential(dev.getNickName(), 0)).collect(Collectors.toList());
} catch (Exception e) {
logger.error(e.getMessage(), e);
Expand All @@ -71,17 +62,17 @@ public String getPanelTextKey() {

@Override
public String getPanelTitleKey() {
return "email.title";
return "usr.email_title";
}

@Override
public int getTotalUserCreds(String arg0) {
return EmailOTPService.getInstance().getCredentialsTotal( sessionContext.getLoggedUser().getId());
public int getTotalUserCreds(String id) {
return EmailOTPService.getInstance().getCredentialsTotal(id);
}

@Override
public String getUINameKey() {
return "email.title";
return "usr.email_label";
}

@Override
Expand Down
Loading

0 comments on commit d04143a

Please sign in to comment.