RegLogServer: Login and registration moduleServer

RegLogServerR Documentation

Login and registration moduleServer

Description

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 are RegLogDBIConnector and RegLogGsheetConnector.

mailConnector

RegLogConnector object used for sending emails. Built-in children classes are RegLogEmayiliConnector and RegLogGmailrConnector.

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

Public 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 are RegLogDBIConnector and RegLogGsheetsConnector. 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 are RegLogEmayiliConnector and RegLogGmailrConnector. 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.


Method logout()

Method logging out logged user

Usage
RegLogServer$logout()

Method get_logs()

Method to receive all saved logs from the object in the form of single data.frame

Usage
RegLogServer$get_logs()
Returns

data.frame


Method clone()

The objects of this class are cloneable with this method.

Usage
RegLogServer$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

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)
}

shiny.reglog documentation built on Aug. 31, 2022, 1:06 a.m.