Documentation ¶
Overview ¶
Package users implements functionality for adding users, editing a user, and logging in a user.
Index ¶
- Variables
- func Add(w http.ResponseWriter, r *http.Request)
- func ChangePwd(w http.ResponseWriter, r *http.Request)
- func CreateAdmin(w http.ResponseWriter, r *http.Request)
- func DoesAdminExist(r *http.Request) error
- func GetAll(w http.ResponseWriter, r *http.Request)
- func GetOne(w http.ResponseWriter, r *http.Request)
- func Login(w http.ResponseWriter, r *http.Request)
- func Logout(w http.ResponseWriter, r *http.Request)
- func UpdatePermissions(w http.ResponseWriter, r *http.Request)
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrAdminDoesNotExist = errors.New("users: admin user does not exist") ErrUserDoesNotExist = errors.New("users: user does not exist") )
errors
Functions ¶
func ChangePwd ¶
func ChangePwd(w http.ResponseWriter, r *http.Request)
ChangePwd is used to change a user's password
func CreateAdmin ¶
func CreateAdmin(w http.ResponseWriter, r *http.Request)
CreateAdmin saves the initial super-admin for the app This user is used to log in and create new users when the app is first used. This user is created when the app upon initial use of the app. Done this way b/c we don't want to set a default password/username in the code.
func DoesAdminExist ¶
DoesAdminExist checks if the super-admin has already been created The super-admin should be created upon initially using and setting up the app. This user must exist for the app to function.
func GetAll ¶
func GetAll(w http.ResponseWriter, r *http.Request)
GetAll retrieves the list of all users in the datastore This is used to populate the select elements in the gui when changing a user's password or access rights.
func GetOne ¶
func GetOne(w http.ResponseWriter, r *http.Request)
GetOne retrieves the full data for one user This is used to fill in the edit user modal in the gui.
func Login ¶
func Login(w http.ResponseWriter, r *http.Request)
Login verifies a username and password combo This makes sure the user exists, that the password is correct, and that the user is active. If user is allowed access, their data is saved to the session and they are redirected into the app.
func Logout ¶
func Logout(w http.ResponseWriter, r *http.Request)
Logout handles logging out of the app this removes the session data so a user must log back in before using the app
func UpdatePermissions ¶
func UpdatePermissions(w http.ResponseWriter, r *http.Request)
UpdatePermissions is used to save changes to a user's permissions (access rights) Super-admin "administrator" account cannot be edited...this user always has full permissions. You can not edit your own permissions so you don't lock yourself out of the app. Permissions default to "false".
Types ¶
type User ¶
type User struct { Username string `json:"username"` //an email address (exception is for the super-admin created initially) Password string `json:"-"` //bcrypt encrypted password AddCards bool `json:"add_cards"` //permissions RemoveCards bool `json:"remove_cards"` //" " ChargeCards bool `json:"charge_cards"` //" " ViewReports bool `json:"view_reports"` //" " Administrator bool `json:"is_admin"` //" " Active bool `json:"is_active"` //is the user able to access the app Created string `json:"datetime_created"` //datetime of when the user was created }
User is the format for data saved to the datastore about a user