Skip to content
Snippets Groups Projects
Commit 51a5a85f7408 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

db: add users.created_at column

parent 5395fb673155
No related branches found
No related tags found
No related merge requests found
// Code generated by go-bindata. DO NOT EDIT.
// Code generated by go-bindata. (@generated) DO NOT EDIT.
// Package migration generated by go-bindata.// sources:
// Code generated for package migration by go-bindata DO NOT EDIT. (@generated)
// sources:
// scripts/0001_init.up.sql
// scripts/0002_add_users_table.up.sql
// scripts/0003_add_user_apikey.up.sql
......@@ -13,6 +12,7 @@
// scripts/0008_email_status.up.sql
// scripts/0009_email_error_tracking.up.sql
// scripts/0010_render_logs.up.sql
// scripts/0011_user_created_at.up.sql
package migration
import (
......@@ -30,7 +30,7 @@
func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %v", name, err)
}
var buf bytes.Buffer
......@@ -38,7 +38,7 @@
clErr := gz.Close()
if err != nil {
return nil, fmt.Errorf("read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %v", name, err)
}
if clErr != nil {
return nil, err
......@@ -74,7 +74,7 @@
return fi.mode
}
// ModTime return file modify time
// Mode return file modify time
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
......@@ -289,7 +289,27 @@
return a, nil
}
var __0011_user_created_atUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4c\xc9\x41\x0e\x82\x30\x10\x05\xd0\x3d\xa7\xf8\x3b\xe0\x0c\xae\x46\x3b\xc4\x26\x6d\xc7\xd8\xdf\x60\xdc\x18\x82\xbd\x00\x94\xfb\x9b\xb8\x62\xfb\x9e\x04\xea\x13\x94\x6b\x50\x1c\x7b\xdd\xf6\x0e\x00\xc4\x39\xdc\x2c\x94\x98\xe0\x27\x24\x23\xf4\xe5\x33\x33\xd6\xad\x2e\xad\x7e\x3f\x4b\x03\x7d\xd4\x4c\x89\x0f\xcc\x9e\x77\x2b\xfc\x0b\xde\x96\x14\x4e\x27\x29\x81\x18\x92\xcd\xc3\x08\x39\x5f\x7f\xb4\xb5\x1f\x2f\xdd\x2f\x00\x00\xff\xff\xd3\xfa\xef\x12\x7a\x00\x00\x00")
func _0011_user_created_atUpSqlBytes() ([]byte, error) {
return bindataRead(
__0011_user_created_atUpSql,
"0011_user_created_at.up.sql",
)
}
func _0011_user_created_atUpSql() (*asset, error) {
bytes, err := _0011_user_created_atUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "0011_user_created_at.up.sql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
......@@ -292,9 +312,9 @@
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
......@@ -319,8 +339,8 @@
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
......@@ -351,6 +371,7 @@
"0008_email_status.up.sql": _0008_email_statusUpSql,
"0009_email_error_tracking.up.sql": _0009_email_error_trackingUpSql,
"0010_render_logs.up.sql": _0010_render_logsUpSql,
"0011_user_created_at.up.sql": _0011_user_created_atUpSql,
}
// AssetDir returns the file names below a certain
......@@ -364,8 +385,8 @@
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("nonexistent") would return an error
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
......@@ -368,9 +389,9 @@
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
canonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(canonicalName, "/")
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
......@@ -404,6 +425,7 @@
"0008_email_status.up.sql": &bintree{_0008_email_statusUpSql, map[string]*bintree{}},
"0009_email_error_tracking.up.sql": &bintree{_0009_email_error_trackingUpSql, map[string]*bintree{}},
"0010_render_logs.up.sql": &bintree{_0010_render_logsUpSql, map[string]*bintree{}},
"0011_user_created_at.up.sql": &bintree{_0011_user_created_atUpSql, map[string]*bintree{}},
}}
// RestoreAsset restores an asset under the given directory
......@@ -449,6 +471,6 @@
}
func _filePath(dir, name string) string {
canonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...)
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}
ALTER TABLE users
ADD COLUMN IF NOT EXISTS created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc');
......@@ -253,6 +253,9 @@
// UserDBUsernameColumn is the name of the column containing field "Username" data
UserDBUsernameColumn = "username"
// UserDBCreatedAtColumn is the name of the column containing field "CreatedAt" data
UserDBCreatedAtColumn = "created_at"
// UserDBPasswordColumn is the name of the column containing field "Password" data
UserDBPasswordColumn = "password"
......@@ -406,6 +409,7 @@
UserDBFirstnameColumn,
UserDBIsAdminColumn,
UserDBLastnameColumn,
UserDBCreatedAtColumn,
UserDBPasswordColumn,
}
......@@ -800,6 +804,8 @@
values[i] = s.Lastname
case "username":
values[i] = s.Username
case "created_at":
values[i] = s.CreatedAt
case "password":
values[i] = s.Password
}
......
package models
import "golang.org/x/crypto/bcrypt"
import (
"time"
"golang.org/x/crypto/bcrypt"
)
// UserDB is a user stored in the database
// dbtable:"users" dbpkey:"username"
type UserDB struct {
Userinfo
......@@ -4,10 +8,11 @@
// UserDB is a user stored in the database
// dbtable:"users" dbpkey:"username"
type UserDB struct {
Userinfo
Password string `json:"-" db:"password"`
CreatedAt time.Time `db:"created_at"`
Password string `json:"-" db:"password"`
}
func (user *UserDB) SetPassword(password string) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment