diff --git a/R/iSEEindex.R b/R/iSEEindex.R index 6640086..2e95039 100644 --- a/R/iSEEindex.R +++ b/R/iSEEindex.R @@ -69,21 +69,23 @@ iSEElogin <- function(app.title = NULL) { #' @author Kevin Rue-Albrecht #' #' @importFrom utils capture.output -#' @importFrom shiny incProgress markdown modalDialog p showModal -#' showNotification withProgress +#' @importFrom shiny incProgress showNotification withProgress #' @importFrom shinyjs enable #' #' @rdname INTERNAL_launch_isee -.launch_isee <- function(FUN, session, pObjects) { +.launch_isee <- function(FUN, session, pObjects, username, password) { # nocov start + initial <- NULL # TODO + tour <- NULL # TODO withProgress(message = sprintf("Logging in ..."), - value = 0, max = 2, { + value = 0, max = 3, { incProgress(1, detail = "Verifying credentials") Sys.sleep(2) - se2 <- try(iseelogin) # TODO - if (is(se2, "try-error")) { + if (!.authenticate(username, password)) { showNotification("Login failed.", type="error") } else { + incProgress(1, detail = "Loading data set") + se2 <- SummarizedExperiment() # TODO: load desired data set (or another landing page like iSEEindex) incProgress(1, detail = "Launching iSEE app") FUN(SE=se2, INITIAL=initial, TOUR=tour) shinyjs::enable(iSEE:::.generalOrganizePanels) # organize panels diff --git a/R/observers.R b/R/observers.R index f2aafa2..427dc04 100644 --- a/R/observers.R +++ b/R/observers.R @@ -21,8 +21,8 @@ #' #' @rdname INTERNAL_create_observers .create_observers <- function(input, session, pObjects, rObjects) { - - invisible(NULL) + + invisible(NULL) } #' @param FUN A function to initialize the \pkg{iSEE} observer @@ -32,12 +32,14 @@ #' #' @rdname INTERNAL_create_observers .create_launch_observers <- function(FUN, input, session, pObjects) { - - # nocov start - observeEvent(input[[.ui_login_submit]], { - .launch_isee(FUN, session, pObjects) - }, ignoreNULL=TRUE, ignoreInit=TRUE) - # nocov end - - invisible(NULL) + + # nocov start + observeEvent(input[[.ui_login_submit]], { + username <- input[[.ui_login_username]] + password <- input[[.ui_login_password]] + .launch_isee(FUN, session, pObjects, username, password) + }, ignoreNULL=TRUE, ignoreInit=TRUE) + # nocov end + + invisible(NULL) } diff --git a/R/utils-authenticate.R b/R/utils-authenticate.R new file mode 100644 index 0000000..f95d3f9 --- /dev/null +++ b/R/utils-authenticate.R @@ -0,0 +1,8 @@ +.authenticate <- function(username, password) { + authorised_file <- system.file(package = "iSEElogin", "authorized") + authorised_info <- read.table(authorised_file, col.names = c("username", "password")) + any( + username == authorised_info$username & + digest(password, "sha512") == authorised_info$password + ) +} \ No newline at end of file diff --git a/inst/authorized b/inst/authorized new file mode 100644 index 0000000..8075391 --- /dev/null +++ b/inst/authorized @@ -0,0 +1,2 @@ +testuser 88d89fa7e0441e6118d3769140efb8d23ae897920d4dcb8cb4d48e8e3a96ace3e10245eb99eac499a33498d8a232fd1f45a1627c3937c9bcca5b5072936cb22d +wronguser nevergonnamatch