weblogin

package
v0.0.0-...-d726a1a Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NavSectionHome     = "Home"
	NavSectionFactoids = "Factoids"
	NavSectionInvite   = "Channels"
	NavSectionLogs     = "Logs"
	NavSectionUser     = "User"
)
View Source
const Identifier = "weblogin"

Variables

View Source
var (
	ErrBadCookie = errors.New("Bad cookie data")
)
View Source
var ErrNoSuchUser = errors.New("That user does not exist.")
View Source
var ErrNotLoggedIn = errors.New("You are not logged in.")
View Source
var NavbarContent = []struct {
	Name string
	URL  string
}{
	{Name: NavSectionFactoids, URL: "/factoids"},
	{Name: NavSectionInvite, URL: "/invites"},
	{Name: NavSectionLogs, URL: "/logs"},
}

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func LayoutTemplateCopy

func LayoutTemplateCopy() *template.Template

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewWebLoginModule

func NewWebLoginModule(t marvin.Team) marvin.Module

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type API

type API interface {
	marvin.Module

	// GetCurrentUser gets the current User object for the request's cookies.
	// If there is no logged in user, this method returns (nil, nil).
	// An error is returned only in case of corrupt cookie data.
	GetCurrentUser(w http.ResponseWriter, r *http.Request) (*User, error)

	// GetUserBySlack gets the User object for the given Slack user.
	// If no associated Slack account is found, ErrNoSuchUser is returned.
	GetUserBySlack(slackID slack.UserID) (*User, error)
	// GetUserByIntra gets the User object for the given Intra username.
	// If no associated Intra account is found, ErrNoSuchUser is returned.
	GetUserByIntra(login string) (*User, error)

	// StartSlackURL returns the URL to redirect to to start Slack authentication.
	StartSlackURL(returnURL string, extraScopes ...string) string
	// StartSlackURL returns the URL to redirect to to start Intra authentication.
	StartIntraURL(returnURL string, extraScopes ...string) string

	// HTTPError renders a formatted error page.
	HTTPError(w http.ResponseWriter, r *http.Request, err error)
}

type ActionSourceWeb

type ActionSourceWeb struct {
	Team marvin.Team
	User *User
}

func (ActionSourceWeb) AccessLevel

func (ws ActionSourceWeb) AccessLevel() marvin.AccessLevel
func (ws ActionSourceWeb) ArchiveLink() string

func (ActionSourceWeb) ChannelID

func (ws ActionSourceWeb) ChannelID() slack.ChannelID

func (ActionSourceWeb) MsgTimestamp

func (ws ActionSourceWeb) MsgTimestamp() slack.MessageTS

func (ActionSourceWeb) UserID

func (ws ActionSourceWeb) UserID() slack.UserID

type LayoutContent

type LayoutContent struct {
	WLMod       *WebLoginModule
	Title       string
	CurrentURL  string
	CurrentUser *User

	NavbarCurrent     string
	NavbarItemsCustom interface{}

	BodyData interface{}
	// contains filtered or unexported fields
}

func NewLayoutContent

func NewLayoutContent(team marvin.Team, w http.ResponseWriter, r *http.Request, navSection string) (*LayoutContent, error)

NewLayoutContent will always succeed, but may leave some fields unfilled when err != nil.

func (*LayoutContent) DCurrentUser

func (w *LayoutContent) DCurrentUser() User

func (*LayoutContent) NavbarItems

func (w *LayoutContent) NavbarItems() interface{}

func (*LayoutContent) SlackUser

func (w *LayoutContent) SlackUser() (*slack.User, error)

func (*LayoutContent) StartIntraURL

func (w *LayoutContent) StartIntraURL(extraScopes ...string) string

func (*LayoutContent) StartSlackURL

func (w *LayoutContent) StartSlackURL(extraScopes ...string) string

func (*LayoutContent) Team

func (w *LayoutContent) Team() marvin.Team

type User

type User struct {
	ID int64

	SlackUser   slack.UserID
	SlackName   string
	SlackToken  string
	SlackScopes []string

	IntraLogin  string
	IntraToken  *oauth2.Token
	IntraScopes []string
	// contains filtered or unexported fields
}

A User contains possibly a logged-in Slack user, and possibly a logged-in Intra user.

func (*User) Destroy

func (u *User) Destroy() error

Destroy removes the User's row in the database.

func (*User) HasScopeSlack

func (u *User) HasScopeSlack(scope string) bool

func (*User) Login

func (u *User) Login(w http.ResponseWriter, r *http.Request) error

Login writes an auth cookie. This cannot be used with a User object not yet saved to the database (ID == -1).

func (*User) Logout

func (u *User) Logout(w http.ResponseWriter, r *http.Request) error

Logout deletes the auth cookie. Cannot be used with a User object not saved to the database.

func (User) NameWarning

func (u User) NameWarning() bool

func (*User) UpdateIntra

func (u *User) UpdateIntra(login string, token *oauth2.Token, scopes []string) error

UpdateIntra saves the given intra token to the database, and creates a new row in the database if necessary (id == -1).

func (*User) UpdateSlack

func (u *User) UpdateSlack(uid slack.UserID, name, token string, scopes []string) error

UpdateSlack saves the given slack token to the database, and creates a new row in the database if necessary (id == -1).

type WebLoginModule

type WebLoginModule struct {
	IntraOAuthConfig oauth2.Config
	// contains filtered or unexported fields
}

func (*WebLoginModule) CommandWebAuthenticate

func (mod *WebLoginModule) CommandWebAuthenticate(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult

func (*WebLoginModule) DestroySession

func (mod *WebLoginModule) DestroySession(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) Disable

func (mod *WebLoginModule) Disable(team marvin.Team)

func (*WebLoginModule) Enable

func (mod *WebLoginModule) Enable(team marvin.Team)

func (*WebLoginModule) GetCurrentUser

func (mod *WebLoginModule) GetCurrentUser(w http.ResponseWriter, r *http.Request) (*User, error)

GetCurrentUser looks up the current user based on the request. If there is no currently logged in user, it returns a nil *User instead of an error.

func (*WebLoginModule) GetOrNewCurrentUser

func (mod *WebLoginModule) GetOrNewCurrentUser(w http.ResponseWriter, r *http.Request) (*User, error)

GetOrNewCurrentUser looks up the current user based on the request. If there is no currently logged in user, it returns a new User object with a pseudo-id of -1.

func (*WebLoginModule) GetUserByID

func (mod *WebLoginModule) GetUserByID(uid int64) (*User, error)

func (*WebLoginModule) GetUserByIntra

func (mod *WebLoginModule) GetUserByIntra(login string) (*User, error)

GetUserByIntra checks for an existing user with the given Intra login name.

func (*WebLoginModule) GetUserBySlack

func (mod *WebLoginModule) GetUserBySlack(slackID slack.UserID) (*User, error)

GetUserBySlack checks for an existing user with the given Slack user ID.

func (*WebLoginModule) HTTPError

func (mod *WebLoginModule) HTTPError(w http.ResponseWriter, r *http.Request, err error)

func (*WebLoginModule) Identifier

func (mod *WebLoginModule) Identifier() marvin.ModuleID

func (*WebLoginModule) Load

func (mod *WebLoginModule) Load(t marvin.Team)

func (*WebLoginModule) OAuthAltSlackStart

func (mod *WebLoginModule) OAuthAltSlackStart(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) OAuthIntraCallback

func (mod *WebLoginModule) OAuthIntraCallback(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) OAuthIntraStart

func (mod *WebLoginModule) OAuthIntraStart(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) OAuthSlackCallback

func (mod *WebLoginModule) OAuthSlackCallback(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) OAuthSlackStart

func (mod *WebLoginModule) OAuthSlackStart(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) Serve404

func (mod *WebLoginModule) Serve404(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) ServeAsset

func (mod *WebLoginModule) ServeAsset(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) ServeCSRF

func (mod *WebLoginModule) ServeCSRF(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) ServeRoot

func (mod *WebLoginModule) ServeRoot(w http.ResponseWriter, r *http.Request)

func (*WebLoginModule) StartIntraURL

func (mod *WebLoginModule) StartIntraURL(returnURL string, extraScopes ...string) string

func (*WebLoginModule) StartSlackURL

func (mod *WebLoginModule) StartSlackURL(returnURL string, extraScopes ...string) string

func (*WebLoginModule) StartURL

func (mod *WebLoginModule) StartURL() string

Jump to

Keyboard shortcuts

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