Skip to content

Commit

Permalink
Add delivery person login functionality
Browse files Browse the repository at this point in the history
Implemented login endpoint for delivery personnel. Added context-based validation and JWT generation for secure authentication. Updated delivery models and routes to support the new login feature.
  • Loading branch information
mukulmantosh committed Sep 12, 2024
1 parent 5b0e268 commit ca5b6c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ import (
"Go_Food_Delivery/pkg/database/models/delivery"
"context"
"errors"
"fmt"
"github.com/golang-jwt/jwt/v5"
"github.com/pquerna/otp/totp"
"log/slog"
"os"
"time"
)

func (deliverSrv *DeliveryService) GenerateTOTP(_ context.Context, phone string) (string, string, error) {
key, err := totp.Generate(totp.GenerateOpts{
Issuer: "Food Delivery",
AccountName: phone,
})
if err != nil {
return "", "", errors.New("error generating key")
}
return key.Secret(), key.URL(), nil
}

func (deliverSrv *DeliveryService) ValidateAccountDetails(ctx context.Context, phone string) (*delivery.DeliveryPerson, error) {
var deliveryAccountInfo delivery.DeliveryPerson
err := deliverSrv.db.Select(ctx, &deliveryAccountInfo, "phone", phone)
Expand All @@ -22,7 +32,6 @@ func (deliverSrv *DeliveryService) ValidateAccountDetails(ctx context.Context, p
if deliveryAccountInfo.Status != "AVAILABLE" {
return nil, errors.New("account is inactive or not available")
}
fmt.Printf("%+v", deliveryAccountInfo)
return &deliveryAccountInfo, nil
}

Expand Down
18 changes: 0 additions & 18 deletions pkg/service/delivery/generate_2fa.go

This file was deleted.

0 comments on commit ca5b6c1

Please sign in to comment.