Skip to content

Commit

Permalink
issue login-enabled auth token for new account validation
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Aug 30, 2022
1 parent 24ecbc1 commit d7b9bfb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
12 changes: 6 additions & 6 deletions server/db/mysql/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,12 @@ func (a *adapter) CreateDb(reset bool) error {
// Links between uploaded files and the topics, users or messages they are attached to.
if _, err = tx.Exec(
`CREATE TABLE filemsglinks(
id INT NOT NULL AUTO_INCREMENT,
createdat DATETIME(3) NOT NULL,
fileid BIGINT NOT NULL,
msgid INT,
topic CHAR(25),
userid BIGINT,
id INT NOT NULL AUTO_INCREMENT,
createdat DATETIME(3) NOT NULL,
fileid BIGINT NOT NULL,
msgid INT,
topic CHAR(25),
userid BIGINT,
PRIMARY KEY(id),
FOREIGN KEY(fileid) REFERENCES fileuploads(id) ON DELETE CASCADE,
FOREIGN KEY(msgid) REFERENCES messages(id) ON DELETE CASCADE,
Expand Down
1 change: 0 additions & 1 deletion server/hdl_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
// Check authorization: either auth information or SID must be present
uid, challenge, err := authHttpRequest(req)
if err != nil {
logs.Info.Println("File upload auth failed", err)
writeHttpResponse(decodeStoreError(err, msgID, "", now, nil), err)
return
}
Expand Down
3 changes: 2 additions & 1 deletion server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func authHttpRequest(req *http.Request) (types.Uid, []byte, error) {
decodedSecret := make([]byte, base64.StdEncoding.DecodedLen(len(secret)))
n, err := base64.StdEncoding.Decode(decodedSecret, []byte(secret))
if err != nil {
logs.Info.Println("media: invalid auth secret", authMethod, "'"+secret+"'")
return uid, nil, types.ErrMalformed
}

Expand All @@ -360,7 +361,7 @@ func authHttpRequest(req *http.Request) (types.Uid, []byte, error) {
}
uid = rec.Uid
} else {
logs.Info.Println("fileUpload: auth data is present but handler is not found", authMethod)
logs.Info.Println("media: unknown auth method", authMethod)
}
} else {
// Find the session, make sure it's appropriately authenticated.
Expand Down
3 changes: 1 addition & 2 deletions server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ func replyCreateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
// Save credentials, update tags if necessary.
tmpToken, _, _ := store.Store.GetLogicalAuthHandler("token").GenSecret(&auth.Rec{
Uid: user.Uid(),
AuthLevel: auth.LevelNone,
AuthLevel: auth.LevelAuth,
Lifetime: auth.Duration(time.Hour * 24),
Features: auth.FeatureNoLogin,
})
validated, _, err := addCreds(user.Uid(), creds, rec.Tags, s.lang, tmpToken)
if err != nil {
Expand Down

0 comments on commit d7b9bfb

Please sign in to comment.