forked from jason/cpolis
Show error messages in UI if something goes wrong
This commit is contained in:
@ -2,6 +2,7 @@ package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
@ -10,9 +11,14 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var ErrUnsupportedFormat error = image.ErrFormat // used internally by imaging
|
||||
|
||||
func SaveImage(c *Config, src io.Reader) (string, error) {
|
||||
img, err := imaging.Decode(src, imaging.AutoOrientation(true))
|
||||
if err != nil {
|
||||
if err == ErrUnsupportedFormat {
|
||||
return "", ErrUnsupportedFormat
|
||||
}
|
||||
return "", fmt.Errorf("error decoding image: %v", err)
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ func (db *DB) AddUser(u *User, pass string) (int64, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (db *DB) GetID(userName string) (int64, bool) {
|
||||
func (db *DB) GetID(userName string) int64 {
|
||||
var id int64
|
||||
|
||||
query := `
|
||||
@ -56,11 +56,11 @@ func (db *DB) GetID(userName string) (int64, bool) {
|
||||
WHERE username = ?
|
||||
`
|
||||
row := db.QueryRow(query, userName)
|
||||
if err := row.Scan(&id); err != nil {
|
||||
return 0, false
|
||||
if err := row.Scan(&id); err != nil { // seems like the only possible error is ErrNoRows
|
||||
return 0
|
||||
}
|
||||
|
||||
return id, true
|
||||
return id
|
||||
}
|
||||
|
||||
func (db *DB) CheckPassword(id int64, pass string) error {
|
||||
@ -146,7 +146,7 @@ func (db *DB) GetUser(id int64) (*User, error) {
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (db *DB) UpdateOwnAttributes(id int64, user, first, last, oldPass, newPass, newPass2 string) error {
|
||||
func (db *DB) UpdateOwnUserAttributes(id int64, user, first, last, oldPass, newPass, newPass2 string) error {
|
||||
passwordEmpty := true
|
||||
if len(newPass) > 0 || len(newPass2) > 0 {
|
||||
if newPass != newPass2 {
|
||||
@ -228,7 +228,7 @@ func (db *DB) AddFirstUser(u *User, pass string) (int64, error) {
|
||||
if err = tx.Commit(); err != nil {
|
||||
return 0, fmt.Errorf("error committing transaction: %v", err)
|
||||
}
|
||||
return 2, nil
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
||||
|
Reference in New Issue
Block a user