Add phone registration with SMS verification and regenerate Swagger docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-13 14:43:33 +05:00
parent 704606b3f5
commit 5e3c46da83
17 changed files with 1008 additions and 20 deletions

30
pkg/sms/sender.go Normal file
View File

@@ -0,0 +1,30 @@
package sms
import (
"context"
"online-back/pkg/logging"
)
// Sender delivers an SMS. Plug your provider in by implementing this
// interface and passing it to auth.NewHandler.
type Sender interface {
Send(ctx context.Context, phone, message string) error
}
// LogSender is a stand-in used until a real SMS client is wired in.
// It logs the message (including the OTP) so local testing still works.
type LogSender struct {
logger *logging.Logger
}
func NewLogSender(logger *logging.Logger) *LogSender {
return &LogSender{logger: logger}
}
func (s *LogSender) Send(_ context.Context, phone, message string) error {
if s.logger != nil {
s.logger.Infof("sms to %s: %s", phone, message)
}
return nil
}

View File

@@ -21,12 +21,20 @@ func DoWithTries(fn func() error, attempts int, delay time.Duration) error {
}
func GenerateTokenPair(id int) (map[string]string, error) {
return generateTokenPair(id, true)
}
func GenerateUserTokenPair(id int) (map[string]string, error) {
return generateTokenPair(id, false)
}
func generateTokenPair(id int, admin bool) (map[string]string, error) {
cfg := config.GetConfig()
secret := []byte(cfg.JwtKey)
accessToken := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"id": id,
"admin": true,
"admin": admin,
"exp": time.Now().Add(time.Hour).Unix(),
})