diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java index 1b00777..2497990 100644 --- a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java @@ -132,6 +132,7 @@ public class EmailAuthService { return this.emailAuthDAO.save(emailAuth); } + // Todo Send Email Refactoring public EmailAuth sendEmailResetPassword(Member member) throws UnsupportedEncodingException, MailException { EmailAuth auth = new EmailAuth(); auth.setMember(member); diff --git a/src/main/java/com/loafle/overflow/module/member/model/MemberTotp.java b/src/main/java/com/loafle/overflow/module/member/model/MemberTotp.java index 4ae1295..9593081 100644 --- a/src/main/java/com/loafle/overflow/module/member/model/MemberTotp.java +++ b/src/main/java/com/loafle/overflow/module/member/model/MemberTotp.java @@ -16,7 +16,7 @@ public class MemberTotp { private String secretCode; private Date createDate; private Date updateDate; - private String otpAuthURL; + private String otpAuth; public MemberTotp() { } @@ -76,11 +76,11 @@ public class MemberTotp { } @Transient - public String getOtpAuthURL() { - return otpAuthURL; + public String getOtpAuth() { + return otpAuth; } - public void setOtpAuthURL(String otpAuthURL) { - this.otpAuthURL = otpAuthURL; + public void setOtpAuth(String otpAuthURL) { + this.otpAuth = otpAuthURL; } } diff --git a/src/main/java/com/loafle/overflow/module/member/service/MemberTotpService.java b/src/main/java/com/loafle/overflow/module/member/service/MemberTotpService.java index 3693f63..635700b 100644 --- a/src/main/java/com/loafle/overflow/module/member/service/MemberTotpService.java +++ b/src/main/java/com/loafle/overflow/module/member/service/MemberTotpService.java @@ -6,6 +6,7 @@ import com.loafle.overflow.module.member.model.MemberTotp; import com.warrenstrange.googleauth.GoogleAuthenticator; import com.warrenstrange.googleauth.GoogleAuthenticatorKey; import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator; +import org.apache.http.client.utils.URIBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -66,12 +67,35 @@ public class MemberTotpService { String secret = key.getKey(); // List scratchCodes = key.getScratchCodes(); - String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", member.getEmail(), key); +// String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", member.getEmail(), key); + URIBuilder uri = (new URIBuilder()).setScheme("otpauth") + .setHost("totp") + .setPath("/" + formatLabel("overFlow", member.getEmail())) + .setParameter("secret", key.getKey()); totp.setMember(member); totp.setSecretCode(secret); - totp.setOtpAuthURL(otpAuthURL); + totp.setOtpAuth(uri.toString()); return totp; } + + private String formatLabel(String issuer, String accountName) { + if(accountName != null && accountName.trim().length() != 0) { + StringBuilder sb = new StringBuilder(); + if(issuer != null) { + if(issuer.contains(":")) { + throw new IllegalArgumentException("Issuer cannot contain the ':' character."); + } + + sb.append(issuer); + sb.append(":"); + } + + sb.append(accountName); + return sb.toString(); + } else { + throw new IllegalArgumentException("Account name must not be empty."); + } + } } diff --git a/src/test/java/com/loafle/overflow/module/member/service/MemberTotpServiceTest.java b/src/test/java/com/loafle/overflow/module/member/service/MemberTotpServiceTest.java index 7e5c7c1..0a2c094 100644 --- a/src/test/java/com/loafle/overflow/module/member/service/MemberTotpServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/member/service/MemberTotpServiceTest.java @@ -60,7 +60,7 @@ public class MemberTotpServiceTest { MemberTotp totp = this.totpService.createTotp(m); System.out.println(totp.getSecretCode()); - System.out.println(totp.getOtpAuthURL()); + System.out.println(totp.getOtpAuth()); } } \ No newline at end of file