|
@ -16,11 +16,11 @@ import ( |
|
|
|
|
|
|
|
|
type usersServer struct { |
|
|
type usersServer struct { |
|
|
proto.UsersServer |
|
|
proto.UsersServer |
|
|
secret *string |
|
|
|
|
|
|
|
|
secret string |
|
|
db *gorm.DB |
|
|
db *gorm.DB |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewUsersServer(secret *string, db *gorm.DB) proto.UsersServer { |
|
|
|
|
|
|
|
|
func NewUsersServer(secret string, db *gorm.DB) proto.UsersServer { |
|
|
db.AutoMigrate(&models.User{}, &models.Role{}, &models.Session{}, &models.PasswordToken{}) |
|
|
db.AutoMigrate(&models.User{}, &models.Role{}, &models.Session{}, &models.PasswordToken{}) |
|
|
return &usersServer{ |
|
|
return &usersServer{ |
|
|
secret: secret, |
|
|
secret: secret, |
|
@ -124,7 +124,7 @@ func (m *usersServer) Logout(ctx context.Context, in *proto.LogoutRequest) (*pro |
|
|
|
|
|
|
|
|
func (m *usersServer) Authorize(ctx context.Context, in *proto.AuthorizeRequest) (*proto.AuthorizeResponse, error) { |
|
|
func (m *usersServer) Authorize(ctx context.Context, in *proto.AuthorizeRequest) (*proto.AuthorizeResponse, error) { |
|
|
// Make sure the secrets match.
|
|
|
// Make sure the secrets match.
|
|
|
if in.Secret != *m.secret { |
|
|
|
|
|
|
|
|
if in.Secret != m.secret { |
|
|
return nil, errors.New("Secrets do not match.") |
|
|
return nil, errors.New("Secrets do not match.") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -233,7 +233,7 @@ func (m *usersServer) ChangePassword(ctx context.Context, in *proto.ChangePasswo |
|
|
|
|
|
|
|
|
func (m *usersServer) ListRoles(ctx context.Context, in *proto.ListRolesRequest) (*proto.ListRolesResponse, error) { |
|
|
func (m *usersServer) ListRoles(ctx context.Context, in *proto.ListRolesRequest) (*proto.ListRolesResponse, error) { |
|
|
// Make sure the secrets match.
|
|
|
// Make sure the secrets match.
|
|
|
if in.Secret != *m.secret { |
|
|
|
|
|
|
|
|
if in.Secret != m.secret { |
|
|
return nil, errors.New("Secrets do not match.") |
|
|
return nil, errors.New("Secrets do not match.") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -256,7 +256,7 @@ func (m *usersServer) ListRoles(ctx context.Context, in *proto.ListRolesRequest) |
|
|
|
|
|
|
|
|
func (m *usersServer) SetRoles(ctx context.Context, in *proto.SetRolesRequest) (*proto.SetRolesResponse, error) { |
|
|
func (m *usersServer) SetRoles(ctx context.Context, in *proto.SetRolesRequest) (*proto.SetRolesResponse, error) { |
|
|
// Make sure the secrets match.
|
|
|
// Make sure the secrets match.
|
|
|
if in.Secret != *m.secret { |
|
|
|
|
|
|
|
|
if in.Secret != m.secret { |
|
|
return nil, errors.New("Secrets do not match.") |
|
|
return nil, errors.New("Secrets do not match.") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|