users

package
v5.2.0--beta+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 17 Imported by: 4

Documentation

Overview

Package users implements functionality for adding users, editing a user, and logging in a user.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAdminDoesNotExist = errors.New("users: admin user does not exist")
	ErrUserDoesNotExist  = errors.New("users: user does not exist")
)

errors

Functions

func Add

func Add(w http.ResponseWriter, r *http.Request)

Add saves a new user to the app

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

func DoesAdminExist(r *http.Request) error

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

	//fields not used in cloud datastore
	ID int64 `json:"sqlite_user_id"`
}

User is the format for data saved to the datastore about a user

func Find

func Find(c context.Context, userID int64) (User, error)

Find gets the data for a given user id This returns all the info on a user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL