Example #1
0
func (this *UserAuth) Regist(login string, email string, cipher string) error {
	if login == "" || email == "" {
		return NewError(0, "login or email is empty")
	}

	e := (&db.ExistsBuilder{}).
		Table(this.VO.Table).
		Where(this.VO.FieldNick+"=? or "+this.VO.FieldEmail+"=?", login, email)
	if isExist, _ := e.Exists(); isExist {
		return NewError(0, "login or email exists")
	}

	_, text, err := this.PraseCipher([]byte(cipher))
	if err != nil {
		return NewError(0, err)
	}
	salt := util.Unique()
	err = this.RegistFunc(salt, this.GenerateUserToken(login, string(text), salt))
	if err != nil {
		return err
	}

	u := this.Query(login)
	if u == nil {
		return NewError(0, "user is empty")
	} else {
		this.SetUser(u)
		this.SetCookie(0)
	}

	return nil
}
Example #2
0
func (this *Upload) Build(origin *OriginFile) (*StoreFile, error) {
	filename := origin.FileName
	var name string
	arr := strings.Split(filename, ".")
	ext := ""
	if len(arr) > 1 {
		ext = strings.ToLower("." + arr[len(arr)-1])
		name = filename[0 : len(filename)-len(ext)]
	} else {
		name = filename
	}

	if !util.InStringArray(this.ExtAllowedList, ext) {
		return nil, errors.New("file " + ext + " is forbidden")
	}

	return &StoreFile{
		StorePath:  strings.TrimPrefix(this.StorePath, "/"),
		StoreName:  util.Unique(),
		Ext:        ext,
		Name:       name,
		OriginFile: origin}, nil
}
Example #3
0
	"bytes"
	"crypto/rand"
	"crypto/rsa"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"github.com/jiorry/db"
	"github.com/jiorry/libs/crypto"
	"github.com/jiorry/libs/util"
	"strconv"
	"strings"
	"time"
)

var poolRSAKey []*RSAKey
var privateSecret string = util.Unique()
var separator []byte = []byte("|")

type AuthVO struct {
	Table, FieldId, FieldNick, FieldToken, FieldEmail, FieldSalt, FieldLastSee string
	CookieKey, CookiePublicKey                                                 string
}

type RSAKey struct {
	Key       *rsa.PrivateKey
	CreatedAt time.Time
}

func init() {
	poolRSAKey = make([]*RSAKey, 3)