Compare commits
No commits in common. "2c0b4878f44b9fdf4661d789d2e08c2d298f8440" and "a8fc28af36592110a47f1d5fc229841f940bc6dc" have entirely different histories.
2c0b4878f4
...
a8fc28af36
@ -140,15 +140,11 @@ func LoadArticleList(filename string) (*ArticleList, error) {
|
|||||||
return nil, fmt.Errorf("error opening key file: %v", err)
|
return nil, fmt.Errorf("error opening key file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
articleList := initArticleList()
|
articleList := NewArticleList()
|
||||||
if err = gob.NewDecoder(file).Decode(&articleList.articles); err != nil {
|
if err = gob.NewDecoder(file).Decode(&articleList.articles); err != nil {
|
||||||
return nil, fmt.Errorf("error decoding key: %v", err)
|
return nil, fmt.Errorf("error decoding key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
articleList.wg.Add(1)
|
|
||||||
go articleList.start()
|
|
||||||
articleList.wg.Wait()
|
|
||||||
|
|
||||||
return articleList, nil
|
return articleList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,14 +189,10 @@ func LoadTagList(filename string) (*TagList, error) {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
tagList := initTagList()
|
tagList := NewTagList()
|
||||||
if err = gob.NewDecoder(file).Decode(&tagList.tags); err != nil {
|
if err = gob.NewDecoder(file).Decode(&tagList.tags); err != nil {
|
||||||
return nil, fmt.Errorf("error decoding key: %v", err)
|
return nil, fmt.Errorf("error decoding key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagList.wg.Add(1)
|
|
||||||
go tagList.start()
|
|
||||||
tagList.wg.Wait()
|
|
||||||
|
|
||||||
return tagList, nil
|
return tagList, nil
|
||||||
}
|
}
|
||||||
|
@ -89,19 +89,12 @@ func (db *DB) CheckPassword(id int64, pass string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) ChangePassword(id int64, oldPass, newPass string) error {
|
func (db *DB) ChangePassword(id int64, oldPass, newPass string) error {
|
||||||
tx, err := db.Begin()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error starting transaction: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := db.CheckPassword(id, oldPass); err != nil {
|
if err := db.CheckPassword(id, oldPass); err != nil {
|
||||||
tx.Rollback()
|
|
||||||
return fmt.Errorf("error checking password: %v", err)
|
return fmt.Errorf("error checking password: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newHashedPass, err := bcrypt.GenerateFromPassword([]byte(newPass), bcrypt.DefaultCost)
|
newHashedPass, err := bcrypt.GenerateFromPassword([]byte(newPass), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
|
||||||
return fmt.Errorf("error creating password hash: %v", err)
|
return fmt.Errorf("error creating password hash: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,14 +104,9 @@ func (db *DB) ChangePassword(id int64, oldPass, newPass string) error {
|
|||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`
|
`
|
||||||
if _, err = db.Exec(query, string(newHashedPass), id); err != nil {
|
if _, err = db.Exec(query, string(newHashedPass), id); err != nil {
|
||||||
tx.Rollback()
|
|
||||||
return fmt.Errorf("error updating password in DB: %v", err)
|
return fmt.Errorf("error updating password in DB: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = tx.Commit(); err != nil {
|
|
||||||
return fmt.Errorf("error committing transaction: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,17 +70,17 @@ func LoadChannel(filename string) (*Channel, error) {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
channel := initChannel()
|
||||||
|
channel.wg.Add(1)
|
||||||
|
go channel.start()
|
||||||
|
channel.wg.Wait()
|
||||||
|
|
||||||
tmpChannel := new(rss.Channel)
|
tmpChannel := new(rss.Channel)
|
||||||
if err = gob.NewDecoder(file).Decode(tmpChannel); err != nil {
|
if err = gob.NewDecoder(file).Decode(tmpChannel); err != nil {
|
||||||
return nil, fmt.Errorf("error decoding channel from file %v: %v", filename, err)
|
return nil, fmt.Errorf("error decoding channel from file %v: %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := initChannel()
|
|
||||||
channel.wg.Add(1)
|
|
||||||
go channel.start()
|
|
||||||
channel.wg.Wait()
|
|
||||||
channel.Set(*tmpChannel)
|
channel.Set(*tmpChannel)
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user