我有一个名为users
的表格,其中有3列(username
,password
,email
)。当用户忘记密码时,他需要插入他的电子邮件以通过电子邮件接收密码(密码恢复)。
我有两个问题:
User does not exist
?observe
中,是否有更有效的方法来获取pass
和msg
?首先:
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 <- "estersilva1990@gmail.com"
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 :(得分:0)
我修好了如下:
我混合了第一次和第二次观察。另外,我将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)
}
})