Documentation ¶
Overview ¶
Package users implements an application for registering and authenticating users, including social sign ins.
Index ¶
- Constants
- Variables
- func Authenticate(ctx *app.Context, usernameOrEmail string, password string) (app.User, error)
- func ByEmail(email string) query.Q
- func ById(id int64) query.Q
- func ByUsername(username string) query.Q
- func Create(ctx *app.Context, username string, email string, pw string) (app.User, error)
- func Current(ctx *app.Context) app.User
- func FacebookChannelHandler(ctx *app.Context)
- func FindFreeUsername(ctx *app.Context, username string) string
- func FormErrors(ctx *app.Context, frm *form.Form)
- func Get(ctx *app.Context, id int64) (app.User, error)
- func Image(ctx *app.Context, user interface{}) (string, error)
- func JSONEncode(ctx *app.Context, user interface{}) ([]byte, error)
- func Normalize(s string) string
- func ResetHandler(ctx *app.Context)
- func SignUpForm(ctx *app.Context, user reflect.Value) *form.Form
- func UserImageHandler(ctx *app.Context)
- type AcceptForm
- type App
- type Facebook
- type Github
- type Google
- type Options
- type PasswordForm
- type SignIn
- type SocialAccountType
- type Twitter
- type User
Constants ¶
const ( JSSignInHandlerName = "users-js-sign-in" JSSignUpHandlerName = "users-js-sign-up" JSSignInFacebookHandlerName = "users-js-sign-in-facebook" JSSignInGoogleHandlerName = "users-js-sign-in-google" SignInFacebookHandlerName = "users-sign-in-facebook" SignInGoogleHandlerName = "users-sign-in-google" SignInTwitterHandlerName = "users-sign-in-twitter" SignInGithubHandlerName = "users-sign-in-github" SignUpHandlerName = "users-sign-up" SignOutHandlerName = "users-sign-out" ForgotHandlerName = "users-forgot" ResetHandlerName = "users-reset" FacebookChannelHandlerName = "users-facebook-channel" ImageHandlerName = "users-image-handler" SignInTemplateName = "sign-in.html" SignInModalTemplateName = "sign-in-modal.html" SignUpTemplateName = "sign-up.html" ForgotTemplateName = "forgot.html" ResetTemplateName = "reset.html" )
Variables ¶
var ( ErrNoPassword = i18n.NewError("this user has no password") ErrInvalidPassword = i18n.NewError("invalid password") ErrNoUser = i18n.NewError("unknown username or email") )
var ( Salt = []byte("gondola/apps/users") PasswordResetExpiry = 24 * time.Hour SignInHandlerName = app.SignInHandlerName SignInHandler = app.Anonymous(signInHandler) SignUpHandler = app.Anonymous(signUpHandler) SignOutHandler = app.SignOutHandler ForgotHandler = app.Anonymous(forgotHandler) JSSignInHandler = app.Anonymous(jsSignInHandler) JSSignInFacebookHandler = app.Anonymous(jsSignInFacebookHandler) JSSignInGoogleHandler = app.Anonymous(jsSignInGoogleHandler) JSSignUpHandler = app.Anonymous(jsSignUpHandler) )
Functions ¶
func Authenticate ¶
Authenticate authenticates an user using her username (or email) and password. This is a conveniency function for checking the values received by a custom handler (e.g. http auth). Otherwise, it's more convenient to use the builtin sign in handler in this app, which also takes care of cookies.
func ByUsername ¶
ByUsername returns a query.Q which finds a user given its username.
func Create ¶
Create creates a new user user with the given parameters, previously checking that the given username and email aren't already in use. Note that the user is only created, no implicit sign in is performed.
func FacebookChannelHandler ¶
func ResetHandler ¶
func UserImageHandler ¶
Types ¶
type AcceptForm ¶
type AcceptForm struct {
Accept bool `form:",label=I accept the Terms of Service and the Privacy Policy"`
}
func (*AcceptForm) ValidateAccept ¶
func (f *AcceptForm) ValidateAccept() error
type App ¶
type App struct {
reusableapp.App
}
type Facebook ¶
type Facebook struct { Id string `form:"-" sql:",unique" json:"id"` Username string `form:"-" json:"username"` Name string `form:"-" json:"name"` FirstName string `form:"-" json:"first_name"` LastName string `form:"-" json:"last_name"` Email string `form:"-" json:"email"` Image string `form:"-" json:"-"` ImageFormat string `form:"-" json:"-"` ImageURL string `form:"-" json:"-"` Token string `form:"-" json:"-"` Expires time.Time `form:"-" json:"-"` }
type Github ¶
type Github struct { Id int64 `form:"-" json:"id" orm:",index,unique"` Username string `form:"-" json:"username"` Name string `form:"-" json:"name"` Company string `form:"-" json:"-"` Location string `form:"-" json:"-"` Email string `form:"-" json:"email"` Image string `form:"-" json:"-"` ImageFormat string `form:"-" json:"-"` ImageURL string `form:"-" json:"-"` Token string `form:"-" json:"-"` Expires time.Time `form:"-" json:"-"` }
type Google ¶
type Google struct { Id string `form:"-" orm:",unique" json:"id"` Email string `form:"-" orm:",unique" json:"email"` Name string `form:"-" json:"name"` LastName string `form:"-" json:"last_name"` Image string `form:"-" json:"-"` ImageFormat string `form:"-" json:"-"` ImageURL string `form:"-" json:"-"` Token string `form:"-" json:"-"` Expires time.Time `form:"-" json:"-"` Refresh string `form:"-" json:"-"` }
type Options ¶
type Options struct { // The name of the site which will appear in user visible messages // e.g. "Sign In to SiteName". SiteName string // The user type, represented by a instance of the type. // e.g. // // users{Options{UserType: MyUser{}}} UserType interface{} FacebookApp *facebook.App FacebookPermissions []string GoogleApp *google.App GoogleScopes []string TwitterApp *twitter.App GithubApp *github.App GithubScopes []string // SocialAccountsOrder can be used to set the order in which // the enabled social accounts appear on the screen, from top // to bottom. If empty, it defaults to: // // []string{SocialTypeFacebook, SocialTypeTwitter, SocialTypeGoogle, SocialTypeGithub} SocialAccountsOrder []SocialAccountType // DisableDirectSignIn can be used to disable non-social sign ins. If it's set to // true, users will only be able to sign in using the social sign in options. // Note that setting this variable to true also disables user registration, regardless // of the value of the DisableRegistration field. DisableDirectSignIn bool // DisableRegistration can be used to disable user registration. Only existing users // and social accounts will be able to log in. DisableRegistration bool }
Options specifies the options for a *UsersApp. See each field for further explanations.
type PasswordForm ¶
type PasswordForm struct { Password password.Password `form:",min_length=6,label=Password" json:"-"` ConfirmPassword password.Password `form:",optional,label=Confirm Password"` User reflect.Value `form:"-"` }
func (*PasswordForm) ValidateConfirmPassword ¶
func (f *PasswordForm) ValidateConfirmPassword() error
type SignIn ¶
type SocialAccountType ¶
type SocialAccountType string
const ( SocialAccountTypeFacebook SocialAccountType = "Facebook" SocialAccountTypeTwitter SocialAccountType = "Twitter" SocialAccountTypeGoogle SocialAccountType = "Google" SocialAccountTypeGithub SocialAccountType = "Github" )
func (SocialAccountType) String ¶
func (s SocialAccountType) String() string
type User ¶
type User struct { UserId int64 `form:"-" orm:"id,primary_key,auto_increment" json:"id"` Username string `form:",max_length=16,min_length=4,alphanumeric,label=Username" json:"username"` NormalizedUsername string `form:"-" orm:",unique" json:"-"` Email string `form:",max_length=50,label=Email" json:"-"` NormalizedEmail string `form:"-" orm:",unique" json:"-"` Password password.Password `form:"-,min_length=6,label=Password" json:"-"` Created time.Time `json:"-" form:"-"` AutomaticUsername bool `form:"-" json:"-"` Admin bool `form:"-" orm:",default=false" json:"admin"` Image string `form:"-" orm:",omitempty,nullempty" json:"-"` ImageFormat string `form:"-" orm:",omitempty,nullempty" json:"-"` }