user

package
v0.0.0-...-8bfda83 Latest Latest
Warning

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

Go to latest
Published: May 12, 2015 License: MIT Imports: 12 Imported by: 23

Documentation

Overview

User management (sign up, login, sessions).

Index

Constants

View Source
const ContextCacheKey = "github.com/ungerik/go-start/user.ContextCacheKey"

Variables

View Source
var Config = Configuration{
	ConfirmationMessage: ConfirmationMessage{
		EmailSubject: "Please confirm your email address for %s",
		EmailMessage: "Please confirm your email address for %s by opening the following link:\n\n%s",
		Sent:         "We sent you an email with a verification link. It might some time to show up, but when it does you will be ready to use this site.",
	},
}
View Source
var UserPtrType = reflect.TypeOf((*User)(nil))
View Source
var UserType = UserPtrType.Elem()

Functions

func ConfirmEmail

func ConfirmEmail(confirmationCode string) (userID, email string, confirmed bool, err error)

func EmailConfirmationView

func EmailConfirmationView(profileURL view.URL) view.View

The confirmation code will be passed in the GET parameter "code"

func EnsureExists

func EnsureExists(username, email, password string, admin bool, resultRef interface{}) (exists bool, err error)

Will use user.User.Username for search Sets the username also as first name

func Init

func Init(collection *mongo.Collection)

func IsConfirmedUserID

func IsConfirmedUserID(id string) (confirmed bool, err error)

func LoggedIn

func LoggedIn(session *view.Session) bool

func Login

func Login(session *view.Session, userDoc mongo.Document)

func LoginEmailPassword

func LoginEmailPassword(session *view.Session, email, password string) (emailPasswdMatch bool, err error)

func LoginID

func LoginID(session *view.Session, id string)

func Logout

func Logout(session *view.Session)

func LogoutView

func LogoutView(redirect view.URL) view.View

If redirect is nil, the redirect will go to "/"

func Nav(login, signup, logout, profile *view.Link, separator view.View) view.View

Nav returns user navigation links depending on if there is an user session. If a user session is active, logout and profile will be returned, if there is no active user session, login and signup will be returned. separator will be put between the returned links. signup, profile, and separator are optional and can be nil.

func NewCollection

func NewCollection(name string) *mongo.Collection

func NewLoginForm

func NewLoginForm(buttonText, class, errorMessageClass, successMessageClass string, redirectURL view.URL) view.View

func NewSignupForm

func NewSignupForm(buttonText, class, errorMessageClass, successMessageClass string, confirmationURL, redirectURL view.URL) *view.Form

confirmationPage must have the confirmation code as first URL parameter

func OfSession

func OfSession(session *view.Session, resultRef interface{}) (found bool, err error)

func WithEmail

func WithEmail(addr string, resultRef interface{}) (found bool, err error)

func WithID

func WithID(id string, resultRef interface{}) (found bool, err error)

Types

type Auth

type Auth struct {
	LoginURL view.URL
}

func (*Auth) Authenticate

func (self *Auth) Authenticate(ctx *view.Context) (ok bool, err error)

type Configuration

type Configuration struct {
	ConfirmationMessage ConfirmationMessage
	CollectionName      string
	Collection          *mongo.Collection
}

func (*Configuration) Close

func (self *Configuration) Close() error

func (*Configuration) Init

func (self *Configuration) Init() error

func (*Configuration) Name

func (self *Configuration) Name() string

type ConfirmationMessage

type ConfirmationMessage struct {
	EmailSubject string
	EmailMessage string
	Sent         string
}

type EmailIdentity

type EmailIdentity struct {
	//	mongo.SubDocumentBase
	Address          model.Email
	Description      model.String
	Confirmed        model.DateTime
	ConfirmationCode model.String
}

func (*EmailIdentity) LinkContent

func (self *EmailIdentity) LinkContent(ctx *view.Context) view.View

func (*EmailIdentity) LinkRel

func (self *EmailIdentity) LinkRel(ctx *view.Context) string

func (*EmailIdentity) LinkTitle

func (self *EmailIdentity) LinkTitle(ctx *view.Context) string

func (*EmailIdentity) MailtoURL

func (self *EmailIdentity) MailtoURL() string

func (*EmailIdentity) SendConfirmationEmail

func (self *EmailIdentity) SendConfirmationEmail(ctx *view.Context, confirmationURL view.URL) <-chan error

EmailIdentity has to be saved after a successful call because the confirmation code could have changed confirmationPage needs to be a page with one URL parameter

func (*EmailIdentity) URL

func (self *EmailIdentity) URL(ctx *view.Context) string

type EmailPasswordFormModel

type EmailPasswordFormModel struct {
	Email             model.Email `model:"required" view:"size=20"`
	PasswordFormModel `bson:",inline" view:"size=20"`
}

type FacebookIdentity

type FacebookIdentity struct {
	ID          model.String
	Name        model.String `view:"placeholder=your facebook url"`
	Confirmed   model.DateTime
	AccessToken model.String
}

func (*FacebookIdentity) LinkContent

func (self *FacebookIdentity) LinkContent(ctx *view.Context) view.View

func (*FacebookIdentity) LinkRel

func (self *FacebookIdentity) LinkRel(ctx *view.Context) string

func (*FacebookIdentity) LinkTitle

func (self *FacebookIdentity) LinkTitle(ctx *view.Context) string

func (*FacebookIdentity) NameOrID

func (self *FacebookIdentity) NameOrID() string

func (*FacebookIdentity) ProfileImageURL

func (self *FacebookIdentity) ProfileImageURL() string

func (*FacebookIdentity) ProfileURL

func (self *FacebookIdentity) ProfileURL() string

func (*FacebookIdentity) URL

func (self *FacebookIdentity) URL(ctx *view.Context) string

type GitHubIdentity

type GitHubIdentity struct {
	ID          model.String
	Name        model.String
	Confirmed   model.DateTime
	AccessToken model.String
}

func (*GitHubIdentity) LinkContent

func (self *GitHubIdentity) LinkContent(ctx *view.Context) view.View

func (*GitHubIdentity) LinkRel

func (self *GitHubIdentity) LinkRel(ctx *view.Context) string

func (*GitHubIdentity) LinkTitle

func (self *GitHubIdentity) LinkTitle(ctx *view.Context) string

func (*GitHubIdentity) ProfileURL

func (self *GitHubIdentity) ProfileURL() string

func (*GitHubIdentity) URL

func (self *GitHubIdentity) URL(ctx *view.Context) string

type LinkedInIdentity

type LinkedInIdentity struct {
	ID          model.String
	Name        model.String
	Confirmed   model.DateTime
	AccessToken model.String
}

func (*LinkedInIdentity) LinkContent

func (self *LinkedInIdentity) LinkContent(ctx *view.Context) view.View

func (*LinkedInIdentity) LinkRel

func (self *LinkedInIdentity) LinkRel(ctx *view.Context) string

func (*LinkedInIdentity) LinkTitle

func (self *LinkedInIdentity) LinkTitle(ctx *view.Context) string

func (*LinkedInIdentity) ProfileURL

func (self *LinkedInIdentity) ProfileURL() string

func (*LinkedInIdentity) URL

func (self *LinkedInIdentity) URL(ctx *view.Context) string

type LoginFormModel

type LoginFormModel struct {
	Email    model.Email    `model:"required" view:"size=20"`
	Password model.Password `model:"required" view:"size=20"`
}

type PasswordFormModel

type PasswordFormModel struct {
	Password1 model.Password `model:"minlen=6" view:"label=Password|size=20"`
	Password2 model.Password `view:"label=Repeat password|size=20"`
}

func (*PasswordFormModel) Validate

func (self *PasswordFormModel) Validate(metaData *model.MetaData) error

type PhoneNumber

type PhoneNumber struct {
	Number      model.Phone
	Description model.String
}

type SkypeIdentity

type SkypeIdentity struct {
	ID        model.String
	Confirmed model.DateTime
}

func (*SkypeIdentity) CallURL

func (self *SkypeIdentity) CallURL() string

func (*SkypeIdentity) LinkContent

func (self *SkypeIdentity) LinkContent(ctx *view.Context) view.View

func (*SkypeIdentity) LinkRel

func (self *SkypeIdentity) LinkRel(ctx *view.Context) string

func (*SkypeIdentity) LinkTitle

func (self *SkypeIdentity) LinkTitle(ctx *view.Context) string

func (*SkypeIdentity) URL

func (self *SkypeIdentity) URL(ctx *view.Context) string

type TwitterIdentity

type TwitterIdentity struct {
	ID          model.String
	Name        model.String
	Confirmed   model.DateTime
	AccessToken model.String
}

func (*TwitterIdentity) LinkContent

func (self *TwitterIdentity) LinkContent(ctx *view.Context) view.View

func (*TwitterIdentity) LinkRel

func (self *TwitterIdentity) LinkRel(ctx *view.Context) string

func (*TwitterIdentity) LinkTitle

func (self *TwitterIdentity) LinkTitle(ctx *view.Context) string

func (*TwitterIdentity) NameOrID

func (self *TwitterIdentity) NameOrID() string

func (*TwitterIdentity) ProfileImageURL

func (self *TwitterIdentity) ProfileImageURL() string

func (*TwitterIdentity) ProfileURL

func (self *TwitterIdentity) ProfileURL() string

func (*TwitterIdentity) URL

func (self *TwitterIdentity) URL(ctx *view.Context) string

type User

type User struct {
	mongo.DocumentBase `bson:",inline"`
	Name               modelext.Name
	Username           model.String `view:"size=20"`
	Password           model.Password
	Blocked            model.Bool
	Admin              model.Bool
	PostalAddress      modelext.PostalAddress `view:"label=Postal Address"`
	Phone              []PhoneNumber
	Web                []Website
	Email              []EmailIdentity
	Facebook           []FacebookIdentity
	Twitter            []TwitterIdentity
	LinkedIn           []LinkedInIdentity
	Xing               []XingIdentity
	GitHub             []GitHubIdentity
	Skype              []SkypeIdentity
}

func FromDocument

func FromDocument(document interface{}) (user *User)

func (*User) AddEmail

func (self *User) AddEmail(address, description string) (err error)

func (*User) AddPhone

func (self *User) AddPhone(number, description string)

func (*User) ConfirmEmailPassword

func (self *User) ConfirmEmailPassword()

func (*User) EmailConfirmed

func (self *User) EmailConfirmed(email string) bool

func (*User) EmailPasswordConfirmed

func (self *User) EmailPasswordConfirmed() bool

One email address has to be confirmed and the password must not be empty

func (*User) EmailPasswordMatch

func (self *User) EmailPasswordMatch(email, password string) bool

func (*User) FacebookIdentityConfirmed

func (self *User) FacebookIdentityConfirmed() bool

func (*User) HasEmail

func (self *User) HasEmail(address string) bool

func (*User) HasPhone

func (self *User) HasPhone(number string) bool

func (*User) IdentityConfirmed

func (self *User) IdentityConfirmed() bool

func (*User) LinkedInIdentityConfirmed

func (self *User) LinkedInIdentityConfirmed() bool

func (*User) PrimaryEmail

func (self *User) PrimaryEmail() string

func (*User) PrimaryEmailIdentity

func (self *User) PrimaryEmailIdentity() *EmailIdentity

func (*User) PrimaryFacebookIdentity

func (self *User) PrimaryFacebookIdentity() *FacebookIdentity

func (*User) PrimaryGitHubIdentity

func (self *User) PrimaryGitHubIdentity() *GitHubIdentity

func (*User) PrimaryLinkedInIdentity

func (self *User) PrimaryLinkedInIdentity() *LinkedInIdentity

func (*User) PrimaryPhone

func (self *User) PrimaryPhone() string

func (*User) PrimarySkypeIdentity

func (self *User) PrimarySkypeIdentity() *SkypeIdentity

func (*User) PrimaryTwitterIdentity

func (self *User) PrimaryTwitterIdentity() *TwitterIdentity

func (*User) PrimaryWeb

func (self *User) PrimaryWeb() string

func (*User) PrimaryXingIdentity

func (self *User) PrimaryXingIdentity() *XingIdentity

func (*User) SetEmailPassword

func (self *User) SetEmailPassword(email, password string) error

func (*User) TwitterIdentityConfirmed

func (self *User) TwitterIdentityConfirmed() bool

type Website

type Website struct {
	Url         model.Url `view:"label=URL"`
	Title       model.String
	Description model.String
}

Implements view.LinkModel

func (*Website) LinkContent

func (self *Website) LinkContent(ctx *view.Context) view.View

func (*Website) LinkRel

func (self *Website) LinkRel(ctx *view.Context) string

func (*Website) LinkTitle

func (self *Website) LinkTitle(ctx *view.Context) string

func (*Website) URL

func (self *Website) URL(ctx *view.Context) string

type XingIdentity

type XingIdentity struct {
	ID model.String
}

func (*XingIdentity) LinkContent

func (self *XingIdentity) LinkContent(ctx *view.Context) view.View

func (*XingIdentity) LinkRel

func (self *XingIdentity) LinkRel(ctx *view.Context) string

func (*XingIdentity) LinkTitle

func (self *XingIdentity) LinkTitle(ctx *view.Context) string

func (*XingIdentity) ProfileURL

func (self *XingIdentity) ProfileURL() string

func (*XingIdentity) URL

func (self *XingIdentity) URL(ctx *view.Context) string

Jump to

Keyboard shortcuts

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