login_access.go 2.6 KB
package domain

import "time"

//登录的平台
const (
	LoginPlatformApp string = "app"
	LoginPlatformWeb string = "web"
)

const (
	LoginPwd     = "signInPassword"
	LoginSmsCode = "signInCaptcha"
)

const (
	DeviceTypeIos     = "1"
	DeviceTypeAndroid = "2"
	DeviceTypeWeb     = "4"
)

// 登录凭证存储
type LoginAccess struct {
	LoginAccessId int64 `json:"loginAccessId"`
	UserBaseId    int64 `json:"userBaseId"`
	UserId        int64 `json:"userId"`
	// 账号
	Account string `json:"account"`
	// 对应平台
	Platform string `json:"platform"`
	// 公司id
	CompanyId int64 `json:"companyId"`
	// 组织id
	OrganizationId int64 `json:"organizationId"`
	// 登录凭证存储
	AccessToken string `json:"accessToken"`
	// 刷新登录凭证
	RefreshToken string `json:"refreshToken"`
	// 登录凭证到期时间,时间戳精度秒
	AccessExpired int64 `json:"accessExpired"`
	// 刷新登录凭证到期时间,时间戳精度秒
	RefreshExpired int64 `json:"refreshExpired"`
	// 创建时间
	CreatedTime time.Time `json:"createdTime"`
	// 更新时间
	UpdatedTime time.Time `json:"updatedTime"`
}

type LoginAccessRepository interface {
	Save(loginAccess *LoginAccess) (*LoginAccess, error)
	Remove(loginAccess *LoginAccess) (*LoginAccess, error)
	FindOne(queryOptions map[string]interface{}) (*LoginAccess, error)
	Find(queryOptions map[string]interface{}) (int64, []*LoginAccess, error)
}

func (loginAccess *LoginAccess) Identify() interface{} {
	if loginAccess.LoginAccessId == 0 {
		return nil
	}
	return loginAccess.LoginAccessId
}

func (loginAccess *LoginAccess) Update(data map[string]interface{}) error {
	if account, ok := data["account"]; ok {
		loginAccess.Account = account.(string)
	}
	if platform, ok := data["platform"]; ok {
		loginAccess.Platform = platform.(string)
	}
	if companyId, ok := data["companyId"]; ok {
		loginAccess.CompanyId = companyId.(int64)
	}
	if organizationId, ok := data["organizationId"]; ok {
		loginAccess.OrganizationId = organizationId.(int64)
	}
	if accessToken, ok := data["accessToken"]; ok {
		loginAccess.AccessToken = accessToken.(string)
	}
	if refreshToken, ok := data["refreshToken"]; ok {
		loginAccess.RefreshToken = refreshToken.(string)
	}
	if accessExpired, ok := data["accessExpired"]; ok {
		loginAccess.AccessExpired = accessExpired.(int64)
	}
	if refreshExpired, ok := data["refreshExpired"]; ok {
		loginAccess.RefreshExpired = refreshExpired.(int64)
	}
	if createdTime, ok := data["createdTime"]; ok {
		loginAccess.CreatedTime = createdTime.(time.Time)
	}
	if updatedTime, ok := data["updatedTime"]; ok {
		loginAccess.UpdatedTime = updatedTime.(time.Time)
	}
	return nil
}