summary refs log tree commit diff stats
path: root/auth/register.go
blob: 69e05ad600027d03c53bfda5b4a050f5db0f717d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package auth

import (
	"log"
	"strings"

	"tildegit.org/andinus/perseus/storage/sqlite3"
	"tildegit.org/andinus/perseus/user"
)

// Register takes in registration details and returns an error. If
// error doesn't equal nil then the registration was unsuccessful.
// regInfo should have username & password.
func Register(db *sqlite3.DB, regInfo map[string]string) error {
	u := user.User{}
	u.SetID(genID(64))
	u.SetUsername(strings.ToLower(regInfo["username"]))

	pass, err := hashPass(regInfo["password"])
	if err != nil {
		log.Printf("auth/register.go: %s\n",
			"hashPass func failed")
		return err
	}
	u.SetPassword(pass)

	err = u.AddUser(db)
	return err
}