Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions server.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
library(Rautoml)
options(shiny.maxRequestSize=300000*1024^2)
options(shiny.maxRequestSize = 300000 * 1024^2)

source("R/utils_logging.R")

# ----- FastAPI base URL local version -----
#api_base <- Sys.getenv("FASTAPI_BASE", "http://127.0.0.1:8000")

# ----- FastAPI base URL - valeur par défaut (fallback) -----
# ----- FastAPI base URL - default / fallback -----
DEFAULT_API_BASE <- Sys.getenv("FASTAPI_BASE", "http://api:8000")

message("[ML API base default] ", DEFAULT_API_BASE)
# ----- FastAPI base URL Docker v1 -----
#api_base <- "http://localhost:3760"

# ----- FastAPI base URL Docker v2 -----
#api_base <- Sys.getenv("FASTAPI_BASE", "http://api:8000")

# FASTAPI Linux
#api_base <- "http://localhost:8000"

# ----- FastAPI base URL -----
# En local (sans Docker), FASTAPI_BASE n'est pas défini => fallback 127.0.0.1:8000
# En Docker Compose, FASTAPI_BASE sera injecté via l'environnement.

#message("[ML API base] ", api_base)


# ---- Source server modules ----
source("server/automl_controls_server.R")
source("server/train_model_server.R")
source("R/utils_api.R")
source("server/deploy_model_server.R", local=TRUE)
source("ui/deploy_model_ui.R", local=TRUE)
source("server/predict_pycaret_server.R", local = TRUE)
source("server/deploy_model_server.R", local = TRUE)
source("ui/deploy_model_ui.R", local = TRUE)
source("server/predict_pycaret_server.R", local = TRUE)

#Auth helper
source("server/auth.R")
function(input, output, session){
waiter_show(
html = spin_loaders(id = 2, style="width:56px;height:56px;color:#7BC148;"),
color = "#FFF"
)

shinyjs::show("login")
source("server/auth.R")
user_auth(input, output, session)
#Authentication, get USER (reactiveValues)
USER <- user_auth(input, output, session)

# 2) Run only once after login success
authed_started <- reactiveVal(FALSE)

observeEvent(USER$logged_in, {
req(isTRUE(USER$logged_in)) # only proceed if logged in = TRUE
waiter_show(
html = spin_loaders(id = 2, style="width:56px;height:56px;color:#7BC148;"),
color = "#FFF"
)

if (authed_started()) return(NULL)
authed_started(TRUE)


# ---- FastAPI base URL réactif (lié au champ fastapi_base) ----
api_base <- reactive({
Expand Down Expand Up @@ -744,7 +741,10 @@ function(input, output, session){
iv$enable()
iv_url$enable()
iv_ml$enable()

waiter_hide()

}, ignoreInit = FALSE)

waiter_hide()
}
71 changes: 43 additions & 28 deletions server/auth.R
Original file line number Diff line number Diff line change
@@ -1,55 +1,70 @@
# server/auth.R

user_auth <- function(input, output, session) {
# guard: run once per session
if (isTRUE(session$userData$user_auth_initialized)) return(invisible(NULL))
# Guard: only initialize once per session
if (isTRUE(session$userData$user_auth_initialized)) {
return(invisible(NULL))
}
session$userData$user_auth_initialized <- TRUE

# ---- Login module ----
USER <- login::login_server(
id = app_login_config$APP_ID,
db_conn = DBI::dbConnect(RSQLite::SQLite(), 'users.sqlite'),
emailer = login::emayili_emailer(
email_host = app_login_config$email_host,
email_port = app_login_config$email_port,
id = app_login_config$APP_ID,
db_conn = DBI::dbConnect(RSQLite::SQLite(), 'users.sqlite'),
emailer = login::emayili_emailer(
email_host = app_login_config$email_host,
email_port = app_login_config$email_port,
email_username = app_login_config$email_username,
email_password = app_login_config$email_password,
from_email = app_login_config$from_email
from_email = app_login_config$from_email
),
additional_fields = c(
"first_name" = "First Name",
"last_name" = "Last Name"
),
additional_fields = c('first_name' = 'First Name',
'last_name' = 'Last Name'),
cookie_name = "aphrc",
cookie_name = "aphrc",
cookie_password = "aphrcpass1"
)

# Show name somewhere if you want (e.g. in header)
output$userName <- renderText({
paste0(USER$first_name, " ", USER$last_name)
})


# Logout button: clear cookie and reload app
observeEvent(input$logoutID, {
shinyjs::runjs("document.cookie = 'aphrc=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'")
shinyjs::runjs(
"document.cookie = 'aphrc=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'"
)
session$reload()
}, ignoreInit = TRUE)


# Toggle between login / signup / reset forms
observeEvent(input$show_login, {
shinyjs::show("login_form", anim = TRUE, animType = "fade", time = 0.4)
shinyjs::hide("signup_form"); shinyjs::hide("reset_form")
output$form_title <- renderText("APHRC Nocode Platform")
shinyjs::hide("signup_form")
shinyjs::hide("reset_form")
}, ignoreInit = TRUE)

observeEvent(input$show_signup, {
shinyjs::show("signup_form", anim = TRUE, animType = "fade", time = 0.4)
shinyjs::hide("login_form"); shinyjs::hide("reset_form")
output$form_title <- renderText("Create an Account")
shinyjs::hide("login_form")
shinyjs::hide("reset_form")
}, ignoreInit = TRUE)

observeEvent(input$show_reset, {
shinyjs::show("reset_form", anim = TRUE, animType = "fade", time = 0.4)
shinyjs::hide("login_form"); shinyjs::hide("signup_form")
output$form_title <- renderText("Reset Password")
shinyjs::hide("login_form")
shinyjs::hide("signup_form")
}, ignoreInit = TRUE)

# Optionally show login form on first load:
observeEvent(TRUE, {
# Show login form on first load
observe({
shinyjs::show("login_form", anim = TRUE, animType = "fade", time = 0.4)
shinyjs::hide("signup_form"); shinyjs::hide("reset_form")
output$form_title <- renderText("APHRC Nocode Platform")
}, once = TRUE, ignoreInit = TRUE)
shinyjs::hide("signup_form")
shinyjs::hide("reset_form")
})

#return USER so server() can see USER$logged_in
USER
}
Binary file modified users.sqlite
Binary file not shown.