@Override public String getDocumentAccess(Long nID_Access, String sSecret) throws Exception { Session oSession = getSession(); DocumentAccess docAcc = new DocumentAccess(); List<DocumentAccess> list = findAll(); if (list == null || list.isEmpty()) { throw new Exception("Access not accepted!"); } else { for (DocumentAccess da : list) { if (da.getId() == nID_Access && da.getSecret().equals(sSecret)) { docAcc = da; break; } } } String sTelephone = ""; if (docAcc.getTelephone() != null) { sTelephone = docAcc.getTelephone(); } String sAnswer = SecurityUtils.generateAnswer(); docAcc.setAnswer(sAnswer); String otpPassword = getOtpPassword(docAcc); return otpPassword; }
@Override public DocumentAccess getDocumentLink(Long nID_Access, String sSecret) { Session oSession = getSession(); List<DocumentAccess> list = null; DocumentAccess docAcc = null; try { list = (List<DocumentAccess>) oSession.createCriteria(DocumentAccess.class).list(); for (DocumentAccess da : list) { if (da.getId() == nID_Access && da.getSecret().equals(sSecret)) { docAcc = da; break; } } } catch (Exception e) { throw e; } return docAcc; }
@Override public String sSentDocumentAccessOTP_Phone(String sCode) throws Exception { String sPhoneSent = null; // Session oSession = getSession(); boolean bSent = false; DocumentAccess oDocumentAccess = findBy("sCode", sCode).orNull(); if (oDocumentAccess.getTelephone() != null && oDocumentAccess.getTelephone().trim().length() > 6) { String sPhone = oDocumentAccess.getTelephone(); sPhoneSent = sPhone; log.info("[bSentDocumentAccessOTP]sPhone=" + sPhone); String sAnswer = SecurityUtils.generateAnswer(); log.info("[bSentDocumentAccessOTP]sAnswer=" + sAnswer); // o.setDateAnswerExpire(null); // SEND SMS with this code String sReturn; if (generalConfig.bTest()) { sAnswer = "4444"; } oDocumentAccess.setAnswer(sAnswer); // writeRow(oDocumentAccess); saveOrUpdate(oDocumentAccess); log.info("oDocumentAccess.getId()=" + oDocumentAccess.getId() + ":Ok!"); if (generalConfig.bTest()) { sReturn = "test"; } else { sReturn = sendPasswordOTP(sPhone, sAnswer); } log.info("[bSentDocumentAccessOTP]sReturn=" + sReturn); bSent = true; } else { // TODO loging warn } // return bSent; return sPhoneSent; }
@Override public String setDocumentLink( Long nID_Document, String sFIO, String sTarget, String sTelephone, Long nMS, String sMail) throws Exception { DocumentAccess oDocumentAccess = new DocumentAccess(); oDocumentAccess.setID_Document(nID_Document); oDocumentAccess.setDateCreate(new DateTime()); oDocumentAccess.setMS(nMS); oDocumentAccess.setFIO(sFIO); oDocumentAccess.setMail(sMail); oDocumentAccess.setTarget(sTarget); oDocumentAccess.setTelephone(sTelephone); oDocumentAccess.setSecret(SecurityUtils.generateSecret()); // String id = writeRow(oDocumentAccess).toString(); if (oDocumentAccess.getsCode() == null) oDocumentAccess.setsCode("null"); if (oDocumentAccess.getsCodeType() == null) oDocumentAccess.setsCodeType("null"); saveOrUpdate(oDocumentAccess); String id = oDocumentAccess.getId().toString(); log.info("id=" + id); // sCode;sCodeType oDocumentAccess.setsCode(id); oDocumentAccess.setsCodeType((sTelephone != null && sTelephone.length() > 6) ? "sms" : ""); // writeRow(oDocumentAccess); saveOrUpdate(oDocumentAccess); log.info("id=" + id + ":Ok!"); /*StringBuilder osURL = new StringBuilder(sURL); osURL.append("nID_Access="); osURL.append(getIdAccess()+"&"); osURL.append("sSecret="); osURL.append(oDocumentAccess.getSecret());*/ // return osURL.toString(); if (sMail != null && !"".equals(sMail.trim())) { String saToMail = sMail; String sHead = "Доступ до документу"; String sBody = "Вам надано доступ до документу на Порталі державних послуг iGov.org.ua.<br>" + "<br>" + "<b>Код документу:</b> %" + id + "%<br>" + "<br>" + "Щоб переглянути цей документ, зайдіть на <a href=\"" + generalConfig.sHostCentral() + "\">iGov.org.ua</a>, пункт меню <b>Документи</b>, вкладка <b>Пошук документу за кодом</b>. Там оберіть тип документу, того, хто його надає та введіть код.<br>" + "<br>" + "З повагою,<br>" + "команда порталу державних послу iGov"; oMail.reset(); oMail._To(saToMail)._Head(sHead)._Body(sBody); oMail.send(); } return id; }