github.com/spline-fu/mattermost-server@v4.10.10+incompatible/model/token.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import "net/http"
     7  
     8  const (
     9  	TOKEN_SIZE            = 64
    10  	MAX_TOKEN_EXIPRY_TIME = 1000 * 60 * 60 * 24 // 24 hour
    11  	TOKEN_TYPE_OAUTH      = "oauth"
    12  )
    13  
    14  type Token struct {
    15  	Token    string
    16  	CreateAt int64
    17  	Type     string
    18  	Extra    string
    19  }
    20  
    21  func NewToken(tokentype, extra string) *Token {
    22  	return &Token{
    23  		Token:    NewRandomString(TOKEN_SIZE),
    24  		CreateAt: GetMillis(),
    25  		Type:     tokentype,
    26  		Extra:    extra,
    27  	}
    28  }
    29  
    30  func (t *Token) IsValid() *AppError {
    31  	if len(t.Token) != TOKEN_SIZE {
    32  		return NewAppError("Token.IsValid", "model.token.is_valid.size", nil, "", http.StatusInternalServerError)
    33  	}
    34  
    35  	if t.CreateAt == 0 {
    36  		return NewAppError("Token.IsValid", "model.token.is_valid.expiry", nil, "", http.StatusInternalServerError)
    37  	}
    38  
    39  	return nil
    40  }