improve checks

This commit is contained in:
2023-04-03 08:33:31 +10:00
parent b45e276df5
commit 748f4251e1
9 changed files with 139 additions and 43 deletions

View File

@@ -12,7 +12,7 @@ type User struct {
UserId int `db:"UserId"`
RoleId int `db:"RoleId"`
UserName string `db:"UserName"`
Password string `db:"Password"`
Password string `db:"Password" json:"-"`
}
type UserRole struct {
@@ -87,7 +87,7 @@ func GetUserByID(uid uint) (User, error) {
var u User
// Query database for matching user object
err := db.QueryRowx("SELECT * FROM users INNER JOIN roles ON users.RoleId = roles.RoleId WHERE UserId=?", uid).StructScan(&u)
err := db.QueryRowx("SELECT * FROM users WHERE UserId=?", uid).StructScan(&u)
if err != nil {
return u, errors.New("user not found")
}
@@ -96,12 +96,25 @@ func GetUserByID(uid uint) (User, error) {
return u, errors.New("User not found!")
}
*/
u.PrepareGive()
//u.PrepareGive()
return u, nil
}
func GetUserByName(username string) (User, error) {
var u User
// Query database for matching user object
err := db.QueryRowx("SELECT * FROM users WHERE UserName=?", username).StructScan(&u)
if err != nil {
return u, errors.New("user not found")
}
return u, nil
}
func GetUserRoleByID(uid uint) (UserRole, error) {
var ur UserRole
@@ -118,6 +131,8 @@ func GetUserRoleByID(uid uint) (UserRole, error) {
}
/*
func (u *User) PrepareGive() {
u.Password = ""
}
*/