totp member checkcode method added & Exception added
This commit is contained in:
		
							parent
							
								
									b7954f5a2d
								
							
						
					
					
						commit
						d86857ed83
					
				@ -0,0 +1,16 @@
 | 
			
		||||
package com.loafle.overflow.module.member.exception;
 | 
			
		||||
 | 
			
		||||
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by geek on 18. 3. 15.
 | 
			
		||||
 */
 | 
			
		||||
public class SecretCodeNotExistException extends OverflowRuntimeException {
 | 
			
		||||
    public SecretCodeNotExistException() {
 | 
			
		||||
        super();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SecretCodeNotExistException(String message) {
 | 
			
		||||
        super(message);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,16 @@
 | 
			
		||||
package com.loafle.overflow.module.member.exception;
 | 
			
		||||
 | 
			
		||||
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by geek on 18. 3. 15.
 | 
			
		||||
 */
 | 
			
		||||
public class TotpCodeNotMatchException extends OverflowRuntimeException {
 | 
			
		||||
    public TotpCodeNotMatchException() {
 | 
			
		||||
        super();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TotpCodeNotMatchException(String message) {
 | 
			
		||||
        super(message);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,6 +1,9 @@
 | 
			
		||||
package com.loafle.overflow.module.member.service;
 | 
			
		||||
 | 
			
		||||
import com.loafle.overflow.module.member.dao.MemberTotpDAO;
 | 
			
		||||
import com.loafle.overflow.module.member.exception.SecretCodeNotExistException;
 | 
			
		||||
import com.loafle.overflow.module.member.exception.SignInIdNotExistException;
 | 
			
		||||
import com.loafle.overflow.module.member.exception.TotpCodeNotMatchException;
 | 
			
		||||
import com.loafle.overflow.module.member.model.Member;
 | 
			
		||||
import com.loafle.overflow.module.member.model.MemberTotp;
 | 
			
		||||
import com.warrenstrange.googleauth.GoogleAuthenticator;
 | 
			
		||||
@ -24,11 +27,11 @@ public class MemberTotpService {
 | 
			
		||||
    public void  regist(Member member, String secretCode, String code) throws Exception {
 | 
			
		||||
 | 
			
		||||
        if (null == member || 0 >= member.getId()) {
 | 
			
		||||
            throw new Exception("Not Null Member ID");
 | 
			
		||||
            throw new SignInIdNotExistException("Not Null Member ID");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!this.checkCode(secretCode, code) ) {
 | 
			
		||||
            throw new Exception("Not Equal");
 | 
			
		||||
            throw new TotpCodeNotMatchException("Not Equal");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MemberTotp totp = new MemberTotp();
 | 
			
		||||
@ -38,12 +41,12 @@ public class MemberTotpService {
 | 
			
		||||
        this.totpDAO.save(totp);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MemberTotp modify(MemberTotp totp) throws Exception {
 | 
			
		||||
    public MemberTotp modify(MemberTotp totp) {
 | 
			
		||||
        if ( null == totp.getSecretCode() || totp.getSecretCode().equals("")) {
 | 
			
		||||
            throw new Exception("Not Null SecretCode");
 | 
			
		||||
            throw new SecretCodeNotExistException("No secret code exists");
 | 
			
		||||
        }
 | 
			
		||||
        if (null == totp.getMember() || 0 < totp.getMember().getId()) {
 | 
			
		||||
            throw new Exception("Not Null Member ID");
 | 
			
		||||
            throw new SignInIdNotExistException("There is no member ID in the TOTP table.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return this.totpDAO.save(totp);
 | 
			
		||||
@ -57,20 +60,27 @@ public class MemberTotpService {
 | 
			
		||||
        return this.totpDAO.findOne(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean checkCodeForMember(Member member, String code) throws Exception {
 | 
			
		||||
        MemberTotp totp = this.totpDAO.findByMember(member);
 | 
			
		||||
        if (null == totp && (totp.getSecretCode() == null || totp.getSecretCode().equals("")) ) {
 | 
			
		||||
            throw new SignInIdNotExistException("Error TotpMember");
 | 
			
		||||
        }
 | 
			
		||||
        return this.checkCode(totp.getSecretCode(), code);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean checkCode(String secretCode, String code) throws Exception {
 | 
			
		||||
        GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
 | 
			
		||||
        int codeInt = Integer.parseInt(code);
 | 
			
		||||
        boolean isCheck = googleAuthenticator.authorize(secretCode, codeInt);
 | 
			
		||||
 | 
			
		||||
        if (!isCheck) {
 | 
			
		||||
            throw new Exception("Invalid Code");
 | 
			
		||||
            throw new TotpCodeNotMatchException("Invalid Code");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return isCheck;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Map<String, String> createTotp(Member member) {
 | 
			
		||||
//        MemberTotp totp = new MemberTotp();
 | 
			
		||||
        Map<String, String> returnMap = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
 | 
			
		||||
@ -84,10 +94,6 @@ public class MemberTotpService {
 | 
			
		||||
                .setPath("/" + formatLabel("overFlow", member.getEmail()))
 | 
			
		||||
                .setParameter("secret", key.getKey());
 | 
			
		||||
 | 
			
		||||
//        totp.setMember(member);
 | 
			
		||||
//        totp.setSecretCode(secret);
 | 
			
		||||
//        totp.setOtpAuth(uri.toString());
 | 
			
		||||
 | 
			
		||||
        returnMap.put("key", secret);
 | 
			
		||||
        returnMap.put("uri", uri.toString());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user