controller

package
v0.0.0-...-b0db392 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package controller defines types used to communicate with the model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthController

type AuthController struct {
	Data         AuthDataProvider
	Provider     oidc.Provider
	ProviderName string
}

AuthController handles login using oidc and logout.

func NewAuthController

func NewAuthController(data AuthDataProvider, provider oidc.Provider, providerName string) *AuthController

NewAuthController creates a new instance associated with an oidc provider.

func (*AuthController) Callback

func (c *AuthController) Callback(successURL string) xhandler.HandlerC

Callback handles the oidc/oauth2 callback after a login attempt from the user. If the idenity provider returned a proof for valid login, the userid is stored in the session. This includes the model lookup and a possible creation for new users. The users last login timestamp is updated.

func (*AuthController) Login

func (c *AuthController) Login() xhandler.HandlerC

Login handles login requests and delegates to the oidc provider.

func (*AuthController) Logout

func (c *AuthController) Logout(loginURL string) xhandler.HandlerC

Logout handles logout requests and invalidates the users session.

type AuthDataProvider

type AuthDataProvider interface {
	GetByOAuthID(oauthid string) (*model.User, error)
	UpdateLastLogin(id string) error
	NewUser() *model.User
	SaveNew(u *model.User) error
}

AuthDataProvider defines a the needed model interactions

type PostController

type PostController struct {
	Model PostDataProvider
}

PostController handles post related requests.

func (*PostController) Create

Create handles a request to create a new post.

Example request: `{"data":{"message":"test message"}}`

It checks for a non empty message with a length of at least 6 characters. On success it inserts an new post into the model and returns the created object as json with status code `http.StatusCreated`. Otherwise a json error is returned.

func (*PostController) Posts

Posts gets all posts from the database and returns valid json, otherwise a json error.

func (*PostController) Remove

Remove handles post remove requests and removes the post from the model if the user id matches the logged in user. The post id is defined as an url parameter.

On success an empty response with status http.StatusNoContent is written. If the post identified by the id could not be found http.StatusNotFound is returned. If the user id does not match http.StatusUnauthorized is returned.

type PostDataProvider

type PostDataProvider interface {
	GetUserByID(id string) (*model.User, error)
	GetPosts() ([]*model.Post, error)
	NewPost(uid string) *model.Post
	SaveNew(p *model.Post) error
	GetByID(id string) (*model.Post, error)
	Remove(p *model.Post) error
}

PostDataProvider defines the needed model interactions.

Jump to

Keyboard shortcuts

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