示例#1
0
func CreateUser(email, password string) (*User, error) {
	rd := pool.Get()
	defer rd.Close()

	exists, err := redis.Bool(rd.Do("EXISTS", Config.UserNamespace+email))

	if exists {
		return nil, fmt.Errorf("that account is already registered")
	} else if err != nil {
		return nil, err
	}

	// Create a token
	hash, err := abdi.Hash(password)
	if err != nil {
		return nil, err
	}
	user := User{
		Email:      email,
		HashedPass: hash,
	}

	data, err := json.Marshal(user)
	if err != nil {
		return nil, err
	}

	_, err = rd.Do("SET", Config.UserNamespace+email, data)
	if err != nil {
		return nil, err
	}
	return &user, nil
}
示例#2
0
文件: user.go 项目: fortytw2/eden
// CreateUser creates a new, validated user
func CreateUser(username string, email string, password string) (user *User, err error) {
	var hash string
	hash, err = abdi.Hash(password)
	if err != nil {
		return
	}

	user = &User{
		Username:     username,
		Email:        email,
		PasswordHash: hash,
		Admin:        false,
		Confirmed:    false,
	}

	return
}
示例#3
0
文件: auth.go 项目: ds0nt/markdown
// RegisterAccount takes email/password
// gets redis connection
// returns error if existing user in redis
// hashes password
func Register(email, password string) (*User, error) {
	// Get redis connection
	rd := pool.Get()
	defer rd.Close()

	// Test existing
	exists, err := redis.Bool(rd.Do("EXISTS", conf.UserNamespace+email))
	if err != nil {
		panic(err)
	} else if exists {
		return nil, fmt.Errorf("account conflict")
	}

	// Hash password
	hash, err := abdi.Hash(password)
	if err != nil {
		return nil, err
	}

	user := User{
		Email:    email,
		Password: hash,
	}

	// json marshal user
	data, err := json.Marshal(user)
	if err != nil {
		return nil, err
	}

	// redis set users:email = json user
	_, err = rd.Do("SET", conf.UserNamespace+email, data)
	if err != nil {
		return nil, err
	}
	return &user, nil
}