예제 #1
0
파일: forms.go 프로젝트: rainycape/gondola
package users

import (
	"reflect"

	"gnd.la/app"
	"gnd.la/crypto/password"
	"gnd.la/form"
	"gnd.la/i18n"
)

var (
	ErrNoPassword      = i18n.NewError("this user has no password")
	ErrInvalidPassword = i18n.NewError("invalid password")
	ErrNoUser          = i18n.NewError("unknown username or email")
)

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 (f *PasswordForm) ValidateConfirmPassword() error {
	if f.ConfirmPassword != f.Password {
		return i18n.Errorf("passwords don't match")
	}
	if f.User.IsValid() {
		setUserValue(f.User, "Password", f.Password)
	}
	return nil
예제 #2
0
파일: funcs.go 프로젝트: rainycape/gondola
package users

import (
	"reflect"
	"strconv"
	"time"

	"gnd.la/app"
	"gnd.la/crypto/password"
	"gnd.la/i18n"
	"gnd.la/orm"
	"gnd.la/orm/driver"
)

var (
	errNoSuchUser = i18n.NewError("no such user")
)

func userFunc(ctx *app.Context, id int64) app.User {
	user, _ := Get(ctx, id)
	if user != nil {
		return user
	}
	return nil
}

// Current returns the currently authenticated user, if any.
func Current(ctx *app.Context) app.User {
	return ctx.User()
}