err:=db.QueryRow("SELECT username, password, email, created, status FROM users WHERE id = ?",id).Scan(&u.Username,&u.HashedPass,&u.Email,&u.Created,&u.Status)
switch{
caseerr==sql.ErrNoRows:
returnnil,ErrUserNotFound
caseerr!=nil:
log.Error("Couldn't SELECT user password: %v",err)
returnnil,err
}
returnu,nil
}
// IsUserSilenced returns true if the user account associated with id is
err:=db.QueryRow("SELECT id, password, email, created, status FROM users WHERE username = ?",username).Scan(&u.ID,&u.HashedPass,&u.Email,&u.Created,&u.Status)
switch{
caseerr==sql.ErrNoRows:
// Check if they've entered the wrong, unnormalized username
username=getSlug(username,"")
ifusername!=u.Username{
err=db.QueryRow("SELECT id FROM users WHERE username = ? LIMIT 1",username).Scan(&u.ID)
iferr==nil{
returndb.GetUserForAuth(username)
}
}
returnnil,ErrUserNotFound
caseerr!=nil:
log.Error("Couldn't SELECT user password: %v",err)
err:=db.QueryRow("SELECT username, one_time FROM accesstokens LEFT JOIN users ON user_id = id WHERE token LIKE ? AND (expires IS NULL OR expires > "+db.now()+")",t).Scan(&username,&oneTime)
err:=db.QueryRow("SELECT user_id, username, one_time FROM accesstokens LEFT JOIN users ON user_id = id WHERE token LIKE ? AND (expires IS NULL OR expires > "+db.now()+")",t).Scan(&userID,&username,&oneTime)
err:=db.QueryRow("SELECT user_id, sudo, one_time FROM accesstokens WHERE token LIKE ? AND (expires IS NULL OR expires > "+db.now()+")",t).Scan(&userID,&sudo,&oneTime)
err:=db.QueryRow("SELECT token FROM accesstokens WHERE user_id = ? AND (expires IS NULL OR expires > "+db.now()+") ORDER BY created DESC LIMIT 1",userID).Scan(&t)
switch{
caseerr==sql.ErrNoRows:
return""
caseerr!=nil:
log.Error("Failed selecting from accesstoken: %v",err)
return""
}
u,err:=uuid.Parse(t)
iferr!=nil{
return""
}
returnu.String()
}
// GetAccessToken creates a new non-expiring, valid access token for the given
log.Error("Unable to insert %s value: %v",collAttrLetterReplyTo,err)
returnerr
}
}
}
}else{
_,err=db.Exec("DELETE FROM collectionattributes WHERE collection_id = ? AND attribute = ?",collID,"email_subs")
iferr!=nil{
log.Error("Unable to delete email_subs value: %v",err)
returnerr
}
}
// Update rest of the collection data
ifq.Updates!=""{
res,err=db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions,q.Params...)
iferr!=nil{
log.Error("Unable to update collection: %v",err)
returnerr
}
}
rowsAffected,_=res.RowsAffected()
if!changed||rowsAffected==0{
// Show the correct error message if nothing was updated
vardummyint
err:=db.QueryRow("SELECT 1 FROM collections WHERE alias = ? AND owner_id = ?",alias,c.OwnerID).Scan(&dummy)
switch{
caseerr==sql.ErrNoRows:
returnErrUnauthorizedEditPost
caseerr!=nil:
log.Error("Failed selecting from collections: %v",err)
}
if!updatePass{
returnnil
}
}
ifupdatePass{
hashedPass,err:=auth.HashPass([]byte(c.Pass))
iferr!=nil{
log.Error("Unable to create hash: %s",err)
returnimpart.HTTPError{http.StatusInternalServerError,"Could not create password hash."}
}
ifdb.driverName==driverSQLite{
_,err=db.Exec("INSERT OR REPLACE INTO collectionpasswords (collection_id, password) VALUES ((SELECT id FROM collections WHERE alias = ?), ?)",alias,hashedPass)
}else{
_,err=db.Exec("INSERT INTO collectionpasswords (collection_id, password) VALUES ((SELECT id FROM collections WHERE alias = ?), ?) "+db.upsert("collection_id")+" password = ?",alias,hashedPass,hashedPass)
row=db.QueryRow("SELECT "+postCols+", (SELECT username FROM users WHERE users.id = posts.owner_id) AS username FROM posts WHERE "+where+" LIMIT 1",params...)
rows,err:=db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? "+pinnedCondition+" "+timeCondition+" ORDER BY created "+order+limitStr,collID)
rows,err=db.Query("SELECT id FROM posts WHERE collection_id = ? AND LOWER(content) regexp ? "+timeCondition+" ORDER BY created "+order,collID,`.*#`+strings.ToLower(tag)+`\b.*`)
}else{
rows,err=db.Query("SELECT id FROM posts WHERE collection_id = ? AND LOWER(content) RLIKE ? "+timeCondition+" ORDER BY created "+order,collID,"#"+strings.ToLower(tag)+"[[:>:]]")
rows,err=db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? AND LOWER(content) regexp ? "+timeCondition+" ORDER BY created "+order+limitStr,collID,`.*#`+strings.ToLower(tag)+`\b.*`)
}else{
rows,err=db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? AND LOWER(content) RLIKE ? "+timeCondition+" ORDER BY created "+order+limitStr,collID,"#"+strings.ToLower(tag)+"[[:>:]]")
rows,err:=db.Query("SELECT actor_id, inbox, shared_inbox FROM remotefollows f INNER JOIN remoteusers u ON f.remote_user_id = u.id WHERE collection_id = ?",c.ID)
iferr!=nil{
log.Error("Failed selecting from followers: %v",err)
// FIXME: sqlite-backed instances don't include ellipsis on truncated titles
timeCondition:=""
if!includeFuture{
timeCondition="AND created <= "+db.now()
}
rows,err:=db.Query("SELECT id, slug, title, "+db.clip("content",80)+", pinned_position FROM posts WHERE collection_id = ? AND pinned_position IS NOT NULL "+timeCondition+" ORDER BY pinned_position ASC",coll.ID)
returnnil,impart.HTTPError{http.StatusInternalServerError,"You don't seem to have any blogs; they might've moved to another account. Try logging out and logging into your other account."}
rows,err:=db.Query("SELECT p.id, p.slug, p.view_count, p.title, p.content, c.alias, c.title, c.description, c.view_count FROM posts p LEFT JOIN collections c ON p.collection_id = c.id WHERE p.owner_id = ?"+where+" ORDER BY p.view_count DESC, created DESC LIMIT 25",params...)
iferr!=nil{
log.Error("Failed selecting from posts: %v",err)
returnnil,impart.HTTPError{http.StatusInternalServerError,"Couldn't retrieve user top posts."}
rows,err:=db.Query("SELECT id, view_count, title, language, created, updated, content FROM posts WHERE owner_id = ? AND collection_id IS NULL ORDER BY created DESC"+limitStr,u.ID)
iferr!=nil{
log.Error("Failed selecting from posts: %v",err)
returnnil,impart.HTTPError{http.StatusInternalServerError,"Couldn't retrieve user anonymous posts."}
rows,err:=db.Query("SELECT p.id, p.slug, p.view_count, p.title, p.created, p.updated, p.content, p.text_appearance, p.language, p.rtl, c.alias, c.title, c.description, c.view_count FROM posts p LEFT JOIN collections c ON collection_id = c.id WHERE p.owner_id = ? ORDER BY created ASC",u.ID)
iferr!=nil{
log.Error("Failed selecting from posts: %v",err)
returnnil,impart.HTTPError{http.StatusInternalServerError,"Couldn't retrieve user posts."}
err:=db.QueryRow("SELECT id, max_uses, created, expires, inactive FROM userinvites WHERE id = ?",id).Scan(&i.ID,&i.MaxUses,&i.Created,&i.Expires,&i.Inactive)
_,err:=db.ExecContext(ctx,`DELETE FROM oauth_users WHERE user_id = ? AND provider = ? AND client_id = ? AND remote_user_id = ?`,userID,provider,clientID,remoteUserID)