Skip to content

Commit

Permalink
feat: add AccessToken and Token model
Browse files Browse the repository at this point in the history
  • Loading branch information
hiwatee committed Jan 6, 2021
1 parent 29adbb3 commit 4cc0550
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 0 additions & 4 deletions controllers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"encoding/json"
"fmt"
"log"

beego "github.com/beego/beego/v2/server/web"
Expand Down Expand Up @@ -43,9 +42,6 @@ func (c *LoginController) Login() {
log.Fatal(err)
}

fmt.Printf("id: %v", v.Email)
// eメールでユーザーを検索 | なかったら404

// パスワード照合 | 間違ったら403

// set_cookie
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func init() {
orm.RegisterModel(
new(models.User),
new(models.Profile),
new(models.Token),
new(models.AccessToken),
)
orm.RunSyncdb("default", false, true)
}
Expand Down
26 changes: 21 additions & 5 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"reflect"
"strings"
"time"

"github.com/beego/beego/v2/client/orm"
"golang.org/x/crypto/bcrypt"
Expand All @@ -19,6 +20,14 @@ type User struct {
TimeStamp
}

type UserLoginBody struct {
Email string `orm:"size(128)" json:"email"`
Password string `orm:"size(128)" json:"-"`
}

type UserInfoBody struct {
Name string `orm:"size(128)" json:"name" example:"山田太郎"`
}
type Profile struct {
Id int64 `orm:"auto" json:"id,omitempty"`
ProfileBody
Expand All @@ -29,13 +38,20 @@ type ProfileBody struct {
Age int64 `orm:"size(128)" json:"age"`
}

type UserLoginBody struct {
Email string `orm:"size(128)" json:"email"`
Password string `orm:"size(128)" json:"-"`
type Token struct {
Id int64 `orm:"auto" json:"id,omitempty"`
Token string `json:"token"`
User *User `orm:"rel(one)" json:"user"` // OneToOne relation
TimeStamp
ExpiredAt time.Time `json:"-"`
}

type UserInfoBody struct {
Name string `orm:"size(128)" json:"name" example:"山田太郎"`
type AccessToken struct {
Id int64 `orm:"auto" json:"id,omitempty"`
Token string `json:"token"`
User *User `orm:"rel(one)" json:"user"` // OneToOne relation
TimeStamp
ExpiredAt time.Time `json:"-"`
}

// AddUser insert a new User into database and returns
Expand Down

0 comments on commit 4cc0550

Please sign in to comment.