userland

package module
v0.0.0-...-8717a1f Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: GPL-2.0 Imports: 3 Imported by: 0

README

userland

Go Report Card Build Status

User Management API, based on https://userland.docs.apiary.io

Entities: User Event Session

Database: postgres, redis Authentication: JWS

Installation | Usage | License

Userland is account self-management, imaginary APIs that will include following near-real-world features:
  • Registration
  • Activation
  • Authentication (with optional 2FA)
  • Forgot and Reset Password
  • Self Data ManagementManage Basic Info
    • Manage Profile Picture
    • Change Email
    • Change Password
    • Configure 2FA
  • Self Session Management
    • Manage Session
    • Manage Refresh Token
    • Manage Access Token
    • Event Logging
    • Self Delete

Installation (For Development)

  • git clone
  • set environtment variables in .env see (.env.sample)
  • create database "userland" on postgres
  • create database "userland_test" on postgres
  • download migration cli
(linux)
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.1.0/migrate.linux-amd64.tar.gz | tar xvz
(mac Os)
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.1.0/migrate.darwin-amd64.tar.gz | tar xvz
  • run migration
(linux)
./migrate.linux-amd64 -path storage/postgres/migration/ -database postgres://[user]:[pass]@localhost:5432?sslmode=disable up 2
(linux)
./migrate.darwin-amd64 -path storage/postgres/migration/ -database postgres://[user]:[pass]@localhost:5432?sslmode=disable up 2
  • run build
make build-api
make build-mail
  • run api and mail

Usage

  • You can find postman collection in docs folder

License

MIT © [Adhitya Ramadhanus]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrUserNotFound represent user is not found when searching in repository
	ErrUserNotFound = errors.New("User not found")
	//ErrDuplicateKey represent insert duplicated user
	ErrDuplicateKey = errors.New("Duplicate key in user")
)
View Source
var (
	//ErrKeyNotFound represent key is not found when searching in KeyValueService
	ErrKeyNotFound = errors.New("Key not found")
)
View Source
var (
	//ErrSessionNotFound represent session not found
	ErrSessionNotFound = errors.New("Session not found")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	ID         int
	UserID     int
	Event      string
	UserAgent  string
	IP         string
	ClientID   int
	ClientName string
	Timestamp  time.Time
	CreatedAt  time.Time
}

Event is domain entity

type EventFilterOptions

type EventFilterOptions struct {
	UserID int
	Event  string
	IP     string
}

type EventPagingOptions

type EventPagingOptions struct {
	Limit  int
	Offset int
	SortBy string
	Order  string
}

EventPagingOptions is a struct used as pagination option to get events

type EventRepository

type EventRepository interface {
	FindAll(filter EventFilterOptions, paging EventPagingOptions) (Events, int, error)
	Insert(event Event) error
	DeleteAllByUserID(userID int) error
}

EventRepository provide an interface to get user events

type Events

type Events []Event

Events is collection of Event

type KeyValueService

type KeyValueService interface {
	Set(key string, value []byte) error
	SetEx(key string, value []byte, expirationInSeconds time.Duration) error
	Get(key string) ([]byte, error)
	Delete(key string) error
}

KeyValueService provide an interface to get key

type ObjectMetaData

type ObjectMetaData struct {
	ContentType     string
	ContentEncoding string
	Size            int64
	CacheControl    string
	Path            string
}

ObjectMetaData is data about object

type ObjectStorageService

type ObjectStorageService interface {
	// should write with options
	Write(reader io.Reader, metadata ObjectMetaData) (string, error)
	Fetch(path string) ([]byte, ObjectMetaData, error)
}

ObjectStorageService provide an interface to get objects

type Session

type Session struct {
	ID         string
	Token      string
	IP         string
	ClientID   int
	ClientName string
	Expiration time.Duration
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Session is domain entity

type SessionRepository

type SessionRepository interface {
	Create(userID int, session Session) error
	FindAllByUserID(userID int) (Sessions, error)
	DeleteExpiredSessions(userID int) error
	DeleteBySessionID(userID int, sessionID string) error
	DeleteOtherSessions(userID int, sessionID string) (deletedSessionIDs []string, err error)
}

SessionRepository provide an interface to get user sessions

type Sessions

type Sessions []Session

Sessions a collection of Session

type User

type User struct {
	ID           int
	Email        string
	Fullname     string
	Phone        string
	Location     string
	Bio          string
	WebURL       string
	PictureURL   string
	Password     string
	TFAEnabled   bool
	Verified     bool
	BackupCodes  []string
	TFAEnabledAt time.Time
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

User is domain entity

type UserRepository

type UserRepository interface {
	Find(id int) (User, error)
	FindByEmail(email string) (User, error)
	Insert(user *User) error
	Update(user User) error
	// problematic func here
	StoreBackupCodes(user User) error
	Delete(id int) error
}

UserRepository provide an interface to get user entities

Jump to

Keyboard shortcuts

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