2017-12-29 22 views
1

나는 이라는 테이블과 3 열 (username, password, email)이 있습니다. 사용자가 비밀번호를 잊어 버렸을 때, 이메일로 비밀번호를 받기 위해 이메일을 삽입해야합니다 (비밀번호 복구).전자 메일을 사용한 비밀번호 복구

  1. 왜 난 항상 메시지 User does not exist를받을 수 있나요 :

    나는이 개 질문이?

  2. 두 번째 observe에는 더 효율적인 방법이 있습니까 passmsg?

첫째

observe({ 
    if (USER$Foget == TRUE){   # Foget is a flag 
     if (!is.null(input$back)){  #back is a button to go back to the main page  
      if (input$back > 0){    
       output$page <- renderUI({    
       div(class="outer",do.call(bootstrapPage,c("",ui1())))  
       }) 
      } 
     } 
    } 
    if (USER$Foget == TRUE){ 
     if (!is.null(input$PassRecall)){  #PassRecall is a button to send the email 
      if (input$PassRecall > 0){ 
       Mail_to <- isolate(input$email) 
       query <- sprintf({" 
        SELECT password 
        FROM users 
        WHERE email='%s'"}, 
        Mail_to, serialize=F) 
        db <- RSQLite::dbConnect(RSQLite::SQLite(), dbname="db.sqlite") 
       userr <- RSQLite::dbGetQuery(db, query) 
       RSQLite::dbDisconnect(db) 
       if (length(userr$rowid)>=1) { 
        USER$existed <- TRUE 
       } 
      } 
     } 
     print(ui) 
    }}) 

둘째

observe({ 
    if (USER$Foget == TRUE) { 
     if (!is.null(input$PassRecall)){ 
     if (input$PassRecall > 0){  
      if(USER$existed == TRUE){ 
      Mail_from <- "[email protected]" 
      Mail_to <- isolate(input$email) 
      subject <- "password recovery" 
      pass <- unique(dbGetQuery(db,"SELECT password FROM users WHERE email=='Mail_to'")) 
      msg <- "You password is: 'pass'" 
      sendmail(Mail_from, Mail_to, subject, msg) 
      showNotification("Please, Check your Email !", duration = 5, type = c("message"))        
      } 
      } 
     } 
    } 
    if (USER$Foget == TRUE) { 
     if (!is.null(input$PassRecall)){ 
      if (input$PassRecall > 0){ 
       if(USER$existed == FALSE){ 
        showNotification("User does not exist !", duration = 5, type = c("error"))    
       } 
      } 
     } 
    }}) 
+0

실제 비밀번호를 저장하는 이유는 무엇입니까? – Dason

+0

@Dason 마음에, "바비 테이블"은 어때? 또한 여기에 게시물 당 하나의 질문이 필요하며 "이 코드가 작동하지 않는 이유는 무엇입니까?"라는 완전한 코드 예제가 필요합니다. 질문. – Spacedman

+0

@ 스페이스 맨, 너무 길기 때문에 전체 스크립트를 쓰는 것을 피하고 모든 스크립트를 혼동스럽게 만들면 잘 모르겠습니다. 어쨌든, 나는 나의 질문을 편집했다. –

답변

0

는 I는 다음과 같이 고정 :

나는 제를 혼합하고, 제 관찰한다. 또한 if (length(userr$rowid)>=1) 상태를 if(nrow(pass_retrived)>=1)으로 변경했습니다.

observe({ 
    if (USER$Foget == TRUE){ 
     if (!is.null(input$back)){ 
      if (input$back > 0){ 
       output$page <- renderUI({ 
       div(class="outer",do.call(bootstrapPage,c("",ui1()))) 
       }) 
      } 
     } 
    } 

    if (USER$Foget == TRUE){ 
     if (!is.null(input$PassRecall)){ 
      if (input$PassRecall > 0){ 
       Mail_to <- isolate(input$email) 
       query <- sprintf({" 
        SELECT password 
        FROM users 
        WHERE email='%s'"}, 
        Mail_to, serialize=F) 
        db <- RSQLite::dbConnect(RSQLite::SQLite(), dbname="db.sqlite") 
       pass_retrived <- RSQLite::dbGetQuery(db, query) 
       RSQLite::dbDisconnect(db) 
       if(nrow(pass_retrived)>=1) { 
        Mail_from <- "YOUREMAIL" 
        subject <- "password recovery" 
        msg <- sprintf("Your password is %s.", pass_retrived) 
        send.mail(from = Mail_from, to = Mail_to, subject = subject, body = msg ,smtp = list(host.name = "smtp.gmail.com", port = 465,user.name="YOUREMAIL", passwd="PASSWORD", ssl=TRUE), authenticate = TRUE, send = TRUE) 
        showNotification("Please, Check your Email !", duration = 5, type = c("message")) 
       } 
       if(nrow(pass_retrived)==0) { 
        showNotification("User does not exist !", duration = 5, type = c("error")) 
       } 
      } 
     } 
     print(ui) 
    } 
    }) 
+1

변경 내용을 간략하고 사람이 읽을 수있는 용어로 알려주십시오. 아주 소수의 사람들이 두 개의 서로 다른 코드 덩어리를 통해 알게 될 것입니다. –

+0

Sure @BenBolker. 나는 첫 번째와 두 번째 관찰을 섞었다. 또한 'if (length (userr $ rowid)> = 1)'조건을 'if (nrow (pass_retrived)> = 1)'로 변경했습니다. –

관련 문제