Documentation ¶
Overview ¶
Package users implements an application for registering and authenticating users, including social sign ins.
Index ¶
- Constants
- Variables
- func ByEmail(email string) query.Q
- func ById(id int64) query.Q
- func ByUsername(username string) query.Q
- func Current(ctx *app.Context) app.User
- func FindFreeUsername(ctx *app.Context, username string) string
- func FormErrors(ctx *app.Context, frm *form.Form)
- func Func(ctx *app.Context, id int64) app.User
- func Get(ctx *app.Context, id int64) (app.User, error)
- func Image(user interface{}) (string, error)
- func JSONEncode(user interface{}) ([]byte, error)
- func Normalize(s string) string
- func SetType(val interface{})
- func SignUpForm(ctx *app.Context, user reflect.Value) *form.Form
- type AcceptForm
- type Facebook
- type Github
- type Google
- type PasswordForm
- type SignIn
- type Twitter
- type User
Constants ¶
View Source
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" )
View Source
const ( SocialTypeFacebook = "Facebook" SocialTypeTwitter = "Twitter" SocialTypeGoogle = "Google" SocialTypeGithub = "Github" )
View Source
const COOKIE_NAME = app.USER_COOKIE_NAME
Variables ¶
View Source
var ( ErrNoPassword = i18n.NewError("this user has no password") ErrInvalidPassword = i18n.NewError("invalid password") ErrNoUser = i18n.NewError("unknown username or email") )
View Source
var ( SiteName = "" Salt = []byte("gnd.la/apps/users") PasswordResetExpiry = 24 * time.Hour SignInHandlerName = app.SignInHandlerName SignInTemplateName = "sign-in.html" SignInModalTemplateName = "sign-in-modal.html" SignUpTemplateName = "sign-up.html" ForgotTemplateName = "forgot.html" ResetTemplateName = "reset.html" SignInHandler = app.NamedHandler(app.SignInHandlerName, app.Anonymous(signInHandler)) SignInFacebookHandler = app.NamedHandler(SignInFacebookHandlerName, app.Anonymous(signInFacebookHandler)) SignInGoogleHandler = app.NamedHandler(SignInGoogleHandlerName, app.Anonymous(signInGoogleHandler)) SignInTwitterHandler = app.NamedHandler(SignInTwitterHandlerName, app.Anonymous(signInTwitterHandler)) SignInGithubHandler = app.NamedHandler(SignInGithubHandlerName, app.Anonymous(signInGithubHandler)) SignUpHandler = app.NamedHandler(SignUpHandlerName, app.Anonymous(signUpHandler)) SignOutHandler = app.NamedHandler(SignOutHandlerName, app.SignOutHandler) ForgotHandler = app.NamedHandler(ForgotHandlerName, app.Anonymous(forgotHandler)) ResetHandler = app.NamedHandler(ResetHandlerName, resetHandler) JSSignInHandler = app.NamedHandler(JSSignInHandlerName, app.Anonymous(jsSignInHandler)) JSSignInFacebookHandler = app.NamedHandler(JSSignInFacebookHandlerName, app.Anonymous(jsSignInFacebookHandler)) JSSignInGoogleHandler = app.NamedHandler(JSSignInGoogleHandlerName, app.Anonymous(jsSignInGoogleHandler)) JSSignUpHandler = app.NamedHandler(JSSignUpHandlerName, app.Anonymous(jsSignUpHandler)) FacebookChannelHandler = app.NamedHandler(FacebookChannelHandlerName, facebookChannelHandler) UserImageHandler = app.NamedHandler(ImageHandlerName, imageHandler) )
View Source
var ( ImageHandler app.Handler ImageFetcher func(ctx *app.Context, url string) (id string, format string, err error) )
View Source
var ( FacebookApp *facebook.App FacebookPermissions []string GoogleApp *google.App GoogleScopes = []string{google.PlusScope, google.EmailScope} TwitterApp *twitter.App GithubApp *github.App GithubScopes = []string{github.ScopeEmail} // AllowUserSignIn can be used to disable non-social sign ins. If it's set to // false, users will only be able to sign in using the social sign in options. // Note that setting this variable to false also sets AllowRegistration to false. AllowUserSignIn = true // AllowRegistration can be used to disable user registration. Only existing users // and social accounts will be able to log in. AllowRegistration = true SocialOrder = []string{SocialTypeFacebook, SocialTypeTwitter, SocialTypeGoogle, SocialTypeGithub} )
View Source
var (
App = app.New()
)
Functions ¶
func ByUsername ¶
ByUsername returns a query.Q which finds a user given its username.
func JSONEncode ¶
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 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 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 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:"-"` }
Click to show internal directories.
Click to hide internal directories.