Documentation ¶
Overview ¶
Package app contains all logic of the project, all business tasks, manages all other modules.
Index ¶
- Variables
- type App
- type Application
- func (a *Application) CreateRecoveryCode(ctx context.Context, email string) error
- func (a *Application) CreateUser(ctx context.Context, email, username, password string, origin Origin) (*User, AuthToken, error)
- func (a *Application) DeleteUser(ctx context.Context, authUser AuthUser) error
- func (a *Application) ListUserByUsername(ctx context.Context, _ AuthUser, username string, page Page) ([]User, int, error)
- func (a *Application) Login(ctx context.Context, email, password string, origin Origin) (*User, AuthToken, error)
- func (a *Application) Logout(ctx context.Context, authUser AuthUser) error
- func (a *Application) RecoveryPassword(ctx context.Context, code, newPassword string) error
- func (a *Application) StartWALNotification(ctx context.Context) error
- func (a *Application) UpdateEmail(ctx context.Context, authUser AuthUser, email string) error
- func (a *Application) UpdatePassword(ctx context.Context, authUser AuthUser, oldPass, newPass string) error
- func (a *Application) UpdateUsername(ctx context.Context, authUser AuthUser, username string) error
- func (a *Application) User(ctx context.Context, _ AuthUser, userID UserID) (*User, error)
- func (a *Application) UserByAuthToken(ctx context.Context, token AuthToken) (*AuthUser, error)
- func (a *Application) VerificationEmail(ctx context.Context, email string) error
- func (a *Application) VerificationUsername(ctx context.Context, username string) error
- type Auth
- type AuthToken
- type AuthUser
- type Code
- type CodeRepo
- type Message
- type MessageKind
- type Notification
- type OAuth
- type OAuthAccount
- type Origin
- type Page
- type Password
- type Session
- type SessionID
- type SessionRepo
- type SocialID
- type TaskNotification
- type TokenID
- type User
- type UserApp
- type UserID
- type UserRepo
- type WAL
- type WALApplication
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmailExist = errors.New("email exist") ErrUsernameExist = errors.New("username exist") ErrNotFound = errors.New("not found") ErrNotValidPassword = errors.New("not valid password") ErrInvalidToken = errors.New("not valid auth") ErrExpiredToken = errors.New("auth is expired") ErrUsernameNeedDifferentiate = errors.New("username need to differentiate") ErrEmailNeedDifferentiate = errors.New("email need to differentiate") ErrNotUnknownKindTask = errors.New("unknown task kind") ErrCodeExpired = errors.New("code is expired") )
Errors.
Functions ¶
This section is empty.
Types ¶
type Application ¶ added in v0.2.0
type Application struct {
// contains filtered or unexported fields
}
Application implements interface App.
func New ¶
func New(userRepo UserRepo, sessionRepo SessionRepo, codeRepo CodeRepo, password Password, auth Auth, wal WAL, notification Notification, code Code) *Application
New creates and returns new App.
func (*Application) CreateRecoveryCode ¶ added in v0.2.0
func (a *Application) CreateRecoveryCode(ctx context.Context, email string) error
CreateRecoveryCode for implemented UserApp.
func (*Application) CreateUser ¶ added in v0.2.0
func (a *Application) CreateUser(ctx context.Context, email, username, password string, origin Origin) (*User, AuthToken, error)
CreateUser for implemented UserApp.
func (*Application) DeleteUser ¶ added in v0.2.0
func (a *Application) DeleteUser(ctx context.Context, authUser AuthUser) error
DeleteUser for implemented UserApp.
func (*Application) ListUserByUsername ¶ added in v0.2.0
func (a *Application) ListUserByUsername(ctx context.Context, _ AuthUser, username string, page Page) ([]User, int, error)
ListUserByUsername for implemented UserApp.
func (*Application) Login ¶ added in v0.2.0
func (a *Application) Login(ctx context.Context, email, password string, origin Origin) (*User, AuthToken, error)
Login for implemented UserApp.
func (*Application) Logout ¶ added in v0.2.0
func (a *Application) Logout(ctx context.Context, authUser AuthUser) error
Logout for implemented UserApp.
func (*Application) RecoveryPassword ¶ added in v0.2.0
func (a *Application) RecoveryPassword(ctx context.Context, code, newPassword string) error
RecoveryPassword for implemented UserApp.
func (*Application) StartWALNotification ¶ added in v0.2.0
func (a *Application) StartWALNotification(ctx context.Context) error
StartWALNotification for implemented WALApplication.
func (*Application) UpdateEmail ¶ added in v0.2.0
UpdateEmail for implemented UserApp.
func (*Application) UpdatePassword ¶ added in v0.2.0
func (a *Application) UpdatePassword(ctx context.Context, authUser AuthUser, oldPass, newPass string) error
UpdatePassword for implemented UserApp.
func (*Application) UpdateUsername ¶ added in v0.2.0
UpdateUsername for implemented UserApp.
func (*Application) UserByAuthToken ¶ added in v0.2.0
UserByAuthToken for implemented UserApp.
func (*Application) VerificationEmail ¶ added in v0.2.0
func (a *Application) VerificationEmail(ctx context.Context, email string) error
VerificationEmail for implemented UserApp.
func (*Application) VerificationUsername ¶ added in v0.2.0
func (a *Application) VerificationUsername(ctx context.Context, username string) error
VerificationUsername for implemented UserApp.
type Auth ¶
type Auth interface { // Token generates an authorization auth with a specified lifetime, // and can also use the UserID if necessary. // Errors: unknown. Token(expired time.Duration) (AuthToken, TokenID, error) // Parse and validates the auth and checks that it's expired. // Errors: ErrInvalidToken, ErrExpiredToken, unknown. Parse(token AuthToken) (TokenID, error) }
Auth module is responsible for working with authorization tokens.
type CodeRepo ¶
type CodeRepo interface { // SaveCode the code to restore the password to the repository. // Removes all recovery codes from this email before adding a new one. // Creates a task to send the recovery code to the user's mail. // Errors: unknown. SaveCode(ctx context.Context, id UserID, code string) error // UserID returns user id by recovery code. // Errors: ErrNotFound, unknown. UserID(ctx context.Context, code string) (userID UserID, createAt time.Time, err error) // Code returns recovery code for recovery password by user id. // Errors: ErrNotFound, unknown. Code(ctx context.Context, id UserID) (code string, err error) }
CodeRepo interface for recover code repository.
type MessageKind ¶
type MessageKind int
MessageKind selects the type of message to be sent.
const ( Welcome MessageKind = iota + 1 ChangeEmail PassRecovery )
Message enums.
func (MessageKind) String ¶
func (m MessageKind) String() string
type Notification ¶
type Notification interface { // NotificationTask must accept the parameter contact to whom the notification will be sent. // At the moment, the guarantee of message delivery lies on this module, it is possible to // transfer it to the Application. Notification(contact string, msg Message) error }
Notification module for working with alerts for registered users.
type OAuth ¶
type OAuth interface { // Account converts an authorization code into user information. // Errors: unknown. Account(context.Context, string) (*OAuthAccount, error) }
OAuth module responsible for working with social network. TODO Implements.
type OAuthAccount ¶
OAuthAccount user information from the social network.
type Password ¶
type Password interface { // Hashing returns the hashed version of the password. // Errors: unknown. Hashing(password string) ([]byte, error) // Compare compares two passwords for matches. Compare(hashedPassword []byte, password []byte) bool }
Password module responsible for working with passwords.
type SessionRepo ¶
type SessionRepo interface { // SaveSession saves the new user Session in a database. // Errors: unknown. SaveSession(context.Context, UserID, TokenID, Origin) error // Session returns user Session. // Errors: ErrNotFound, unknown. SessionByTokenID(context.Context, TokenID) (*Session, error) // DeleteSession removes user Session. // Errors: unknown. DeleteSession(context.Context, TokenID) error }
SessionRepo interface for session data repository.
type TaskNotification ¶
type TaskNotification struct { ID int UserID UserID Kind MessageKind }
TaskNotification contains information to perform the task of notifying the user.
type User ¶
type User struct { ID UserID Email string Username string PassHash []byte CreatedAt time.Time UpdatedAt time.Time }
User contains user information.
type UserApp ¶ added in v0.2.0
type UserApp interface { // VerificationEmail check if the user is registered with this email. // Errors: ErrEmailExist, unknown. VerificationEmail(ctx context.Context, email string) error // VerificationUsername check if the user is registered with this username. // Errors: ErrUsernameExist, unknown. VerificationUsername(ctx context.Context, username string) error // Login authorizes the user to the system. // Errors: ErrNotFound, ErrNotValidPassword, unknown. Login(ctx context.Context, email, password string, origin Origin) (*User, AuthToken, error) // Logout remove user Session. // Errors: unknown. Logout(context.Context, AuthUser) error // CreateUser creates a new user to the system, the password is hashed with bcrypt. // Errors: ErrEmailExist, ErrUsernameExist, unknown. CreateUser(ctx context.Context, email, username, password string, origin Origin) (*User, AuthToken, error) // DeleteUser deleting user profile. // Errors: unknown. DeleteUser(context.Context, AuthUser) error // User returning user profile. // Errors: ErrNotFound, unknown. User(context.Context, AuthUser, UserID) (*User, error) // UserByAuthToken returns user by authToken. // Errors: ErrNotFound, unknown. UserByAuthToken(ctx context.Context, token AuthToken) (*AuthUser, error) // UpdateUsername refresh the username. // Errors: ErrUsernameExist, ErrUsernameNeedDifferentiate, unknown. UpdateUsername(context.Context, AuthUser, string) error // UpdateEmail refresh the email. // Errors: ErrEmailExist, ErrEmailNeedDifferentiate, unknown. UpdateEmail(context.Context, AuthUser, string) error // UpdateUsername refresh user password. // Errors: ErrNotValidPassword, unknown. UpdatePassword(ctx context.Context, authUser AuthUser, oldPass, newPass string) error // ListUserByUsername returns list user by username. // Errors: unknown. ListUserByUsername(context.Context, AuthUser, string, Page) ([]User, int, error) // CreateRecoveryCode creates and sends a password recovery code to the user's email. // Errors: ErrNotFound, unknown. CreateRecoveryCode(ctx context.Context, email string) error // RecoveryPassword replaces the password with a new one from the user who owns this recovery code. // Errors: ErrCodeExpired, ErrNotFound, unknown. RecoveryPassword(ctx context.Context, code, newPassword string) error }
UserApp implements the business logic for user methods.
type UserRepo ¶
type UserRepo interface { // CreateUser adds to the new user in repository. // This method is also required to create a notifying hoard. // Errors: ErrEmailExist, ErrUsernameExist, unknown. CreateUser(context.Context, User) (UserID, error) // DeleteUser removes user from repository. // Errors: unknown. DeleteUser(context.Context, UserID) error // UpdateUsername changes username if he's not busy. // Errors: ErrUsernameExist, unknown. UpdateUsername(context.Context, UserID, string) error // UpdateEmail changes email if he's not busy. // Errors: ErrEmailExist, unknown. UpdateEmail(context.Context, UserID, string) error // UpdatePassword changes password. // Resets all codes to reset the password. // Errors: unknown. UpdatePassword(context.Context, UserID, []byte) error // UserByID returning user info by id. // Errors: ErrNotFound, unknown. UserByID(context.Context, UserID) (*User, error) // UserByAuthToken returning user info by authToken. // Errors: ErrNotFound, unknown. UserByTokenID(context.Context, TokenID) (*User, error) // UserByEmail returning user info by email. // This method is also required to create a notifying hoard. // Errors: ErrNotFound, unknown. UserByEmail(context.Context, string) (*User, error) // UserByUsername returning user info by id. // Errors: ErrNotFound, unknown. UserByUsername(context.Context, string) (*User, error) // ListUserByUsername returning list user info. // Errors: unknown. ListUserByUsername(context.Context, string, Page) ([]User, int, error) }
UserRepo interface for user data repository.
type WAL ¶
type WAL interface { // NotificationTask returns the earliest task that has not been completed. // Errors: ErrNotFound, unknown. NotificationTask(ctx context.Context) (task *TaskNotification, err error) // DeleteTaskNotification removes the task performed. // Errors: unknown. DeleteTaskNotification(ctx context.Context, id int) error }
WAL module returning tasks and also closing them.
type WALApplication ¶ added in v0.2.0
type WALApplication interface { // StartWALNotification starts the task of notifying users. StartWALNotification(ctx context.Context) error }
WALApplication a provider to run tasks.