feat: update auth and fix url for gitea
This commit is contained in:
Binary file not shown.
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/auth"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/repositories"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/storage"
|
||||
@@ -106,13 +107,10 @@ func (h *AuthHandlers) CallbackGithub(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"user": ghUser})
|
||||
|
||||
reg := h.repo.Register(c.Request.Context(), ghUser)
|
||||
if reg != nil {
|
||||
if reg = nil {
|
||||
c.JSON(500, gin.H{"error": "database error", "details": reg.Error()})
|
||||
err := h.repo.Register(c.Request.Context(), ghUser)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": "database error", "details": err.Error()})
|
||||
h.logger.Error("Database eer in gh callback handler")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,20 @@ func NewAuthRepository(db *sql.DB) AuthRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *authRepository) Register(ctx context.Context, user storage.UserReg) error {
|
||||
func (a *authRepository) Register(ctx context.Context, user storage.UserReg) (int, error) {
|
||||
var id int
|
||||
_, err := a.db.Exec(
|
||||
"INSERT INTO users(email, github_id, github_login, avatar_url) VALUES(?, ?, ?, ?)",
|
||||
)
|
||||
if err != nil {
|
||||
a.logger.Error("error scan: " + err.Error())
|
||||
return err
|
||||
a.logger.Error("error request: " + err.Error())
|
||||
return 0, err
|
||||
}
|
||||
row := a.db.QueryRow("SELECT id FROM users WHERE github_id = ?", user.GithubID)
|
||||
row.Scan(&id)
|
||||
|
||||
a.logger.Info("User registered:", "email", user.Email)
|
||||
return nil
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (a *authRepository) IsRegistered(ctx context.Context, github_id int) (bool, error) {
|
||||
|
||||
@@ -15,6 +15,6 @@ type PostRepository interface {
|
||||
}
|
||||
|
||||
type AuthRepository interface {
|
||||
Register(ctx context.Context, user storage.UserReg) error
|
||||
Register(ctx context.Context, user storage.UserReg) (int, error)
|
||||
IsRegistered(ctx context.Context, github_id int) (bool, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user