-
Notifications
You must be signed in to change notification settings - Fork 2
/
user.go
36 lines (31 loc) · 927 Bytes
/
user.go
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
30
31
32
33
34
35
36
package basicserver
import (
"math/rand"
"time"
"github.com/globalsign/mgo/bson"
)
// User is an user data entity:
//
// `ID` user uid
// `Email` user email
// `Password` encrypted password
// `RecoveryCode` optional recovery code for password reset
// `LastLoginAt` time at which last login happened
//
type User struct {
ID bson.ObjectId `bson:"_id" json:"id"`
Email string `bson:"email"`
Password string `bson:"password"`
RecoveryCode string `bson:"recovery_code"`
LastLoginAt time.Time `bson:"last_login_at"`
}
var codeLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var codeLettersLength = len(codeLetters)
// GenerateRecoveryCode creates a recovery code
func (user *User) GenerateRecoveryCode() string {
b := make([]rune, 12)
for i := range b {
b[i] = codeLetters[rand.Intn(codeLettersLength)]
}
return string(b)
}