Started working on the accounts service
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/email"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
||||
accounts "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -14,55 +14,51 @@ import (
|
||||
|
||||
func NewAccountRPCImpl(db *sql.DB, hashCost int16, email *email.EmailConf, devMode bool) *AccountsServer {
|
||||
return &AccountsServer{
|
||||
Params: &controllers.AccountParams{
|
||||
HashCost: hashCost,
|
||||
},
|
||||
Params: &controllers.AccountParams{},
|
||||
SQLDriver: db,
|
||||
emailConfig: *email,
|
||||
devMode: devMode,
|
||||
hashCost: hashCost,
|
||||
}
|
||||
}
|
||||
|
||||
type AccountsServer struct {
|
||||
accounts.UnimplementedAccountsServer
|
||||
accounts.UnimplementedAccountsServiceServer
|
||||
Params *controllers.AccountParams
|
||||
SQLDriver *sql.DB
|
||||
emailConfig email.EmailConf
|
||||
// When dev mode is enabled, email won't be sent, instead the code will be returned in metadata
|
||||
devMode bool
|
||||
devMode bool
|
||||
hashCost int16
|
||||
}
|
||||
|
||||
func (a *AccountsServer) SignUp(ctx context.Context, in *accounts.AccountWithPassword) (*accounts.AccountFullWithToken, error) {
|
||||
accountCtrl := controllers.AccountController{
|
||||
Params: controllers.AccountParams{
|
||||
HashCost: a.Params.HashCost,
|
||||
},
|
||||
DB: a.SQLDriver,
|
||||
DevMode: a.devMode,
|
||||
func (a *AccountsServer) SignUp(ctx context.Context, in *accounts.SignUpRequest) (*empty.Empty, error) {
|
||||
ctrl := &controllers.AccountController{
|
||||
HashCost: a.hashCost,
|
||||
DB: a.SQLDriver,
|
||||
DevMode: a.devMode,
|
||||
}
|
||||
|
||||
if err := accountCtrl.Create(ctx, &controllers.AccountData{
|
||||
data := &controllers.AccountData{
|
||||
Username: in.Data.GetName(),
|
||||
Password: in.Password.GetPassword(),
|
||||
Email: in.Data.GetEmail(),
|
||||
}); err != nil {
|
||||
return nil, status.Error(codes.Aborted, "Couldn't create a user")
|
||||
}
|
||||
return &accounts.AccountFullWithToken{
|
||||
Id: &accounts.AccountId{},
|
||||
Data: &accounts.AccountData{},
|
||||
Token: "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *AccountsServer) SignIn(ctx context.Context, in *accounts.AccountWithPassword) (*accounts.AccountFullWithToken, error) {
|
||||
if err := ctrl.Create(ctx, data); err != nil {
|
||||
return nil, status.Error(codes.Aborted, "User can't be created")
|
||||
}
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
func (a *AccountsServer) ResetPassword(ctx context.Context, in *accounts.AccountData) (*empty.Empty, error) {
|
||||
func (a *AccountsServer) SignIn(ctx context.Context, in *accounts.SignInRequest) (*empty.Empty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
func (acc *AccountsServer) NewPassword(ctx context.Context, in *accounts.AccountWithPasswordAndCode) (*empty.Empty, error) {
|
||||
func (a *AccountsServer) ResetPassword(ctx context.Context, in *accounts.ResetPasswordRequest) (*empty.Empty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
func (acc *AccountsServer) NewPassword(ctx context.Context, in *accounts.NewPasswordRequest) (*empty.Empty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -133,7 +133,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260423180238-53a8a976b540
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260427034527-ad8a1eb091c2
|
||||
github.com/golang/protobuf v1.5.4
|
||||
golang.org/x/net v0.49.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@@ -3,8 +3,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
|
||||
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260423180238-53a8a976b540 h1:DX/lMTetxHz4ezEyBI4bKaJwxhO0uXUyGv9pQTV9NYI=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260423180238-53a8a976b540/go.mod h1:zgX1KfGcHue8TjuXWN0onGpg3pQPek/lKMfdT6S7TQM=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260427034527-ad8a1eb091c2 h1:iOJrE/EiQ3JPgcwgp4oddMX2gil364TomWSUxeDgSvE=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260427034527-ad8a1eb091c2/go.mod h1:AgOh1lkPHyRgBf3/s1btKcAqke/33LbKYarTD13qeAg=
|
||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
|
||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
|
||||
|
||||
@@ -55,20 +55,18 @@ releases:
|
||||
readOnlyRootFilesystem: true
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
redis:
|
||||
# -- Enable redis cluster with docker container.
|
||||
enable: true
|
||||
image:
|
||||
repository: bitnamilegacy/redis
|
||||
# -- Cluster domain.
|
||||
clusterDomain: 'cluster.local'
|
||||
auth:
|
||||
# -- Enable password authentication.
|
||||
enabled: true
|
||||
# -- Redis password.
|
||||
password: dragonfly
|
||||
master:
|
||||
service:
|
||||
ports:
|
||||
# -- Redis master service port.
|
||||
redis: 6379
|
||||
service:
|
||||
port: 30379
|
||||
type: NodePort
|
||||
strategicMergePatches:
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: dragonfly
|
||||
namespace: databases
|
||||
spec:
|
||||
ports:
|
||||
- name: dragonfly
|
||||
port: 30379
|
||||
protocol: TCP
|
||||
nodePort: 30379
|
||||
|
||||
@@ -9,13 +9,17 @@ import (
|
||||
)
|
||||
|
||||
type AccountController struct {
|
||||
Params AccountParams
|
||||
DB *sql.DB
|
||||
DevMode bool
|
||||
DB *sql.DB
|
||||
DevMode bool
|
||||
HashCost int16
|
||||
}
|
||||
|
||||
type JWT struct {
|
||||
RefreshToken string
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
type AccountParams struct {
|
||||
HashCost int16
|
||||
}
|
||||
|
||||
type AccountData struct {
|
||||
@@ -28,7 +32,7 @@ type AccountData struct {
|
||||
func (c *AccountController) Create(ctx context.Context, data *AccountData) error {
|
||||
data.UUID = uuid.New().String()
|
||||
|
||||
passwordHash, err := hash.HashPassword(data.Password, int(c.Params.HashCost))
|
||||
passwordHash, err := hash.HashPassword(data.Password, int(c.HashCost))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ nodes:
|
||||
extraPortMappings:
|
||||
- containerPort: 30432
|
||||
hostPort: 30432
|
||||
- containerPort: 30431
|
||||
hostPort: 30431
|
||||
- containerPort: 30379
|
||||
hostPort: 30379
|
||||
|
||||
4
main.go
4
main.go
@@ -11,7 +11,7 @@ import (
|
||||
v1 "gitea.badhouseplants.net/softplayer/softplayer-backend/api/v1"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/email"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/tools/logger"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
||||
accounts "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
||||
applications_proto "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/applications/v1"
|
||||
email_proto "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/email/v1"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments/v1"
|
||||
@@ -147,7 +147,7 @@ func server(ctx context.Context, params Serve) error {
|
||||
}
|
||||
|
||||
environments.RegisterEnvironmentsServer(grpcServer, v1.NewapiGrpcImpl(controller, log))
|
||||
accounts.RegisterAccountsServer(grpcServer, v1.NewAccountRPCImpl(db, params.HashCost, &emailConfig, params.DevMode))
|
||||
accounts.RegisterAccountsServiceServer(grpcServer, v1.NewAccountRPCImpl(db, params.HashCost, &emailConfig, params.DevMode))
|
||||
email_proto.RegisterEmailValidationServer(grpcServer, v1.InitEmailServer(controller, &emailConfig, params.DevMode))
|
||||
applications_proto.RegisterApplicationsServer(grpcServer, v1.NewApplicationsGrpcImpl(controller, log))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user