Login and registration moduleServer
RegLogServer.Rd
RegLogServer is an R6 class to use for handling the whole backend of login and registration component of your shinyApp.
Public fields
is_logged
reactiveVal containing logical indicating if the user is logged in
user_id
reactiveVal containing character specifying the logged user name. If the user is not logged in, it will consist of uuid generated with
uuid::UUIDgenerate
user_mail
reactiveVal cantaining character string specifying the logged user mail. When not logged in, it contains NULL.
account_id
reactiveVal caintaining integer specifying the logged user account's id number: for SQL database it is equal to the value contained withing
id
variable. For googlesheets database it is equal to the row number - 1 (the header). If not logged, it contains NULL.mail_message
reactiveVal containing most recent RegLogConnectorMessage received from mailConnector
message
reactiveVal containing most recent RegLogConnectorMessage received from dbConnector or generated by RegLogServer itself.
module_id
character storing ID for reglog_system module.
dbConnector
RegLogConnector
object used for communication with the database. Build-in children classes areRegLogDBIConnector
andRegLogGsheetConnector
.mailConnector
RegLogConnector
object used for sending emails. Built-in children classes areRegLogEmayiliConnector
andRegLogGmailrConnector
.log
list containing all messages send and received.
UI_list_login
reactiveVal holding the tagList of whole login UI.
UI_list_resetPass
reactiveVal holding the tagList of whole resetPass UI.
UI_list_credsEdit
reactiveVal holding the tagList of whole credentioals edit UI.
UI_list_register
reactiveVal holding the tagList of whole register UI.
Methods
Method new()
Initialize 'ReglogServer' moduleServer
Usage
RegLogServer$new(
dbConnector,
mailConnector,
app_name = basename(getwd()),
app_address = NULL,
lang = "en",
custom_txts = NULL,
use_modals = TRUE,
module_id = "login_system"
)
Arguments
dbConnector
object of class
RegLogConnector
handling the reads from and writes to database. Two available in the package areRegLogDBIConnector
andRegLogGsheetsConnector
. See their documentation for more information about usage and creation of custom dbConnectors.mailConnector
object of class
RegLogConnector
handling the email sending to the user for register confirmation and password reset. Two available in the package areRegLogEmayiliConnector
andRegLogGmailrConnector
. See their documentation for more information about usage and creation of custom mailConnectors.app_name
Name of the app to refer during correspondence to users. Defaults to the name of working directory.
app_address
URL to refer to during correspondence to users. If left at NULL, the URL will be parsed from
session$clientData
.lang
character specyfiyng which language to use for all texts generated in the UI. Defaults to 'en' for English. Currently 'pl' for Polish is also supported.
custom_txts
named list containing character strings with custom messages. Defaults to NULL, so all built-in strings will be used.
use_modals
either logical indicating if all (
TRUE
) or none (FALSE
) modalDialogs should be shown or character vector indicating which modals should be shown. For more information see details.module_id
Character declaring the id of the module. Defaults to 'login_system'. Recommended to keep it that way, unless it would cause any namespace issues.
Examples
# Run only in interactive session #
if (interactive()) {
library(shiny.reglog)
# for exemplary setup temporary SQLite database will be created
library("DBI")
library("RSQLite")
temp_sqlite <- tempfile(fileext = ".sqlite")
conn <- DBI::dbConnect(RSQLite::SQLite(),
dbname = temp_sqlite)
DBI_tables_create(conn)
DBI::dbDisconnect(conn)
# create minimalistic UI
ui <- navbarPage(
title = "RegLog system",
tabPanel("Register", RegLog_register_UI("custom_id")),
tabPanel("Login", RegLog_login_UI("custom_id")),
tabPanel("Credentials edit", RegLog_credsEdit_UI("custom_id")),
tabPanel("Password reset", RegLog_resetPass_UI("custom_id"))
)
# create server logic
server <- function(input, output, session) {
# create dbConnector with connection to the temporary SQLite database
dbConnector <- RegLogDBIConnector$new(
driver = RSQLite::SQLite(),
dbname = temp_sqlite)
# create mockup mailConnector
mailConnector <- RegLogConnector$new()
# create RegLogServer
RegLog <- RegLogServer$new(
dbConnector = dbConnector,
mailConnector = mailConnector,
## all arguments below are optional! ##
app_name = "RegLog example",
app_address = "https://reglogexample.com",
lang = "en",
# custom texts as a named list with strings
custom_txts = list(
user_id = "Name of the user",
register_success_t= "Congratulations - you have been registered in
successfully with RegLog system!"),
# use modals as a named list of FALSE to inhibit specific modal
use_modals = list(
login_success = FALSE),
# custom module id - provide the same to the UI elements!
module_id = "custom_id")
}
shinyApp(ui, server)
}