--- title: "Accounts, Login and Admin" linkTitle: "Accounts, login and admin" type: docs weight: 10 --- ***** ## SPS accounts After a SPS project is initialized, some default accounts has been set up. They will not become useful unless you enable the login and admin features. There are 2 default accounts created for you to test before deploy: |name| role | password | | --- | --- | --- | | admin | admin | admin | | user | user | user | The admin account can be used in both the main app login and admin page login, and the user account can only be used for main app login.

Please change these accounts before deployment.

### Account management You can manage accounts in two ways: commandline and admin page. Here is how you manage from commandline, read how to do it from [admin page below](#admin-page). There are some helper code inside `global.R` file under your SPS project root. ```{r} ## account information ## PLEASE use following to add your own accounts and remove the default accounts for deployment # mydb <- spsAccount$new() # mydb$accList() # mydb$accAdd(acc_name = "XXX", acc_pass = "$xxxx", role = "admin") # mydb$accRemove("admin") # mydb$accRemove("user") ``` You can uncomment these lines to practice how to manage accounts, or read the reference manual about [spsAccount class](/sps/funcs/sps/reference/spsAccount.html). First to create a SPS project ```{r} suppressPackageStartupMessages(library(systemPipeShiny)) ``` ```{r eval=FALSE} app_path <- "." spsInit(app_path = app_path, overwrite = TRUE, open_files = FALSE) ``` ```{r echo=FALSE, collapse=TRUE} app_path <- tempdir() spsInit(app_path = app_path, overwrite = TRUE, change_wd = FALSE, open_files = FALSE) ``` Create a `spsAccount` object. SPS accounts are stored in the `config/sps.db` database inside your SPS projects. ```{r warning=FALSE, collapse=TRUE} acc <- spsAccount$new() ``` ```{r echo=FALSE} acc$createDb() ``` See what accounts you have ```{r} acc$accList() ``` You can also list passwords. They are SHA256 encrypted. ```{r collapse=TRUE} tibble::as_tibble(acc$accList(include_pass = TRUE)) ``` See [SPS database](../database) for encryption key details. Add a new user ```{r collapse=TRUE} acc$accAdd(acc_name = 'user2', acc_pass = '!newuser12345', role = "user") ``` Change the role of `user2` from "user" to "admin" ```{r collapse=TRUE} acc$accRoleChange(acc_name = "user2", role = "admin") ``` Remove a user ```{r collapse=TRUE} acc$accRemove("user2") acc$accList() ``` Change password ```{r collapse=TRUE} acc$accPassChange(acc_name = "user", , acc_pass = '!newuser54321') ``` Validate password ```{r} acc$accMatch(acc_name = "user", acc_pass = '!newuser54321') acc$accMatch(acc_name = "user", acc_pass = "user") acc$accMatch(acc_name = "abc", acc_pass = "123") ``` Validate password + role ```{r} acc$accMatch(acc_name = "user", acc_pass = '!newuser54321', match_role = TRUE, role = "user") acc$accMatch(acc_name = "user", acc_pass = '!newuser54321', match_role = TRUE, role = "admin") ``` ## Main app login After the account has been set up properly, one can try to turn on the login page for the main app. Use `spsOption("login_screen", TRUE)` or set `login_screen = TRUE` in **`global.R`** file. Whether enabling the login screen is fundamentally different how the Shiny app loads the UI and server code. - Disabled: loads UI and server on app start - Enabled: loads login UI and server on start, loads main app UI and server code only when login is successful. One advantage of using the login is the app starting time is fast. On app start, it only loads the login logic so it saves some time. The heavy part is the main app logic which will be loaded after a successful login. So the overall loading time is about the same. The difference is at what time point to load main app. Of course, if the user fails to login, main app will never be loaded. This can save some resources to handle unauthorized requests.

This difference may cause some javascript not working if you are loading your custom tabs with custom javascript. Set a wait signal in your javascript or report an issue to us if you have troubles.

**** The login screen is also controlled by another setting `login_theme`. By default, if you turn on the "login_screen", app will show you a random loading theme (`login_theme = "random"`) before you see the login panel. You can interact with these themes or change to play with a different theme. Or you can specify your favorate from "vhelix" (DNA double helix), "hhelix" (DNA flow), or "biomatrix" (DNA Matrix). ![](../login_theme.gif) **** If you are not a fan of these themes, you can use `login_theme = "empty"` to directly go to login panel.
![](../login_empty.png)
## Admin page SPS Admin page is panel of tabs to help app managers administrate the app. Under current version, SPS provides 2 main features: app information/statistics and account control. ### Admin login To reach the Admin page, users first need to enable this feature (default is `TRUE`) in SPS options `admin_page` use either `spsOption("admin_page", TRUE)` or set it in `global.R`. Afterwards, users need type in the correct url to find the page. This can be set with the SPS option `admin_url`. Default is "admin", `admin_url = "admin"`, but for security we recommend you to change it in deployment. To access it, add "?" + "YOUR_ADMIN_URL" to your app url to visit it. For example: we have a demo to visit the admin page, then we visit
![](../admin_login.png) Admin login page
You can use the testing account "admin" and password "admin" to login, but for security we strongly recommend you to change it in deployment. ### App information The first tab of the Admin page is current app and server information, like CPU, RAM, size, *etc*. On this tab, under details, some real-time statistic plots are rendered. You can interact with these plots to dig for more information.
![](../admin_tab_info.png) Admin page app info
### Account control Instead of changing account information from commandline, you can use this tab to add / remove / change password/ change roles of current app accounts.
![](../admin_tab_user.png) Admin page user control
![](../admin_newuser.png) Create a new user