user

package
v0.0.0-...-927f0f1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUsernameTaken is thrown if username is already taken while creating an user
	ErrUsernameTaken = errors.New("This username is already taken")
	// ErrUserNotFound is thrown if user is not found when searching users from database
	ErrUserNotFound = errors.New("User not found")
)

Functions

func DeleteUser

func DeleteUser(id string)

DeleteUser removes user from database

func DoesAdminExist

func DoesAdminExist() (bool, error)

DoesAdminExist checks if there is any account in the database that has admin rights

func UpdateEmail

func UpdateEmail(id string, newEmail string)

UpdateEmail replaces specific users email in database with the new email.

func UpdatePassword

func UpdatePassword(id string, newPass string) bool

UpdatePassword updates the users password hash with the new passwords hash

func UpdateRealName

func UpdateRealName(id string, newName string)

UpdateRealName updates users real name to database

func UpdateUsername

func UpdateUsername(id string, newUn string)

UpdateUsername replaces users username on database with new username.

Types

type Teacher

type Teacher struct {
	User
	ShortenedName string
}

Teacher represents a teacher

type User

type User struct {
	Username        string
	Fullname        string
	Email           string
	PasswordHash    string
	UUID            string
	LastLogin       int64
	Online          bool
	PermissionLevel int // PermissionLevel tells the system what actions user can do. Only users with permissionlevel of over 3 can create new users.
	TemporaryAdmin  bool
}

User represents an user of this service

PermissionLevel:

Basically permissionlevels work like this:

0: Student, has all basic permissions

1: Teacher, can assing students to own groups

2: Manager, can manage groups and schedules

3: Admin, can create new subjects, courses and users

func CreateTemporaryAdmin

func CreateTemporaryAdmin(username string, password string) (User, error)

CreateTemporaryAdmin creates an user that has temp admin rights, it is deleted when it is first used.

func CreateUser

func CreateUser(username string, permissionLevel int, fullName string, email string, password string) (User, error)

CreateUser makes a new user and saves it to database. It returns the user.

func GetUser

func GetUser(id string) (User, error)

GetUser gets user based on user id

func GetUserByName

func GetUserByName(name string) (User, error)

GetUserByName returns an user based on username

func GetUsers

func GetUsers() ([]User, error)

GetUsers returns a slice of all users

func (*User) CheckPassword

func (u *User) CheckPassword(password string) (bool, error)

CheckPassword Compares users password with another password

Jump to

Keyboard shortcuts

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