Example #1
0
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
Example #2
0
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()
}