Spaces:
Configuration error
Configuration error
Commit ·
1a608ec
1
Parent(s): 895f95d
Deploy files from GitHub repository
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- services/email_verification_service.go+1-4
- services/forgot_password_service.go+1-4
- space/services/external_authentication_service.go+18-1
- space/space/controller/academy/academy_controller.goAdded+31
- space/space/logs/error_log.txt+2
- space/space/models/database_orm_model.go+7-7
- space/space/repositories/academy_repository.go+28-2
- space/space/router/academy_route.goAdded+16
- space/space/router/router.go+1-1
- space/space/services/academy_service.go+75-11
- space/space/services/email_verification_service.go+5-2
- space/space/services/forgot_password_service.go+4-1
- space/space/space/logs/error_log.txt-1
- space/space/space/models/response_model.go+9-6
- space/space/space/repositories/academy_repository.goAdded+47
- space/space/space/services/academy_service.goAdded+40
- space/space/space/services/external_authentication_service.go+1
- space/space/space/services/forgot_password_service.go+11-7
- space/space/space/space/space/go.mod+2-5
- space/space/space/space/space/go.sum+17-13
- space/space/space/space/space/space/models/request_model.go+1-1
- space/space/space/space/space/space/models/response_model.go+10
- space/space/space/space/space/space/services/forgot_password_service.go+7-3
- space/space/space/space/space/space/space/controller/auth/auth_external_controller.go+1-1
- space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go+28
- space/space/space/space/space/space/space/controller/email/email_validate_controller.go-1
- space/space/space/space/space/space/space/models/request_model.go+9-4
- space/space/space/space/space/space/space/repositories/account_repository.go+2-4
- space/space/space/space/space/space/space/router/auth_route.go+2
- space/space/space/space/space/space/space/services/authentication_service.go+2-1
- space/space/space/space/space/space/space/services/email_verification_service.go+5-1
- space/space/space/space/space/space/space/services/external_authentication_service.go+6-1
- space/space/space/space/space/space/space/services/forgot_password_service.goAdded+105
- space/space/space/space/space/space/space/services/user_profile_service.go+20-5
- space/space/space/space/space/space/space/space/space/services/email_verification_service.go+11-60
- space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go+60-11
- space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go+4-2
- space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go+2
- space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go+4
- space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go+8-3
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go+9
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go+1-1
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go+8-2
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml+1-1
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile+3
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go+1-1
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go+2-4
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go+5
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go-4
- space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/forgot_password_repository.goAdded+22
28 unmodified lines293031323334353233343528 unmodified lines remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour
dueTime := CalculateDueTime(remainingTime)
token := uint(rand.IntN(1000000))
for token < 1000000 {
token = uint(rand.IntN(1000000))
}
token := uint(rand.IntN(999999-100000) + 100000)
s.Constructor.UUID = uuid.NewV4()
repo := repositories.CreateEmailVerification(s.Constructor.UUID, s.Constructor.AccountID, dueTime, token)33 unmodified lines343536373839403738394033 unmodified lines remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour
dueTime := CalculateDueTime(remainingTime)
token := uint(rand.IntN(1000000))
for token < 1000000 {
token = uint(rand.IntN(1000000))
}
token := uint(rand.IntN(999999-100000) + 100000)
s.Constructor.UUID = uuid.NewV4()
s.Constructor.ExpiredAt = dueTime
s.Constructor.AccountID = accountRepo.Result.Id31 unmodified lines323334353637383940414243444546474849504251525354555657585960616263646531 unmodified lines }
s.Constructor.UUID = uuid.NewV4()
s.Constructor.OauthProvider = "Google"
checkRegisteredEmail := repositories.GetAccountbyEmail(email.(string))
if !checkRegisteredEmail.NoRecord {
s.Exception.DataDuplicate = true
s.Exception.Message = "Account with email" + email.(string) + "already registered!"
return
}
createAccount := repositories.CreateAccount(models.Account{
UUID: uuid.NewV4(),
Email: email.(string),
IsEmailVerified: true,
})
s.Constructor.AccountID = createAccount.Result.Id
createGoogleAuth := repositories.CreateExternalAuth(s.Constructor)
GoogleAuth.Result.AccountID = createGoogleAuth.Result.ID
GoogleAuth.Result.AccountID = createGoogleAuth.Result.AccountID
userProfile := UserProfileService{}
userProfile.Constructor.AccountID = GoogleAuth.Result.AccountID
userProfile.Create()
if userProfile.Error != nil {
s.Error = userProfile.Error
return
}
s.Error = createGoogleAuth.RowsError
s.Error = errors.Join(s.Error, createAccount.RowsError)
}
accountData := repositories.GetAccountById(GoogleAuth.Result.AccountID)
token, err_tok := GenerateToken(&accountData.Result)
12345678910111213141516171819202122232425262728293031package academy
import (
"api.qobiltu.id/controller"
"api.qobiltu.id/models"
"api.qobiltu.id/services"
"github.com/gin-gonic/gin"
)
func List(c *gin.Context) {
academy := services.AcademyService{}
academyController := controller.Controller[any, models.Academy, models.AllAcademyResponse]{
Service: &academy.Service,
}
academyController.Service.Constructor.Slug = c.Param("slug")
academy.Retrieve()
academyController.Response(c)
}
func Create(c *gin.Context) {
createAcademy := services.CreateAcademyService{}
academyController := controller.Controller[models.AllAcademyResponse, models.AllAcademyResponse, models.AllAcademyResponse]{
Service: &createAcademy.Service,
}
academyController.RequestJSON(c, func() {
academyController.Service.Constructor.Academies = academyController.Request.Academies
createAcademy.Create()
})
}122025/04/20 10:05:28 Error Log : duplicated key not allowed2025/04/20 10:11:41 Error Log : duplicated key not allowed29 unmodified lines303132333334353648 unmodified lines85868788899091929388899091929394959629 unmodified lines LastEducation *string `json:"last_education"`
MaritalStatus *string `json:"marital_status"`
Avatar *string `json:"avatar"`
PhoneNumber *uint `json:"phone_number"`
PhoneNumber *string `json:"phone_number"`
}
type EmailVerification struct {48 unmodified lines}
type AcademyContent struct {
ID uint `gorm:"primaryKey" json:"id"`
UUID uint `json:"uuid"`
Title string `json:"title"`
Order uint `json:"order"`
AcademyMaterialID uint `json:"academy_material_id"`
Description string `json:"description"`
ID uint `gorm:"primaryKey" json:"id"`
UUID uuid.UUID `json:"uuid"`
Title string `json:"title"`
Order uint `json:"order"`
AcademyMaterialID uint `json:"academy_material_id"`
Description string `json:"description"`
}
type OptionCategory struct {
ID uint `gorm:"primaryKey" json:"id"`12 unmodified lines131415161617181819202123 unmodified lines454647484950515253545556575859606162636465666768697071727312 unmodified lines return *repo
}
func GetAcademyDataById(academyId uint) Repository[models.Academy, models.Academy] {
func GetAcademyDataBySlug(slug string) Repository[models.Academy, models.Academy] {
repo := Construct[models.Academy, models.Academy](
models.Academy{ID: academyId},
models.Academy{Slug: slug},
)
repo.Transactions(
WhereGivenConstructor[models.Academy, models.Academy],23 unmodified lines )
return *repo
}
func CreateAcademy(academies models.Academy) Repository[models.Academy, models.Academy] {
repo := Construct[models.Academy, models.Academy](
academies,
)
Create(repo)
return *repo
}
func CreateAcademyMaterial(academyMaterial models.AcademyMaterial) Repository[models.AcademyMaterial, models.AcademyMaterial] {
repo := Construct[models.AcademyMaterial, models.AcademyMaterial](
academyMaterial,
)
Create(repo)
return *repo
}
func CreateAcademyContent(academyContent models.AcademyContent) Repository[models.AcademyContent, models.AcademyContent] {
repo := Construct[models.AcademyContent, models.AcademyContent](
academyContent,
)
Create(repo)
return *repo
}12345678910111213141516package router
import (
AcademyController "api.qobiltu.id/controller/academy"
"api.qobiltu.id/middleware"
"github.com/gin-gonic/gin"
)
func AcademyRoute(router *gin.Engine) {
routerGroup := router.Group("/api/v1/academy")
{
routerGroup.GET("/list/:slug", middleware.AuthUser, AcademyController.List)
routerGroup.GET("/list", middleware.AuthUser, AcademyController.List)
routerGroup.POST("/create", middleware.AuthUser, AcademyController.Create)
}
}15 unmodified lines161718191920212215 unmodified lines UserRoute(router)
EmailRoute(router)
OptionsRoute(router)
AcademyRoute(router)
err := router.Run(config.TCP_ADDRESS)
if err != nil {
log.Fatalf("Failed to run server: %v", err)2 unmodified lines345678910111213141516171819202122232425262728131429303132333435362122232425262737383940413242434445463747484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031042 unmodified linesimport (
"api.qobiltu.id/models"
"api.qobiltu.id/repositories"
"github.com/gosimple/slug"
uuid "github.com/satori/go.uuid"
)
type AcademyService struct {
Service[models.Academy, models.AllAcademyResponse]
}
type CreateAcademyService struct {
Service[models.AllAcademyResponse, models.AllAcademyResponse]
}
func castAcademyMaterials(academyId uint) []models.AcademyMaterialResponse {
var ArrMaterials []models.AcademyMaterialResponse
for _, academyMaterial := range repositories.GetAllAcademyMaterialsByAcademyID(academyId).Result {
ArrMaterials = append(ArrMaterials, models.AcademyMaterialResponse{
Materials: academyMaterial,
Contents: repositories.GetAllAcademyContentsByMaterialID(academyMaterial.ID).Result,
})
}
return ArrMaterials
}
func (s *AcademyService) Retrieve() {
if s.Constructor.ID != 0 {
AcademyRepo := repositories.GetAcademyDataById(s.Constructor.ID)
if s.Constructor.Slug != "" {
AcademyRepo := repositories.GetAcademyDataBySlug(s.Constructor.Slug)
s.Error = AcademyRepo.RowsError
if AcademyRepo.NoRecord {
s.Exception.Message = "Academy not found"
s.Exception.DataNotFound = true
return
}
var ArrMaterials []models.AcademyMaterialResponse
for _, academyMaterial := range repositories.GetAllAcademyMaterialsByAcademyID(s.Constructor.ID).Result {
ArrMaterials = append(ArrMaterials, models.AcademyMaterialResponse{
Materials: academyMaterial,
Contents: repositories.GetAllAcademyContentsByMaterialID(academyMaterial.ID).Result,
})
}
s.Result = models.AllAcademyResponse{
Academies: []models.AcademyResponse{
models.AcademyResponse{
Academy: AcademyRepo.Result,
Materials: ArrMaterials,
Materials: castAcademyMaterials(s.Constructor.ID),
},
},
}
} else {
// AcademyRepo := repositories.GetAllAcademy()
AcademyRepo := repositories.GetAllAcademy()
s.Error = AcademyRepo.RowsError
var ArrAcademy []models.AcademyResponse
for _, academy := range AcademyRepo.Result {
ArrAcademy = append(ArrAcademy, models.AcademyResponse{
Academy: academy,
Materials: castAcademyMaterials(academy.ID),
})
}
s.Result = models.AllAcademyResponse{
Academies: ArrAcademy,
}
}
}
func (s *CreateAcademyService) Create() {
var ArrAcademy []models.AcademyResponse
for _, academy := range s.Constructor.Academies {
academy.Academy.UUID = uuid.NewV4()
if academy.Academy.Slug == "" {
academy.Academy.Slug = slug.Make(academy.Academy.Title)
}
createdAcademy := repositories.CreateAcademy(academy.Academy)
if createdAcademy.RowsError != nil {
s.Error = createdAcademy.RowsError
return
}
for _, material := range academy.Materials {
material.Materials.AcademyID = createdAcademy.Result.ID
material.Materials.UUID = uuid.NewV4()
if material.Materials.Slug == "" {
material.Materials.Slug = slug.Make(material.Materials.Title)
}
createdMaterial := repositories.CreateAcademyMaterial(material.Materials)
if createdMaterial.RowsError != nil {
s.Error = createdMaterial.RowsError
return
}
for _, content := range material.Contents {
content.UUID = uuid.NewV4()
content.AcademyMaterialID = createdMaterial.Result.ID
createdContent := repositories.CreateAcademyContent(content)
if createdContent.RowsError != nil {
s.Error = createdContent.RowsError
return
}
ArrAcademy = append(ArrAcademy, models.AcademyResponse{
Academy: createdAcademy.Result,
Materials: castAcademyMaterials(createdAcademy.Result.ID),
})
}
}
}
s.Result = models.AllAcademyResponse{Academies: ArrAcademy}
}28 unmodified lines293031323233343536373847 unmodified lines868788868990919228 unmodified lines remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour
dueTime := CalculateDueTime(remainingTime)
token := uint(rand.IntN(100000))
token := uint(rand.IntN(1000000))
for token < 1000000 {
token = uint(rand.IntN(1000000))
}
s.Constructor.UUID = uuid.NewV4()
repo := repositories.CreateEmailVerification(s.Constructor.UUID, s.Constructor.AccountID, dueTime, token)47 unmodified lines }
account := repositories.GetAccountById(repo.Result.AccountID)
account.Result.IsEmailVerified = true
repositories.UpdateAccount(account.Result)
s.Result = repo.Result
}33 unmodified lines343536373738394041424333 unmodified lines remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour
dueTime := CalculateDueTime(remainingTime)
token := uint(rand.IntN(100000))
token := uint(rand.IntN(1000000))
for token < 1000000 {
token = uint(rand.IntN(1000000))
}
s.Constructor.UUID = uuid.NewV4()
s.Constructor.ExpiredAt = dueTime
s.Constructor.AccountID = accountRepo.Result.Id1
30 unmodified lines31323334353637343536373839404142404143444530 unmodified lines Details AccountDetails `json:"details"`
}
type AkademiDasar struct {
Academies Academy `json:"academy"`
Materials []AcademyMaterial `json:"academy_material"`
Contents []AcademyContent `json:"academy_content"`
type AcademyMaterialResponse struct {
Materials AcademyMaterial
Contents []AcademyContent
}
type AcademyResponse struct {
Academy Academy `json:"academy"`
Materials []AcademyMaterialResponse `json:"academy_materials"`
}
type AkademiDasarResponse struct {
AkademiDasar []AkademiDasar `json:"academy_dasar"`
type AllAcademyResponse struct {
Academies []AcademyResponse `json:"academy_dasar"`
}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647package repositories
import "api.qobiltu.id/models"
func GetAllAcademy() Repository[models.Academy, []models.Academy] {
repo := Construct[models.Academy, []models.Academy](
models.Academy{},
)
repo.Transactions(
WhereGivenConstructor[models.Academy, []models.Academy],
Find[models.Academy, []models.Academy],
)
return *repo
}
func GetAcademyDataById(academyId uint) Repository[models.Academy, models.Academy] {
repo := Construct[models.Academy, models.Academy](
models.Academy{ID: academyId},
)
repo.Transactions(
WhereGivenConstructor[models.Academy, models.Academy],
Find[models.Academy, models.Academy],
)
return *repo
}
func GetAllAcademyMaterialsByAcademyID(acaddemyId uint) Repository[models.AcademyMaterial, []models.AcademyMaterial] {
repo := Construct[models.AcademyMaterial, []models.AcademyMaterial](
models.AcademyMaterial{AcademyID: acaddemyId},
)
repo.Transactions(
WhereGivenConstructor[models.AcademyMaterial, []models.AcademyMaterial],
Find[models.AcademyMaterial, []models.AcademyMaterial],
)
return *repo
}
func GetAllAcademyContentsByMaterialID(materialId uint) Repository[models.AcademyContent, []models.AcademyContent] {
repo := Construct[models.AcademyContent, []models.AcademyContent](
models.AcademyContent{AcademyMaterialID: materialId},
)
repo.Transactions(
WhereGivenConstructor[models.AcademyContent, []models.AcademyContent],
Find[models.AcademyContent, []models.AcademyContent],
)
return *repo
}12345678910111213141516171819202122232425262728293031323334353637383940package services
import (
"api.qobiltu.id/models"
"api.qobiltu.id/repositories"
)
type AcademyService struct {
Service[models.Academy, models.AllAcademyResponse]
}
func (s *AcademyService) Retrieve() {
if s.Constructor.ID != 0 {
AcademyRepo := repositories.GetAcademyDataById(s.Constructor.ID)
s.Error = AcademyRepo.RowsError
if AcademyRepo.NoRecord {
s.Exception.Message = "Academy not found"
s.Exception.DataNotFound = true
return
}
var ArrMaterials []models.AcademyMaterialResponse
for _, academyMaterial := range repositories.GetAllAcademyMaterialsByAcademyID(s.Constructor.ID).Result {
ArrMaterials = append(ArrMaterials, models.AcademyMaterialResponse{
Materials: academyMaterial,
Contents: repositories.GetAllAcademyContentsByMaterialID(academyMaterial.ID).Result,
})
}
s.Result = models.AllAcademyResponse{
Academies: []models.AcademyResponse{
models.AcademyResponse{
Academy: AcademyRepo.Result,
Materials: ArrMaterials,
},
},
}
} else {
// AcademyRepo := repositories.GetAllAcademy()
}
}32 unmodified lines3334353637383932 unmodified lines s.Constructor.UUID = uuid.NewV4()
s.Constructor.OauthProvider = "Google"
createAccount := repositories.CreateAccount(models.Account{
UUID: uuid.NewV4(),
Email: email.(string),
IsEmailVerified: true,
})70 unmodified lines717273747576777879807475767 unmodified lines8485868788899091929394959697989910010110210310410510610770 unmodified lines}
func (s *ForgotPasswordService) Validate(newPassword *string) {
accountRepo := repositories.GetAccountById(s.Constructor.AccountID)
if accountRepo.NoRecord {
s.Error = accountRepo.RowsError
s.Exception.DataNotFound = true
s.Exception.Message = "There is no account data with given credentials!"
return
}
fgPasswordRepo := repositories.GetForgotPasswordByToken(s.Constructor.Token)
s.Error = fgPasswordRepo.RowsError7 unmodified lines s.Exception.Message = "Token has expired!"
return
}
accountRepo := repositories.GetAccountById(fgPasswordRepo.Result.AccountID)
if accountRepo.NoRecord {
s.Error = accountRepo.RowsError
s.Exception.DataNotFound = true
s.Exception.Message = "There is no account data with given credentials!"
return
}
s.Result = fgPasswordRepo.Result
if newPassword == nil {
return
}
// fmt.Println("Previous Account", accountRepo.Result)
// fmt.Println("New password", *newPassword)
hashed_password, _ := HashPassword(*newPassword)
accountRepo.Result.Password = hashed_password
changePassword := repositories.UpdateAccount(accountRepo.Result)
// fmt.Println("New Account", changePassword.Result)
if changePassword.RowsError != nil {
s.Error = changePassword.RowsError
s.Exception.QueryError = true4 unmodified lines5678910111213141517 unmodified lines333435343637383 unmodified lines424344444546474849505051522 unmodified lines555657595859606162656364654 unmodified linesrequire ( github.com/gin-gonic/gin v1.10.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/gosimple/slug v1.15.0 github.com/joho/godotenv v1.5.1 github.com/satori/go.uuid v1.2.0 golang.org/x/crypto v0.36.0 google.golang.org/api v0.228.0 gorm.io/driver/postgres v1.5.11 gorm.io/gorm v1.25.12)17 unmodified lines github.com/google/s2a-go v0.1.9 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect github.com/googleapis/gax-go/v2 v2.14.1 // indirect github.com/gosimple/slug v1.15.0 // indirect github.com/gosimple/unidecode v1.0.1 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect3 unmodified lines github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect2 unmodified lines go.opentelemetry.io/otel/metric v1.34.0 // indirect go.opentelemetry.io/otel/trace v1.34.0 // indirect golang.org/x/arch v0.15.0 // indirect golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect golang.org/x/net v0.37.0 // indirect golang.org/x/oauth2 v0.28.0 // indirect golang.org/x/sync v0.12.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect google.golang.org/api v0.228.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect google.golang.org/grpc v1.71.0 // indirect google.golang.org/protobuf v1.36.6 // indirect11 unmodified lines1213141515161722 unmodified lines404142444543444546474849505152535422 unmodified lines777879777880818283849 unmodified lines949596949597989910015 unmodified lines1161171181191201211221231241251261271281291301311321331341351361291301371381395 unmodified lines14514614714214314814915015115215315415515015115615715811 unmodified linesgithub.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=22 unmodified linesgithub.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4=github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q=22 unmodified linesgithub.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=9 unmodified linesgithub.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=15 unmodified linesgithub.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 h1:rgMkmiGfix9vFJDcDi1PK8WEQP4FLQwLDfhp5ZLpFeE=go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0/go.mod h1:ijPqXp5P6IRRByFVVg9DY8P5HkxkHE5ARIa+86aXPf4=go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s=go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I=go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=5 unmodified linesgolang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=google.golang.org/api v0.228.0 h1:X2DJ/uoWGnY5obVjewbp8icSL5U4FzuCfy9OjbLSnLs=google.golang.org/api v0.228.0/go.mod h1:wNvRS1Pbe8r4+IfBIniV8fwCpGwTrYa+kMUDiC5z5a4=google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 h1:iK2jbkWL86DXjEx0qiHcRE9dE4/Ahua5k6V8OWFb//c=google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=37 unmodified lines38394041414237 unmodified lines}
type ValidateForgotPasswordRequest struct {
Token uint `json:"token" binding:"required"`
NewPassword string `json:"new_password" binding:"required"`
NewPassword string `json:"new_password"`
}29 unmodified lines3031323334353637383940414229 unmodified lines Account Account `json:"account"`
Details AccountDetails `json:"details"`
}
type AkademiDasar struct {
Academies Academy `json:"academy"`
Materials []AcademyMaterial `json:"academy_material"`
Contents []AcademyContent `json:"academy_content"`
}
type AkademiDasarResponse struct {
AkademiDasar []AkademiDasar `json:"academy_dasar"`
}69 unmodified lines707172737374757614 unmodified lines919293949596979498991001013 unmodified lines10510610710410810969 unmodified lines // s.Result.Token = 0
}
func (s *ForgotPasswordService) Validate(newPassword string) {
func (s *ForgotPasswordService) Validate(newPassword *string) {
accountRepo := repositories.GetAccountById(s.Constructor.AccountID)
if accountRepo.NoRecord {
s.Error = accountRepo.RowsError14 unmodified lines s.Exception.Message = "Token has expired!"
return
}
s.Result = fgPasswordRepo.Result
if newPassword == nil {
return
}
hashed_password, _ := HashPassword(newPassword)
hashed_password, _ := HashPassword(*newPassword)
accountRepo.Result.Password = hashed_password
changePassword := repositories.UpdateAccount(accountRepo.Result)
if changePassword.RowsError != nil {3 unmodified lines return
}
// fgPasswordRepo.Result.Token = 0
s.Result = fgPasswordRepo.Result
}13 unmodified lines141516171718192013 unmodified lines GoogleLogin := services.GoogleAuthService{}
ExternalAuthController.Service = &GoogleLogin.Service
ExternalAuthController.Service.Constructor.OauthID = ExternalAuthController.Request.OauthID
GoogleLogin.Authenticate()
GoogleLogin.Authenticate(ExternalAuthController.Request.IsAgreeTerms && !ExternalAuthController.Request.IsSexualDisease)
}
})
}1234567891011121314151617181920212223242526272829package auth
import (
"api.qobiltu.id/controller"
"api.qobiltu.id/models"
"api.qobiltu.id/services"
"github.com/gin-gonic/gin"
)
func CreateForgotPassword(c *gin.Context) {
ForgotPassword := services.ForgotPasswordService{}
ForgotPasswordController := controller.Controller[models.ForgotPasswordRequest, models.ForgotPassword, models.ForgotPassword]{
Service: &ForgotPassword.Service,
}
ForgotPasswordController.RequestJSON(c, func() {
ForgotPassword.Create(ForgotPasswordController.Request.Email)
})
}
func ValidateForgotPassword(c *gin.Context) {
ForgotPassword := services.ForgotPasswordService{}
ForgotPasswordController := controller.Controller[models.ValidateForgotPasswordRequest, models.ForgotPassword, models.ForgotPassword]{
Service: &ForgotPassword.Service,
}
ForgotPasswordController.RequestJSON(c, func() {
ForgotPasswordController.Service.Constructor.Token = ForgotPasswordController.Request.Token
ForgotPassword.Validate(&ForgotPasswordController.Request.NewPassword)
})
}15 unmodified lines1617181919202115 unmodified lines emailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID)
emailVerificationController.RequestJSON(c, func() {
emailVerificationController.Service.Constructor.Token = emailVerificationController.Request.Token
emailVerificationController.Service.Constructor.UUID = emailVerificationController.Request.UUID
emailVerification.Validate()
})
})123434512 unmodified lines1819202324212223247 unmodified lines3233343536373839404142package models
import uuid "github.com/satori/go.uuid"
type LoginRequest struct {
Email string `json:"email" binding:"required"`
Password string `json:"password" binding:"required"`12 unmodified lines}
type CreateVerifyEmailRequest struct {
Token uint `json:"token" binding:"required"`
UUID uuid.UUID `json:"uuid" binding:"required"`
Token uint `json:"token" binding:"required"`
}
type OptionsRequest struct {7 unmodified lines IsAgreeTerms bool `json:"is_agree_terms"`
IsSexualDisease bool `json:"is_sexual_disease"`
}
type ForgotPasswordRequest struct {
Email string `json:"email" binding:"required,email"`
}
type ValidateForgotPasswordRequest struct {
Token uint `json:"token" binding:"required"`
NewPassword string `json:"new_password" binding:"required"`
}38 unmodified lines39404142434445424344454638 unmodified lines repo := Construct[models.Account, models.Account](
account,
)
repo.Transactions(
WhereGivenConstructor[models.Account, models.Account],
Update[models.Account],
)
repo.Transaction.Save(&repo.Constructor)
repo.Result = repo.Constructor
return *repo
}
12 unmodified lines1314151617181912 unmodified lines routerGroup.POST("/login", AuthController.Login)
routerGroup.POST("/register", AuthController.Register)
routerGroup.PUT("/change-password", middleware.AuthUser, AuthController.ChangePassword)
routerGroup.POST("/forgot-password", AuthController.CreateForgotPassword)
routerGroup.PUT("/forgot-password", AuthController.ValidateForgotPassword)
}
}57 unmodified lines58596061616263646557 unmodified lines s.Exception.Message = "incorrect old password!"
return
}
hashed_password, _ := HashPassword(newPassword)
accountData.Result.Password = newPassword
accountData.Result.Password = hashed_password
changePassword := repositories.UpdateAccount(accountData.Result)
changePassword.Result.Password = "SECRET"
s.Result = models.AuthenticatedUser{60 unmodified lines6162636465666713 unmodified lines81828384858687888489909160 unmodified lines return
}
}(accountRepo.Result.Email, token)
// s.Result.Token = 0
}
func (s *EmailVerificationService) Validate() {13 unmodified lines s.Delete()
return
}
account := repositories.GetAccountById(repo.Result.AccountID)
account.Result.IsEmailVerified = true
repositories.UpdateAccount(account.Result)
s.Result = repo.Result
s.Delete()
}
func (s *EmailVerificationService) Delete() {13 unmodified lines14151617171819204 unmodified lines252627282930313233343513 unmodified lines Service[models.ExternalAuth, models.AuthenticatedUser]
}
func (s *GoogleAuthService) Authenticate() {
func (s *GoogleAuthService) Authenticate(isAgree bool) {
GoogleAuth := repositories.GetExternalAccountByOauthId(s.Constructor.OauthID)
payload, errGoogleAuth := idtoken.Validate(context.Background(), s.Constructor.OauthID, "")
s.Error = errGoogleAuth4 unmodified lines }
email := payload.Claims["email"]
if GoogleAuth.NoRecord {
if !isAgree {
s.Exception.BadRequest = true
s.Exception.Message = "Please agree to the terms and conditions to create an account"
return
}
s.Constructor.UUID = uuid.NewV4()
s.Constructor.OauthProvider = "Google"
createAccount := repositories.CreateAccount(models.Account{123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105package services
import (
"fmt"
"log"
"math/rand/v2"
"net/smtp"
"time"
"api.qobiltu.id/config"
"api.qobiltu.id/models"
"api.qobiltu.id/repositories"
uuid "github.com/satori/go.uuid"
)
type ForgotPasswordService struct {
Service[models.ForgotPassword, models.ForgotPassword]
}
func (s *ForgotPasswordService) Create(email string) {
if email == "" {
s.Exception.BadRequest = true
s.Exception.Message = "Email is required!"
return
}
accountRepo := repositories.GetAccountbyEmail(email)
if accountRepo.NoRecord {
s.Error = accountRepo.RowsError
s.Exception.DataNotFound = true
s.Exception.Message = "There is no account data with given credentials!"
return
}
remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour
dueTime := CalculateDueTime(remainingTime)
token := uint(rand.IntN(100000))
s.Constructor.UUID = uuid.NewV4()
s.Constructor.ExpiredAt = dueTime
s.Constructor.AccountID = accountRepo.Result.Id
s.Constructor.Token = token
repo := repositories.CreateForgotPassword(s.Constructor)
s.Error = repo.RowsError
s.Result = repo.Result
// ⬇ Kirim token ke email user menggunakan SMTP
go func(toEmail string, token uint) {
from := config.SMTP_SENDER_EMAIL
password := config.SMTP_SENDER_PASSWORD
smtpHost := config.SMTP_HOST
smtpPort := config.SMTP_PORT
auth := smtp.PlainAuth("", from, password, smtpHost)
subject := "Forgot Password Token"
body := fmt.Sprintf("Your Forgot Password token is: %06d\nPlease use it before it expires.", token)
msg := []byte("To: " + toEmail + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" +
body + "\r\n")
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)
if err != nil {
s.Error = err
log.Printf("Error sending verification email: %v", err)
return
}
}(accountRepo.Result.Email, token)
// s.Result.Token = 0
}
func (s *ForgotPasswordService) Validate(newPassword string) {
accountRepo := repositories.GetAccountById(s.Constructor.AccountID)
if accountRepo.NoRecord {
s.Error = accountRepo.RowsError
s.Exception.DataNotFound = true
s.Exception.Message = "There is no account data with given credentials!"
return
}
fgPasswordRepo := repositories.GetForgotPasswordByToken(s.Constructor.Token)
s.Error = fgPasswordRepo.RowsError
if fgPasswordRepo.NoRecord {
s.Exception.DataNotFound = true
s.Exception.Message = "There is no forgot password data with given credentials!"
return
}
if fgPasswordRepo.Result.ExpiredAt.Before(time.Now()) {
s.Exception.Unauthorized = true
s.Exception.Message = "Token has expired!"
return
}
hashed_password, _ := HashPassword(newPassword)
accountRepo.Result.Password = hashed_password
changePassword := repositories.UpdateAccount(accountRepo.Result)
if changePassword.RowsError != nil {
s.Error = changePassword.RowsError
s.Exception.QueryError = true
s.Exception.Message = "Failed to update password!"
return
}
// fgPasswordRepo.Result.Token = 0
s.Result = fgPasswordRepo.Result
}68 unmodified lines697071727374753 unmodified lines7980818281828384838485868788899091923 unmodified lines969798991001011021031041051061071081091109611111211311468 unmodified lines Account: repositories.GetAccountById(s.Constructor.AccountID).Result,
Details: userProfile.Result,
}
s.Result.Account.Password = "SECRET"
}
func (s *UserProfileService) Update() {3 unmodified lines }
usersCount := repositories.GetAllAccount().RowsCount
var initialName string
if s.Constructor.Gender != nil {
if *s.Constructor.Gender {
initialName = "IKH_"
} else {
initialName = "AKH_"
if *s.Constructor.Gender {
initialName = "IKH_"
} else {
initialName = "AKH_"
}
}
initialName += strconv.Itoa(usersCount)
s.Constructor.InitialName = initialName
userProfile := repositories.UpdateAccountDetails(s.Constructor)3 unmodified lines s.Exception.Message = "There is no account with given credentials!"
return
}
account := repositories.GetAccountById(s.Constructor.AccountID)
account.Result.IsDetailCompleted = (userProfile.Result.InitialName != "" &&
userProfile.Result.FullName != nil &&
userProfile.Result.DateOfBirth != nil &&
userProfile.Result.PlaceOfBirth != nil &&
userProfile.Result.Domicile != nil &&
userProfile.Result.LastJob != nil &&
userProfile.Result.Gender != nil &&
userProfile.Result.LastEducation != nil &&
userProfile.Result.MaritalStatus != nil)
repositories.UpdateAccount(account.Result)
s.Result = models.UserProfileResponse{
Account: repositories.GetAccountById(s.Constructor.AccountID).Result,
Account: account.Result,
Details: userProfile.Result,
}
s.Result.Account.Password = "SECRET"12344567835 unmodified lines444546474849505152535455565758596061624764656648686970495051727374757677525354555679575881596061628384858687888990919293949596979899100101102103104105106107108109110111636465package services
import (
"crypto/tls"
"fmt"
"log"
"math/rand/v2"
"net/smtp"
"time"35 unmodified lines smtpHost := config.SMTP_HOST
smtpPort := config.SMTP_PORT
tlsconfig := &tls.Config{
InsecureSkipVerify: true,
ServerName: smtpHost,
}
conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", smtpHost, smtpPort), tlsconfig)
if err != nil {
panic(err)
}
client, err := smtp.NewClient(conn, smtpHost)
if err != nil {
panic(err)
}
// auth := smtp.PlainAuth("", from, password, smtpHost)
auth := smtp.PlainAuth("", from, password, smtpHost)
if err = client.Auth(auth); err != nil {
panic(err)
}
if err = client.Mail(from); err != nil {
panic(err)
}
subject := "Email Verification Token"
body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token)
to := []string{toEmail}
for _, addr := range to {
if err = client.Rcpt(addr); err != nil {
panic(err)
}
}
msg := []byte("To: " + toEmail + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" +
body + "\r\n")
wc, err := client.Data()
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)
if err != nil {
panic(err)
s.Error = err
log.Printf("Error sending verification email: %v", err)
return
}
msg := []byte("Subject: Test Email\r\n\r\nThis is the email body.")
_, err = wc.Write(msg)
if err != nil {
panic(err)
}
err = wc.Close()
if err != nil {
panic(err)
}
client.Quit()
fmt.Println("Email sent successfully!")
// subject := "Email Verification Token"
// body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token)
// msg := []byte("To: " + toEmail + "\r\n" +
// "Subject: " + subject + "\r\n" +
// "\r\n" +
// body + "\r\n")
// err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)
// if err != nil {
// s.Error = err
// log.Printf("Error sending verification email: %v", err)
// return
// }
}(accountRepo.Result.Email, token)
}
12345567835 unmodified lines444546474849505152535455565758596061626364656667495068697071525354557273747576777857798059606181828384858687888990919293949596979899100101102103104105106107108109110111112113114package services
import (
"crypto/tls"
"fmt"
"log"
"math/rand/v2"
"net/smtp"
"time"35 unmodified lines smtpHost := config.SMTP_HOST
smtpPort := config.SMTP_PORT
tlsconfig := &tls.Config{
InsecureSkipVerify: true,
ServerName: smtpHost,
}
conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", smtpHost, smtpPort), tlsconfig)
if err != nil {
panic(err)
}
client, err := smtp.NewClient(conn, smtpHost)
if err != nil {
panic(err)
}
// auth := smtp.PlainAuth("", from, password, smtpHost)
auth := smtp.PlainAuth("", from, password, smtpHost)
if err = client.Auth(auth); err != nil {
panic(err)
}
subject := "Email Verification Token"
body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token)
if err = client.Mail(from); err != nil {
panic(err)
}
msg := []byte("To: " + toEmail + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" +
body + "\r\n")
to := []string{toEmail}
for _, addr := range to {
if err = client.Rcpt(addr); err != nil {
panic(err)
}
}
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)
wc, err := client.Data()
if err != nil {
s.Error = err
log.Printf("Error sending verification email: %v", err)
return
panic(err)
}
msg := []byte("Subject: Test Email\r\n\r\nThis is the email body.")
_, err = wc.Write(msg)
if err != nil {
panic(err)
}
err = wc.Close()
if err != nil {
panic(err)
}
client.Quit()
fmt.Println("Email sent successfully!")
// subject := "Email Verification Token"
// body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token)
// msg := []byte("To: " + toEmail + "\r\n" +
// "Subject: " + subject + "\r\n" +
// "\r\n" +
// body + "\r\n")
// err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)
// if err != nil {
// s.Error = err
// log.Printf("Error sending verification email: %v", err)
// return
// }
}(accountRepo.Result.Email, token)
}
29 unmodified lines3031323334333435363729 unmodified lines}
type ExternalAuthRequest struct {
OauthID string `json:"oauth_id" binding:"required"`
OauthProvider string `json:"oauth_provider" binding:"required"`
OauthID string `json:"oauth_id" binding:"required"`
OauthProvider string `json:"oauth_provider" binding:"required"`
IsAgreeTerms bool `json:"is_agree_terms"`
IsSexualDisease bool `json:"is_sexual_disease"`
}17 unmodified lines181920212223244 unmodified lines2930313233343517 unmodified lines s.Exception.Message = "there is no account with given credentials!"
return
}
if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {
s.Exception.Unauthorized = true
s.Exception.Message = "incorrect password!"4 unmodified lines
if err_tok != nil {
s.Error = errors.Join(s.Error, err_tok)
return
}
accountData.Result.Password = "SECRET"55 unmodified lines56575859606162636412 unmodified lines777879808182838485868755 unmodified lines
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)
if err != nil {
s.Error = err
log.Printf("Error sending verification email: %v", err)
return
}
}(accountRepo.Result.Email, token)
}12 unmodified lines s.Exception.Unauthorized = true
s.Exception.Message = "Token has expired!"
repositories.UpdateExpiredEmailVerification(s.Constructor.UUID)
s.Delete()
return
}
s.Result = repo.Result
s.Delete()
}
func (s *EmailVerificationService) Delete() {1 unmodified line234567863 unmodified lines7273747574757677787980811 unmodified line8384858386878889905 unmodified lines969798991001 unmodified line
import (
"regexp"
"strconv"
"strings"
"api.qobiltu.id/models"63 unmodified lines}
func (s *UserProfileService) Update() {
if s.Constructor.PhoneNumber != nil {
phoneNumber := *s.Constructor.PhoneNumber
*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)
phoneNumber := *s.Constructor.PhoneNumber
*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)
}
usersCount := repositories.GetAllAccount().RowsCount
var initialName string
if *s.Constructor.Gender {1 unmodified line } else {
initialName = "AKH_"
}
initialName += string(usersCount)
initialName += strconv.Itoa(usersCount)
s.Constructor.InitialName = initialName
userProfile := repositories.UpdateAccountDetails(s.Constructor)
s.Error = userProfile.RowsError
if userProfile.NoRecord {5 unmodified lines Account: repositories.GetAccountById(s.Constructor.AccountID).Result,
Details: userProfile.Result,
}
s.Result.Account.Password = "SECRET"
}14 unmodified lines15161718192021222324252627282914 unmodified lines return *repo
}
func GetAllAccount() Repository[models.Account, []models.Account] {
repo := Construct[models.Account, []models.Account](
models.Account{},
)
repo.Transactions(
Find[models.Account, []models.Account],
)
return *repo
}
func GetAccountById(accountId uint) Repository[models.Account, models.Account] {
repo := Construct[models.Account, models.Account](
models.Account{Id: accountId},32 unmodified lines333435363637383932 unmodified lines })
s.Constructor.AccountID = createAccount.Result.Id
createGoogleAuth := repositories.CreateExternalAuth(s.Constructor)
GoogleAuth.Result.AccountID = createGoogleAuth.Result.ID
s.Error = createGoogleAuth.RowsError
s.Error = errors.Join(s.Error, createAccount.RowsError)
}43 unmodified lines444546474847484923 unmodified lines737475767778798081828384858643 unmodified lines return input
}
func (s *UserProfileService) Create() {
phoneNumber := *s.Constructor.PhoneNumber
*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)
userProfile := repositories.CreateAccountDetails(s.Constructor)
s.Error = userProfile.RowsError
if userProfile.NoRecord {23 unmodified linesfunc (s *UserProfileService) Update() {
phoneNumber := *s.Constructor.PhoneNumber
*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)
usersCount := repositories.GetAllAccount().RowsCount
var initialName string
if *s.Constructor.Gender {
initialName = "IKH_"
} else {
initialName = "AKH_"
}
initialName += string(usersCount)
userProfile := repositories.UpdateAccountDetails(s.Constructor)
s.Error = userProfile.RowsError
if userProfile.NoRecord {23 unmodified lines242526272728293023 unmodified lines ports: - "5432:5432" volumes: - db-data:/var/lib/postgresql/data - /home/qobiltu/postgres-data:/var/lib/postgresql/data restart: always
volumes:27 unmodified lines28293031323334353627 unmodified lines# Copy hasil build dari builder ke image runtimeCOPY --from=builder /app/main .
# Copy folder utils (termasuk file seeder) dari builder ke runtimeCOPY --from=builder /app/utils ./utils
# Copy file .env untuk konfigurasi environmentCOPY .env .env
8 unmodified lines9101112121314158 unmodified lines
func Profile(c *gin.Context) {
userProfile := services.UserProfileService{}
userProfileController := controller.Controller[any, models.AccountDetails, models.AccountDetails]{
userProfileController := controller.Controller[any, models.AccountDetails, models.UserProfileResponse]{
Service: &userProfile.Service,
}
userProfileController.HeaderParse(c, func() {123454562 unmodified lines9101114121314151 unmodified line1718192220212223package user
import (
"fmt"
"api.qobiltu.id/controller"
"api.qobiltu.id/models"
"api.qobiltu.id/services"2 unmodified lines
func UpdateProfile(c *gin.Context) {
userProfile := services.UserProfileService{}
userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.AccountDetails]{
userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.UserProfileResponse]{
Service: &userProfile.Service,
}
1 unmodified line userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request
userUpdateProfileController.HeaderParse(c, func() {
userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID)
fmt.Println("Account ID:", userUpdateProfileController.Service.Constructor.AccountID)
})
userProfile.Update()
},24 unmodified lines252627282930313224 unmodified linestype OptionsResponse struct {
Options []Options `json:"options"`
}
type UserProfileResponse struct {
Account Account `json:"account"`
Details AccountDetails `json:"details"`
}1234545655 unmodified lines6263646768656667package repositories
import (
"fmt"
"api.qobiltu.id/models"
)
55 unmodified lines repo := Construct[models.AccountDetails, models.AccountDetails](
accountDetails,
)
fmt.Println(accountDetails)
fmt.Println("Account ID : ", accountDetails.AccountID)
Create(repo)
return *repo
}12345678910111213141516171819202122package repositories
import "api.qobiltu.id/models"
func CreateForgotPassword(forgotPassword models.ForgotPassword) Repository[models.ForgotPassword, models.ForgotPassword] {
repo := Construct[models.ForgotPassword, models.ForgotPassword](
forgotPassword,
)
Create(repo)
return *repo
}
func GetForgotPasswordByToken(token uint) Repository[models.ForgotPassword, models.ForgotPassword] {
repo := Construct[models.ForgotPassword, models.ForgotPassword](
models.ForgotPassword{Token: token},
)
repo.Transactions(
WhereGivenConstructor[models.ForgotPassword, models.ForgotPassword],
Find[models.ForgotPassword, models.ForgotPassword],
)
return *repo
}services/email_verification_service.go+1-4
services/forgot_password_service.go+1-4
space/services/external_authentication_service.go+18-1
space/space/controller/academy/academy_controller.goAdded+31
space/space/logs/error_log.txt+2
space/space/models/database_orm_model.go+7-7
space/space/repositories/academy_repository.go+28-2
space/space/router/academy_route.goAdded+16
space/space/router/router.go+1-1
space/space/services/academy_service.go+75-11
space/space/services/email_verification_service.go+5-2
space/space/services/forgot_password_service.go+4-1
space/space/space/logs/error_log.txt-1
space/space/space/models/response_model.go+9-6
space/space/space/repositories/academy_repository.goAdded+47
space/space/space/services/academy_service.goAdded+40
space/space/space/services/external_authentication_service.go+1
space/space/space/services/forgot_password_service.go+11-7
space/space/space/space/space/go.mod+2-5
space/space/space/space/space/go.sum+17-13
space/space/space/space/space/space/models/request_model.go+1-1
space/space/space/space/space/space/models/response_model.go+10
space/space/space/space/space/space/services/forgot_password_service.go+7-3
space/space/space/space/space/space/space/controller/auth/auth_external_controller.go+1-1
space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go+28
space/space/space/space/space/space/space/controller/email/email_validate_controller.go-1
space/space/space/space/space/space/space/models/request_model.go+9-4
space/space/space/space/space/space/space/repositories/account_repository.go+2-4
space/space/space/space/space/space/space/router/auth_route.go+2
space/space/space/space/space/space/space/services/authentication_service.go+2-1
space/space/space/space/space/space/space/services/email_verification_service.go+5-1
space/space/space/space/space/space/space/services/external_authentication_service.go+6-1
space/space/space/space/space/space/space/services/forgot_password_service.goAdded+105
space/space/space/space/space/space/space/services/user_profile_service.go+20-5
space/space/space/space/space/space/space/space/space/services/email_verification_service.go+11-60
space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go+60-11
space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go+4-2
space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go+2
space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go+4
space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go+8-3
space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go+9
space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go+1-1
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go+8-2
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml+1-1
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile+3
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go+1-1
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go+2-4
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go+5
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go-4
space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/forgot_password_repository.goAdded+22