add Token authentication support

Added CRUD methods for Tokens.
Extend Auth Handler to check for the presence of a Bearer Authorization
header to authenticate against. If there is no header, or the token is not
valid, the Auth Handler falls back to looking for a Session.
This commit is contained in:
woodsaj
2015-01-14 16:33:34 +08:00
parent e58cd91487
commit 7b17e38f5d
8 changed files with 311 additions and 36 deletions
+9 -11
View File
@@ -23,23 +23,21 @@ type Account struct {
Company string
NextDashboardId int
UsingAccountId int64
Created time.Time
Updated time.Time
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type CreateAccountCommand struct {
Email string `json:"email" binding:"required"`
Login string `json:"login"`
Password string `json:"password" binding:"required"`
Name string `json:"name"`
Company string `json:"company"`
Salt string `json:"-"`
Result Account `json:"-"`
Email string `json:"email" binding:"required"`
Login string `json:"login"`
Password string `json:"password" binding:"required"`
Name string `json:"name"`
Company string `json:"company"`
Salt string `json:"-"`
Result Account `json:"-"`
}
type SetUsingAccountCommand struct {
+62
View File
@@ -0,0 +1,62 @@
package models
import (
"time"
)
type Token struct {
Id int64
AccountId int64 `xorm:"not null unique(uix_account_id_name)"`
Name string `xorm:"not null unique(uix_account_id_name)"`
Token string `xorm:"UNIQUE NOT NULL"`
Role RoleType `xorm:"not null"`
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type AddTokenCommand struct {
Name string `json:"name" binding:"required"`
Role RoleType `json:"role" binding:"required"`
AccountId int64 `json:"-"`
Token string `json:"-"`
Result *Token `json:"-"`
}
type UpdateTokenCommand struct {
Id int64 `json:"id"`
Name string `json:"name"`
AccountId int64 `json:"-"`
Role RoleType `json:"role"`
Result *Token `json:"-"`
}
type DeleteTokenCommand struct {
Id int64 `json:"id"`
AccountId int64 `json:"-"`
Result *Token `json:"-"`
}
// ----------------------
// QUERIES
type GetTokensQuery struct {
AccountId int64
Result []*Token
}
type GetAccountByTokenQuery struct {
Token string
Result *Account
}
// ------------------------
// DTO & Projections
type TokenDTO struct {
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
Role RoleType `json:"role"`
}