manager

package
v0.0.0-...-ea2ceb1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUsernameTaken common error on registration form when the username already existed
	ErrUsernameTaken = errors.New("username taken")

	// ErrUserNotFound common error on login form when the user is not found
	ErrUserNotFound = errors.New("user not found")

	// ErrTypeMismatch specific error for capturing type mismatch
	ErrTypeMismatch = errors.New("the type didn't match")

	// ErrNilClient gives error message when redis client variable is nil
	ErrNilClient = errors.New("client is nil")

	// ErrEmptyForm gives error message when form body is empty
	ErrEmptyForm = errors.New("form is empty")

	// ErrPerm gives error message when self tries to modify other accounts details
	ErrPerm = errors.New("permission to modify is denied")
)

Functions

func GetUser

func GetUser(ctx context.Context, c redis.Cmdable, user *User) (pensive.User, error)

func PostUpdate

func PostUpdate(ctx context.Context, c redis.Cmdable, userID int64, body, mediaID string) error

PostUpdate adds a new update; this differs from edit which actually changes

func UpdateEmail

func UpdateEmail(ctx context.Context, c redis.Cmdable, userID int64, newEmail, oldPassword string) error

UpdateEmail authenticates the user by its username and password and updates it with new ones userID is the current user requesting

func UpdatePassword

func UpdatePassword(ctx context.Context, c redis.Cmdable, userID int64, oldPassword, newPassword string) error

UpdatePassword authenticates the user by its username and password and updates it with new ones userID is the current user requesting

func UpdateUser

func UpdateUser(ctx context.Context, c redis.Cmdable, userID int64, newUsername, oldPassword, newPassword, newEmail string) error

UpdateUser authenticates the user by its username and password and updates it with new ones userID is the current user requesting

func UpdateUsername

func UpdateUsername(ctx context.Context, c redis.Cmdable, userID int64, newUsername, oldPassword string) error

UpdateUsername authenticates the user by its username and password and updates it with new ones userID is the current user requesting

Types

type Manager

type Manager struct {
	Cmdable redis.Cmdable
}

func NewManager

func NewManager(ctx context.Context, addr, password string) (*Manager, error)

type Post

type Post struct {
	// contains filtered or unexported fields
}

Post user generated inputs

func AddPost

func AddPost(ctx context.Context, c redis.Cmdable, p pensive.Post) (*Post, error)

AddPost creates a new post, saves it to the database, and returns the newly created question

func GetAllPosts

func GetAllPosts(ctx context.Context, c redis.Cmdable) ([]*Post, error)

GetAllPosts All Updates getter

func GetPosts

func GetPosts(ctx context.Context, c redis.Cmdable, userID int64) ([]*Post, error)

GetPosts gets all updates created by the user

func (*Post) Body

func (p *Post) Body(ctx context.Context) (string, error)

Body getter

func (*Post) CreatedAt

func (p *Post) CreatedAt(ctx context.Context) (*time.Time, error)

CreatedAt getter

func (*Post) MediaID

func (p *Post) MediaID(ctx context.Context) (string, error)

MediaID getter

func (*Post) UpdatedAt

func (p *Post) UpdatedAt(ctx context.Context) (*time.Time, error)

UpdatedAt getter

func (*Post) User

func (p *Post) User(ctx context.Context) (*User, error)

User getter

type User

type User struct {
	// contains filtered or unexported fields
}

User the general people

func AddUser

func AddUser(ctx context.Context, c redis.Cmdable, username string, password []byte, email string) (*User, error)

AddUser this creates a new user entry

func AuthSelf

func AuthSelf(r *http.Request, s *sessions.Session, c redis.Cmdable, key string) (*User, error)

AuthSelf checks if username has registered in this site

func AuthUser

func AuthUser(ctx context.Context, c redis.Cmdable, username, password string) (*User, error)

AuthUser authenticates the user by its username and password

func GetUserByName

func GetUserByName(ctx context.Context, c redis.Cmdable, username string) (*User, error)

GetUserByName gets the user using the username

func GetUserByUserID

func GetUserByUserID(c redis.Cmdable, userID int64) (*User, error)

GetUserByUserID gets user using a user id

func RegisterUser

func RegisterUser(ctx context.Context, c redis.Cmdable, username, password, email string) (*User, error)

RegisterUser register a valid user

func (*User) CreatedAt

func (u *User) CreatedAt(ctx context.Context) (*time.Time, error)

CreatedAt getter there should be no setter for created at

func (*User) Email

func (u *User) Email(ctx context.Context) (string, error)

Email getter

func (*User) ID

func (u *User) ID() int64

ID UserID getter there should be no setter for id

func (*User) IsVerified

func (u *User) IsVerified(ctx context.Context) (bool, error)

IsVerified getter

func (*User) Password

func (u *User) Password(ctx context.Context) ([]byte, error)

Password Hash getter

func (*User) SetEmail

func (u *User) SetEmail(ctx context.Context, value string) error

SetEmail Email setter

func (*User) SetPassword

func (u *User) SetPassword(ctx context.Context, value []byte) error

SetPassword Password Hash setter

func (*User) SetUsername

func (u *User) SetUsername(ctx context.Context, value string) error

SetUsername Username setter

func (*User) UpdateNow

func (u *User) UpdateNow(ctx context.Context) error

UpdateNow UpdatedAt setter

func (*User) UpdatedAt

func (u *User) UpdatedAt(ctx context.Context) (*time.Time, error)

UpdatedAt Hash getter

func (*User) Username

func (u *User) Username(ctx context.Context) (string, error)

Username Username getter

func (*User) Verify

func (u *User) Verify(ctx context.Context, value bool) error

Verify Verify setter this converts bool to a redis friendly string bool

Jump to

Keyboard shortcuts

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