Initiate this container at global level. Methods in this class can help admins to manage accounts in a SPS project.

It uses a SQLite database, by default is created inside config directory on SPS initialization.

You can use it to add/remove users, change user roles, change password, match/verify account, password, role.

A default user account "user", with password "user", and a default admin account "admin" with password "admin" are create for you.

For app deployment, PLEASE create your own accounts and DELETE the default ones.

Super classes

systemPipeShiny::spsDb -> systemPipeShiny::spsEncryption -> spsaccount

Methods

Public methods

Inherited methods

Method new()

initialize a new SPS account container

Usage

spsAccount$new()


Method accList()

list all accounts of the app. Returns a dataframe

Usage

spsAccount$accList(include_pass = FALSE, db_name = "config/sps.db")

Arguments

include_pass

bool, include password hash column?

db_name

SPS database path


Method accAdd()

add an account to use the app

Usage

spsAccount$accAdd(acc_name, acc_pass, role = "user", db_name = "config/sps.db")

Arguments

acc_name

string, account name

acc_pass

string, account password

role

string, what kind role is this user, one of "user", "admin"

db_name

SPS database path


Method accRemove()

remove an account

Usage

spsAccount$accRemove(acc_name, db_name = "config/sps.db")

Arguments

acc_name

string, account name

db_name

SPS database path


Method accPassChange()

change password of an account

Usage

spsAccount$accPassChange(acc_name, acc_pass, db_name = "config/sps.db")

Arguments

acc_name

string, account name

acc_pass

string, account new password

db_name

SPS database path


Method accRoleChange()

change the role of an account

Usage

spsAccount$accRoleChange(acc_name, role, db_name = "config/sps.db")

Arguments

acc_name

string, account name

role

string, one of "user" or "admin"

db_name

SPS database path


Method accMatch()

Try to see if the account name exists and has the right password and role type, useful for login authentification.

Usage

spsAccount$accMatch(
  acc_name,
  acc_pass,
  role = "user",
  match_role = FALSE,
  db_name = "config/sps.db"
)

Arguments

acc_name

string, account name

acc_pass

string, account new password

role

string, one of "user" or "admin"

match_role

bool, also verify the account role type?

db_name

SPS database path


Method clone()

The objects of this class are cloneable with this method.

Usage

spsAccount$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

dir.create("config", showWarnings = FALSE) spsOption("verbose", TRUE) spsOption("use_crayon", TRUE) # create a new container db <- spsAccount$new()
#> [SPS-INFO] 2021-09-18 02:42:27 Created SPS account method container
#> [SPS-INFO] 2021-09-18 02:42:27 This container inherits all functions from spsEncryption and spsDb class
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Connected, but tables missing, seems like a new db.
db$createDb()
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Creating SPS db...
#> [SPS-INFO] 2021-09-18 02:42:27 Db write the meta table
#> [SPS-INFO] 2021-09-18 02:42:27 Db write the raw table
#> [SPS-INFO] 2021-09-18 02:42:27 Key generated and stored in db
#> [SPS-INFO] 2021-09-18 02:42:27 Db create admin account
#> [SPS-DANGER] 2021-09-18 02:42:27 Done, Db created at 'config/sps.db'. DO NOT share this file with others or upload to open access domains. #> [SPS-INFO] 2021-09-18 02:42:27 Key md5 bf0347e879706ba54826de2a38a9a0af
# list all accounts db$accList()
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Query sent
#> account role #> 1 admin admin #> 2 user user
# add a new user db$accAdd('user2', '!admin12345')
#> [SPS-INFO] 2021-09-18 02:42:27 Checking account info
#> [SPS-INFO] 2021-09-18 02:42:27 Account user2 created.
# list all accounts include password hash db$accList(include_pass = TRUE)
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Query sent
#> account pass #> 1 admin 20500faed327463d8b3d80cb40b9e514852be7b2c24ff0489e70ae65ed8d02e4 #> 2 user 9f5a4de3b28a5cd01441b4e8f471e092cf9e344251701c4085f6b74b4f05bf06 #> 3 user2 2dde4e35c2a65b09ac0ad04d64b301e078b929a19d37ff89d31676bea5059867 #> role #> 1 admin #> 2 user #> 3 user
# change password of an account db$accPassChange("user2", "$aaaaaaa")
#> [SPS-INFO] 2021-09-18 02:42:27 Checking account info
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Updated 1 rows
#> [SPS-INFO] 2021-09-18 02:42:27 Account user2 password created.
# check if pass changed db$accList(include_pass = TRUE)
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Query sent
#> account pass #> 1 admin 20500faed327463d8b3d80cb40b9e514852be7b2c24ff0489e70ae65ed8d02e4 #> 2 user 9f5a4de3b28a5cd01441b4e8f471e092cf9e344251701c4085f6b74b4f05bf06 #> 3 user2 d9ec87e03b0a6e0559b0086641aa893e2015fda5ba9af8cff64de51e4ae47c50 #> role #> 1 admin #> 2 user #> 3 user
# change the role of from user to admin db$accRoleChange("user2", "admin")
#> [SPS-INFO] 2021-09-18 02:42:27 Checking account info
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Updated 1 rows
#> [SPS-INFO] 2021-09-18 02:42:27 Account user2 role changed.
# check role change db$accList()
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Query sent
#> account role #> 1 admin admin #> 2 user user #> 3 user2 admin
# remove a user db$accRemove("user2")
#> [SPS-INFO] 2021-09-18 02:42:27 Checking account info
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Deleted 1 rows
#> [SPS-INFO] 2021-09-18 02:42:27 Account user2 removed
# check accounts again db$accList()
#> [SPS-INFO] 2021-09-18 02:42:27 Db connected
#> [SPS-INFO] 2021-09-18 02:42:27 Query sent
#> account role #> 1 admin admin #> 2 user user
# check if username and password matches db$accMatch(acc_name = "user", acc_pass = "user")
#> [SPS-INFO] 2021-09-18 02:42:27 Matching account info
#> [1] TRUE
# wrong pass db$accMatch("user", "user123")
#> [SPS-INFO] 2021-09-18 02:42:27 Matching account info
#> [1] FALSE
# also check if the user has the right role db$accMatch("user", "user", role = "user", match_role = TRUE)
#> [SPS-INFO] 2021-09-18 02:42:27 Matching account info
#> [1] TRUE
db$accMatch("user", "user", role = "admin", match_role = TRUE)
#> [SPS-INFO] 2021-09-18 02:42:27 Matching account info
#> [1] FALSE