You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
683 B
Go
33 lines
683 B
Go
package auth
|
|
|
|
import (
|
|
"cls-server/internal/domain/admin"
|
|
"cls-server/internal/domain/auth"
|
|
"cls-server/pkg/xorm_engine"
|
|
"errors"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
type AuthRepositoryORM struct {
|
|
engine *xorm_engine.Engine
|
|
}
|
|
|
|
var _ auth.AuthRepository = (*AuthRepositoryORM)(nil)
|
|
|
|
func NewAuthRepositoryORM(db *xorm_engine.Engine) auth.AuthRepository {
|
|
return &AuthRepositoryORM{
|
|
engine: db,
|
|
}
|
|
}
|
|
func (a AuthRepositoryORM) GetAdminByUsername(username string) (*admin.Admin, error) {
|
|
u := &admin.Admin{}
|
|
has, err := a.engine.Where(builder.Eq{"username": username}).Get(u)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !has {
|
|
return nil, errors.New("用户不存在")
|
|
}
|
|
return u, nil
|
|
}
|