Spaces:
Configuration error
Configuration error
Commit ·
14dc9b2
1
Parent(s): b7ebd0e
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)
- config/config.go+2
- services/email_verification_service.go+100-8
- space/services/external_authentication_service.go+10-6
- space/space/services/email_verification_service.go+1-4
- space/space/services/forgot_password_service.go+1-4
- space/space/space/services/external_authentication_service.go+18-1
- space/space/space/space/controller/academy/academy_controller.goAdded+31
- space/space/space/space/logs/error_log.txt+2
- space/space/space/space/models/database_orm_model.go+7-7
- space/space/space/space/repositories/academy_repository.go+28-2
- space/space/space/space/router/academy_route.goAdded+16
- space/space/space/space/router/router.go+1-1
- space/space/space/space/services/academy_service.go+75-11
- space/space/space/space/services/email_verification_service.go+5-2
- space/space/space/space/services/forgot_password_service.go+4-1
- space/space/space/space/space/logs/error_log.txt-1
- space/space/space/space/space/models/response_model.go+9-6
- space/space/space/space/space/repositories/academy_repository.goAdded+47
- space/space/space/space/space/services/academy_service.goAdded+40
- space/space/space/space/space/services/external_authentication_service.go+1
- space/space/space/space/space/services/forgot_password_service.go+11-7
- space/space/space/space/space/space/space/go.mod+2-5
- space/space/space/space/space/space/space/go.sum+17-13
- space/space/space/space/space/space/space/space/models/request_model.go+1-1
- space/space/space/space/space/space/space/space/models/response_model.go+10
- space/space/space/space/space/space/space/space/services/forgot_password_service.go+7-3
- space/space/space/space/space/space/space/space/space/controller/auth/auth_external_controller.go+1-1
- space/space/space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go+28
- space/space/space/space/space/space/space/space/space/controller/email/email_validate_controller.go-1
- space/space/space/space/space/space/space/space/space/models/request_model.go+9-4
- space/space/space/space/space/space/space/space/space/repositories/account_repository.go+2-4
- space/space/space/space/space/space/space/space/space/router/auth_route.go+2
- space/space/space/space/space/space/space/space/space/services/authentication_service.go+2-1
- space/space/space/space/space/space/space/space/space/services/email_verification_service.go+5-1
- space/space/space/space/space/space/space/space/space/services/external_authentication_service.go+6-1
- space/space/space/space/space/space/space/space/space/services/forgot_password_service.goAdded+105
- space/space/space/space/space/space/space/space/space/services/user_profile_service.go+20-5
- space/space/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/space/space/services/email_verification_service.go+60-11
- space/space/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/space/space/services/authentication_service.go+2
- space/space/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/space/space/services/user_profile_service.go+8-3
- space/space/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/space/space/services/external_authentication_service.go+1-1
- space/space/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/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/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/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/space/space/controller/user/user_update_profile_controller.go+2-4
6 unmodified lines7891011128 unmodified lines2122232425266 unmodified lines"github.com/joho/godotenv")var TCP_ADDRESS stringvar LOG_PATH string8 unmodified linesfunc init() {godotenv.Load()HOST_ADDRESS = os.Getenv("HOST_ADDRESS")HOST_PORT = os.Getenv("HOST_PORT")TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT6 unmodified lines789101112138 unmodified lines222324252627286 unmodified lines"github.com/joho/godotenv")var ENV stringvar TCP_ADDRESS stringvar LOG_PATH string8 unmodified linesfunc init() {godotenv.Load()ENV = os.Getenv("ENV")HOST_ADDRESS = os.Getenv("HOST_ADDRESS")HOST_PORT = os.Getenv("HOST_PORT")TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT
12345632 unmodified lines394041424344454647484950515253545556575859606162636465package servicesimport ("fmt""log""math/rand/v2"32 unmodified lines// ⬇ Kirim token ke email user menggunakan SMTPgo func(toEmail string, token uint) {from := config.SMTP_SENDER_EMAILpassword := config.SMTP_SENDER_PASSWORDsmtpHost := config.SMTP_HOSTsmtpPort := config.SMTP_PORTauth := smtp.PlainAuth("", from, password, smtpHost)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 = errlog.Printf("Error sending verification email: %v", err)return}}(accountRepo.Result.Email, token)// s.Result.Token = 0}123456732 unmodified lines404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157package servicesimport ("crypto/tls""fmt""log""math/rand/v2"32 unmodified lines// ⬇ Kirim token ke email user menggunakan SMTPgo func(toEmail string, token uint) {env := config.ENVfrom := config.SMTP_SENDER_EMAILpassword := config.SMTP_SENDER_PASSWORDsmtpHost := config.SMTP_HOSTsmtpPort := config.SMTP_PORTto := []string{toEmail}subject := "Verification token"body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token)msg := []byte(fmt.Sprintf("From: %s\r\n", from) +fmt.Sprintf("To: %s\r\n", toEmail) +fmt.Sprintf("Subject: %s\r\n", subject) +"\r\n" + body)// 1. Connect to the serverconn, err := tls.Dial("tcp", fmt.Sprintf("[%s]:%s", smtpHost, smtpPort), &tls.Config{InsecureSkipVerify: env != "production", // ⚠️ set false di productionServerName: smtpHost,})// conn, err := net.Dial("tcp", fmt.Sprintf("[%s]:%s", smtpHost, smtpPort))if err != nil {s.Error = errlog.Printf("Error sending verification email: %v", err)return}c, err := smtp.NewClient(conn, smtpHost)if err != nil {s.Error = errlog.Printf("Error create new client mail: %v", err)return}// 2. Start TLStlsconfig := &tls.Config{ServerName: smtpHost,}if err = c.StartTLS(tlsconfig); err != nil {s.Error = errlog.Printf("Error start TLS: %v", err)return}// 3. Authauth := smtp.PlainAuth("", from, password, smtpHost)if err = c.Auth(auth); err != nil {s.Error = errlog.Printf("Error auth mail: %v", err)return}// 4. Set From and Toif err = c.Mail(from); err != nil {s.Error = errlog.Printf("Error set mail from to: %v", err)return}for _, addr := range to {if err = c.Rcpt(addr); err != nil {s.Error = errlog.Printf("Error receipt addr: %v", err)return}}// 5. Send messagewc, err := c.Data()if err != nil {s.Error = errlog.Printf("Error data Send Message: %v", err)return}_, err = wc.Write(msg)if err != nil {s.Error = errlog.Printf("Error write Send Message: %v", err)return}err = wc.Close()if err != nil {s.Error = errlog.Printf("Error close Send Message: %v", err)return}c.Quit()fmt.Println("Email sent successfully!")// auth := smtp.PlainAuth("", from, password, smtpHost)// 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// } else {// log.Printf("Successfully sending verification email: %v", err)// }}(accountRepo.Result.Email, token)// s.Result.Token = 0}
23 unmodified lines2425262728292 unmodified lines32333435363738394041424323 unmodified linesreturn}email := payload.Claims["email"]if GoogleAuth.NoRecord {if !isAgree {s.Exception.BadRequest = true2 unmodified lines}s.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"checkRegisteredEmail := repositories.GetAccountbyEmail(email.(string))if !checkRegisteredEmail.NoRecord {s.Exception.DataDuplicate = trues.Exception.Message = "Account with email" + email.(string) + "already registered!"return}createAccount := repositories.CreateAccount(models.Account{UUID: uuid.NewV4(),23 unmodified lines242526272829303132333435363738392 unmodified lines42434445464723 unmodified linesreturn}email := payload.Claims["email"]checkRegisteredEmail := repositories.GetAccountbyEmail(email.(string))if !checkRegisteredEmail.NoRecord {token, _ := GenerateToken(&checkRegisteredEmail.Result)checkRegisteredEmail.Result.Password = "SECRET"s.Result = models.AuthenticatedUser{Account: checkRegisteredEmail.Result,Token: token,}return}if GoogleAuth.NoRecord {if !isAgree {s.Exception.BadRequest = true2 unmodified lines}s.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"createAccount := repositories.CreateAccount(models.Account{UUID: uuid.NewV4(),
28 unmodified lines2930313233343536373828 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)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)28 unmodified lines2930313233343528 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)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 lines3435363738394041424333 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)token := uint(rand.IntN(1000000))for token < 1000000 {token = uint(rand.IntN(1000000))}s.Constructor.UUID = uuid.NewV4()s.Constructor.ExpiredAt = dueTimes.Constructor.AccountID = accountRepo.Result.Id33 unmodified lines3435363738394033 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)token := uint(rand.IntN(999999-100000) + 100000)s.Constructor.UUID = uuid.NewV4()s.Constructor.ExpiredAt = dueTimes.Constructor.AccountID = accountRepo.Result.Id
31 unmodified lines323334353637383940414243444546474831 unmodified lines}s.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"createAccount := repositories.CreateAccount(models.Account{UUID: uuid.NewV4(),Email: email.(string),IsEmailVerified: true,})s.Constructor.AccountID = createAccount.Result.IdcreateGoogleAuth := repositories.CreateExternalAuth(s.Constructor)GoogleAuth.Result.AccountID = createGoogleAuth.Result.IDs.Error = createGoogleAuth.RowsErrors.Error = errors.Join(s.Error, createAccount.RowsError)}accountData := repositories.GetAccountById(GoogleAuth.Result.AccountID)token, err_tok := GenerateToken(&accountData.Result)31 unmodified lines3233343536373839404142434445464748495051525354555657585960616263646531 unmodified lines}s.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"checkRegisteredEmail := repositories.GetAccountbyEmail(email.(string))if !checkRegisteredEmail.NoRecord {s.Exception.DataDuplicate = trues.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.IdcreateGoogleAuth := repositories.CreateExternalAuth(s.Constructor)GoogleAuth.Result.AccountID = createGoogleAuth.Result.AccountIDuserProfile := UserProfileService{}userProfile.Constructor.AccountID = GoogleAuth.Result.AccountIDuserProfile.Create()if userProfile.Error != nil {s.Error = userProfile.Errorreturn}s.Error = createGoogleAuth.RowsErrors.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 allowed
29 unmodified lines3031323334353648 unmodified lines85868788899091929394959629 unmodified linesLastEducation *string `json:"last_education"`MaritalStatus *string `json:"marital_status"`Avatar *string `json:"avatar"`PhoneNumber *uint `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"`}type OptionCategory struct {ID uint `gorm:"primaryKey" json:"id"`29 unmodified lines3031323334353648 unmodified lines85868788899091929394959629 unmodified linesLastEducation *string `json:"last_education"`MaritalStatus *string `json:"marital_status"`Avatar *string `json:"avatar"`PhoneNumber *string `json:"phone_number"`}type EmailVerification struct {48 unmodified lines}type AcademyContent struct {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 lines13141516171819202123 unmodified lines45464712 unmodified linesreturn *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],23 unmodified lines)return *repo}12 unmodified lines13141516171819202123 unmodified lines454647484950515253545556575859606162636465666768697071727312 unmodified linesreturn *repo}func GetAcademyDataBySlug(slug string) Repository[models.Academy, models.Academy] {repo := Construct[models.Academy, models.Academy](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 lines1617181920212215 unmodified linesUserRoute(router)EmailRoute(router)OptionsRoute(router)err := router.Run(config.TCP_ADDRESS)if err != nil {log.Fatalf("Failed to run server: %v", err)15 unmodified lines1617181920212215 unmodified linesUserRoute(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 lines3456789101112131415161718192021222324252627282930313233343536373839402 unmodified linesimport ("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.RowsErrorif AcademyRepo.NoRecord {s.Exception.Message = "Academy not found"s.Exception.DataNotFound = truereturn}var ArrMaterials []models.AcademyMaterialResponsefor _, 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()}}2 unmodified lines34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031042 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.AcademyMaterialResponsefor _, 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.Slug != "" {AcademyRepo := repositories.GetAcademyDataBySlug(s.Constructor.Slug)s.Error = AcademyRepo.RowsErrorif AcademyRepo.NoRecord {s.Exception.Message = "Academy not found"s.Exception.DataNotFound = truereturn}s.Result = models.AllAcademyResponse{Academies: []models.AcademyResponse{models.AcademyResponse{Academy: AcademyRepo.Result,Materials: castAcademyMaterials(s.Constructor.ID),},},}} else {AcademyRepo := repositories.GetAllAcademy()s.Error = AcademyRepo.RowsErrorvar ArrAcademy []models.AcademyResponsefor _, 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.AcademyResponsefor _, 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.RowsErrorreturn}for _, material := range academy.Materials {material.Materials.AcademyID = createdAcademy.Result.IDmaterial.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.RowsErrorreturn}for _, content := range material.Contents {content.UUID = uuid.NewV4()content.AcademyMaterialID = createdMaterial.Result.IDcreatedContent := repositories.CreateAcademyContent(content)if createdContent.RowsError != nil {s.Error = createdContent.RowsErrorreturn}ArrAcademy = append(ArrAcademy, models.AcademyResponse{Academy: createdAcademy.Result,Materials: castAcademyMaterials(createdAcademy.Result.ID),})}}}s.Result = models.AllAcademyResponse{Academies: ArrAcademy}}
28 unmodified lines2930313233343547 unmodified lines8384858687888928 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)token := uint(rand.IntN(100000))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 = truerepositories.UpdateAccount(account.Result)s.Result = repo.Result}28 unmodified lines2930313233343536373847 unmodified lines8687888990919228 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)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 = truerepositories.UpdateAccount(account.Result)s.Result = repo.Result}
33 unmodified lines3435363738394033 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)token := uint(rand.IntN(100000))s.Constructor.UUID = uuid.NewV4()s.Constructor.ExpiredAt = dueTimes.Constructor.AccountID = accountRepo.Result.Id33 unmodified lines3435363738394041424333 unmodified linesremainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.HourdueTime := CalculateDueTime(remainingTime)token := uint(rand.IntN(1000000))for token < 1000000 {token = uint(rand.IntN(1000000))}s.Constructor.UUID = uuid.NewV4()s.Constructor.ExpiredAt = dueTimes.Constructor.AccountID = accountRepo.Result.Id
1
30 unmodified lines31323334353637383940414230 unmodified linesDetails 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"`}30 unmodified lines31323334353637383940414243444530 unmodified linesDetails AccountDetails `json:"details"`}type AcademyMaterialResponse struct {Materials AcademyMaterialContents []AcademyContent}type AcademyResponse struct {Academy Academy `json:"academy"`Materials []AcademyMaterialResponse `json:"academy_materials"`}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 lines33343536373832 unmodified liness.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"createAccount := repositories.CreateAccount(models.Account{Email: email.(string),IsEmailVerified: true,})32 unmodified lines3334353637383932 unmodified liness.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"createAccount := repositories.CreateAccount(models.Account{UUID: uuid.NewV4(),Email: email.(string),IsEmailVerified: true,})
70 unmodified lines717273747576777879808182837 unmodified lines91929394959697989910010110210370 unmodified lines}func (s *ForgotPasswordService) Validate(newPassword *string) {accountRepo := repositories.GetAccountById(s.Constructor.AccountID)if accountRepo.NoRecord {s.Error = accountRepo.RowsErrors.Exception.DataNotFound = trues.Exception.Message = "There is no account data with given credentials!"return}fgPasswordRepo := repositories.GetForgotPasswordByToken(s.Constructor.Token)s.Error = fgPasswordRepo.RowsError7 unmodified liness.Exception.Message = "Token has expired!"return}s.Result = fgPasswordRepo.Resultif newPassword == nil {return}hashed_password, _ := HashPassword(*newPassword)accountRepo.Result.Password = hashed_passwordchangePassword := repositories.UpdateAccount(accountRepo.Result)if changePassword.RowsError != nil {s.Error = changePassword.RowsErrors.Exception.QueryError = true70 unmodified lines7172737475767 unmodified lines8485868788899091929394959697989910010110210310410510610770 unmodified lines}func (s *ForgotPasswordService) Validate(newPassword *string) {fgPasswordRepo := repositories.GetForgotPasswordByToken(s.Constructor.Token)s.Error = fgPasswordRepo.RowsError7 unmodified liness.Exception.Message = "Token has expired!"return}accountRepo := repositories.GetAccountById(fgPasswordRepo.Result.AccountID)if accountRepo.NoRecord {s.Error = accountRepo.RowsErrors.Exception.DataNotFound = trues.Exception.Message = "There is no account data with given credentials!"return}s.Result = fgPasswordRepo.Resultif newPassword == nil {return}// fmt.Println("Previous Account", accountRepo.Result)// fmt.Println("New password", *newPassword)hashed_password, _ := HashPassword(*newPassword)accountRepo.Result.Password = hashed_passwordchangePassword := repositories.UpdateAccount(accountRepo.Result)// fmt.Println("New Account", changePassword.Result)if changePassword.RowsError != nil {s.Error = changePassword.RowsErrors.Exception.QueryError = true
4 unmodified lines567891011121317 unmodified lines313233343536373 unmodified lines414243444546474849505152532 unmodified lines565758596061626364656667684 unmodified linesrequire (github.com/gin-gonic/gin v1.10.0github.com/golang-jwt/jwt/v5 v5.2.1github.com/joho/godotenv v1.5.1github.com/satori/go.uuid v1.2.0golang.org/x/crypto v0.36.0gorm.io/driver/postgres v1.5.11gorm.io/gorm v1.25.12)17 unmodified linesgithub.com/google/s2a-go v0.1.9 // indirectgithub.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirectgithub.com/googleapis/gax-go/v2 v2.14.1 // indirectgithub.com/gosimple/slug v1.15.0 // indirectgithub.com/gosimple/unidecode v1.0.1 // indirectgithub.com/jackc/pgpassfile v1.0.0 // indirectgithub.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect3 unmodified linesgithub.com/jinzhu/now v1.1.5 // indirectgithub.com/json-iterator/go v1.1.12 // indirectgithub.com/klauspost/cpuid/v2 v2.2.10 // indirectgithub.com/kr/text v0.2.0 // indirectgithub.com/leodido/go-urn v1.4.0 // indirectgithub.com/mattn/go-isatty v0.0.20 // indirectgithub.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirectgithub.com/modern-go/reflect2 v1.0.2 // indirectgithub.com/pelletier/go-toml/v2 v2.2.3 // indirectgithub.com/rogpeppe/go-internal v1.13.1 // indirectgithub.com/twitchyliquid64/golang-asm v0.15.1 // indirectgithub.com/ugorji/go/codec v1.2.12 // indirectgo.opentelemetry.io/auto/sdk v1.1.0 // indirect2 unmodified linesgo.opentelemetry.io/otel/metric v1.34.0 // indirectgo.opentelemetry.io/otel/trace v1.34.0 // indirectgolang.org/x/arch v0.15.0 // indirectgolang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirectgolang.org/x/net v0.37.0 // indirectgolang.org/x/oauth2 v0.28.0 // indirectgolang.org/x/sync v0.12.0 // indirectgolang.org/x/sys v0.31.0 // indirectgolang.org/x/text v0.23.0 // indirectgoogle.golang.org/api v0.228.0 // indirectgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirectgoogle.golang.org/grpc v1.71.0 // indirectgoogle.golang.org/protobuf v1.36.6 // indirect4 unmodified lines5678910111213141517 unmodified lines3334353637383 unmodified lines42434445464748495051522 unmodified lines55565758596061626364654 unmodified linesrequire (github.com/gin-gonic/gin v1.10.0github.com/golang-jwt/jwt/v5 v5.2.1github.com/gosimple/slug v1.15.0github.com/joho/godotenv v1.5.1github.com/satori/go.uuid v1.2.0golang.org/x/crypto v0.36.0google.golang.org/api v0.228.0gorm.io/driver/postgres v1.5.11gorm.io/gorm v1.25.12)17 unmodified linesgithub.com/google/s2a-go v0.1.9 // indirectgithub.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirectgithub.com/googleapis/gax-go/v2 v2.14.1 // indirectgithub.com/gosimple/unidecode v1.0.1 // indirectgithub.com/jackc/pgpassfile v1.0.0 // indirectgithub.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect3 unmodified linesgithub.com/jinzhu/now v1.1.5 // indirectgithub.com/json-iterator/go v1.1.12 // indirectgithub.com/klauspost/cpuid/v2 v2.2.10 // indirectgithub.com/leodido/go-urn v1.4.0 // indirectgithub.com/mattn/go-isatty v0.0.20 // indirectgithub.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirectgithub.com/modern-go/reflect2 v1.0.2 // indirectgithub.com/pelletier/go-toml/v2 v2.2.3 // indirectgithub.com/twitchyliquid64/golang-asm v0.15.1 // indirectgithub.com/ugorji/go/codec v1.2.12 // indirectgo.opentelemetry.io/auto/sdk v1.1.0 // indirect2 unmodified linesgo.opentelemetry.io/otel/metric v1.34.0 // indirectgo.opentelemetry.io/otel/trace v1.34.0 // indirectgolang.org/x/arch v0.15.0 // indirectgolang.org/x/net v0.37.0 // indirectgolang.org/x/oauth2 v0.28.0 // indirectgolang.org/x/sync v0.12.0 // indirectgolang.org/x/sys v0.31.0 // indirectgolang.org/x/text v0.23.0 // indirectgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirectgoogle.golang.org/grpc v1.71.0 // indirectgoogle.golang.org/protobuf v1.36.6 // indirect
11 unmodified lines1213141516171822 unmodified lines414243444546474849505122 unmodified lines74757677787980819 unmodified lines919293949596979815 unmodified lines1141151161171181191201211221231241251261271281291301311321335 unmodified lines13914014114214314414514614714814915015115215315411 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/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/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/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/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/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/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=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=11 unmodified lines12131415161722 unmodified lines40414243444546474849505152535422 unmodified lines77787980818283849 unmodified lines94959697989910015 unmodified lines1161171181191201211221231241251261271281291301311321331341351361371381395 unmodified lines14514614714814915015115215315415515615715811 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/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/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.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.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/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/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.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 lines383940414237 unmodified lines}type ValidateForgotPasswordRequest struct {Token uint `json:"token" binding:"required"`NewPassword string `json:"new_password" binding:"required"`}37 unmodified lines383940414237 unmodified lines}type ValidateForgotPasswordRequest struct {Token uint `json:"token" binding:"required"`NewPassword string `json:"new_password"`}
29 unmodified lines30313229 unmodified linesAccount Account `json:"account"`Details AccountDetails `json:"details"`}29 unmodified lines3031323334353637383940414229 unmodified linesAccount 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 lines7071727374757614 unmodified lines919293949596973 unmodified lines10110210310410569 unmodified lines// s.Result.Token = 0}func (s *ForgotPasswordService) Validate(newPassword string) {accountRepo := repositories.GetAccountById(s.Constructor.AccountID)if accountRepo.NoRecord {s.Error = accountRepo.RowsError14 unmodified liness.Exception.Message = "Token has expired!"return}hashed_password, _ := HashPassword(newPassword)accountRepo.Result.Password = hashed_passwordchangePassword := repositories.UpdateAccount(accountRepo.Result)if changePassword.RowsError != nil {3 unmodified linesreturn}// fgPasswordRepo.Result.Token = 0s.Result = fgPasswordRepo.Result}69 unmodified lines7071727374757614 unmodified lines9192939495969798991001013 unmodified lines10510610710810969 unmodified lines// s.Result.Token = 0}func (s *ForgotPasswordService) Validate(newPassword *string) {accountRepo := repositories.GetAccountById(s.Constructor.AccountID)if accountRepo.NoRecord {s.Error = accountRepo.RowsError14 unmodified liness.Exception.Message = "Token has expired!"return}s.Result = fgPasswordRepo.Resultif newPassword == nil {return}hashed_password, _ := HashPassword(*newPassword)accountRepo.Result.Password = hashed_passwordchangePassword := repositories.UpdateAccount(accountRepo.Result)if changePassword.RowsError != nil {3 unmodified linesreturn}// fgPasswordRepo.Result.Token = 0}
13 unmodified lines1415161718192013 unmodified linesGoogleLogin := services.GoogleAuthService{}ExternalAuthController.Service = &GoogleLogin.ServiceExternalAuthController.Service.Constructor.OauthID = ExternalAuthController.Request.OauthIDGoogleLogin.Authenticate()}})}13 unmodified lines1415161718192013 unmodified linesGoogleLogin := services.GoogleAuthService{}ExternalAuthController.Service = &GoogleLogin.ServiceExternalAuthController.Service.Constructor.OauthID = ExternalAuthController.Request.OauthIDGoogleLogin.Authenticate(ExternalAuthController.Request.IsAgreeTerms && !ExternalAuthController.Request.IsSexualDisease)}})}
1package auth1234567891011121314151617181920212223242526272829package authimport ("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.TokenForgotPassword.Validate(&ForgotPasswordController.Request.NewPassword)})}
15 unmodified lines1617181920212215 unmodified linesemailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID)emailVerificationController.RequestJSON(c, func() {emailVerificationController.Service.Constructor.Token = emailVerificationController.Request.TokenemailVerificationController.Service.Constructor.UUID = emailVerificationController.Request.UUIDemailVerification.Validate()})})15 unmodified lines16171819202115 unmodified linesemailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID)emailVerificationController.RequestJSON(c, func() {emailVerificationController.Service.Constructor.Token = emailVerificationController.Request.TokenemailVerification.Validate()})})
123456712 unmodified lines20212223242526277 unmodified lines353637package modelsimport 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"`}type OptionsRequest struct {7 unmodified linesIsAgreeTerms bool `json:"is_agree_terms"`IsSexualDisease bool `json:"is_sexual_disease"`}1234512 unmodified lines181920212223247 unmodified lines3233343536373839404142package modelstype 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"`}type OptionsRequest struct {7 unmodified linesIsAgreeTerms 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"`}
38 unmodified lines3940414243444546474838 unmodified linesrepo := Construct[models.Account, models.Account](account,)repo.Transactions(WhereGivenConstructor[models.Account, models.Account],Update[models.Account],)return *repo}38 unmodified lines394041424344454638 unmodified linesrepo := Construct[models.Account, models.Account](account,)repo.Transaction.Save(&repo.Constructor)repo.Result = repo.Constructorreturn *repo}
12 unmodified lines131415161712 unmodified linesrouterGroup.POST("/login", AuthController.Login)routerGroup.POST("/register", AuthController.Register)routerGroup.PUT("/change-password", middleware.AuthUser, AuthController.ChangePassword)}}12 unmodified lines1314151617181912 unmodified linesrouterGroup.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 lines5859606162636457 unmodified liness.Exception.Message = "incorrect old password!"return}accountData.Result.Password = newPasswordchangePassword := repositories.UpdateAccount(accountData.Result)changePassword.Result.Password = "SECRET"s.Result = models.AuthenticatedUser{57 unmodified lines585960616263646557 unmodified liness.Exception.Message = "incorrect old password!"return}hashed_password, _ := HashPassword(newPassword)accountData.Result.Password = hashed_passwordchangePassword := repositories.UpdateAccount(accountData.Result)changePassword.Result.Password = "SECRET"s.Result = models.AuthenticatedUser{
60 unmodified lines61626364656613 unmodified lines808182838485868760 unmodified linesreturn}}(accountRepo.Result.Email, token)}func (s *EmailVerificationService) Validate() {13 unmodified liness.Delete()return}s.Result = repo.Results.Delete()}func (s *EmailVerificationService) Delete() {60 unmodified lines6162636465666713 unmodified lines818283848586878889909160 unmodified linesreturn}}(accountRepo.Result.Email, token)// s.Result.Token = 0}func (s *EmailVerificationService) Validate() {13 unmodified liness.Delete()return}account := repositories.GetAccountById(repo.Result.AccountID)account.Result.IsEmailVerified = truerepositories.UpdateAccount(account.Result)s.Result = repo.Result}func (s *EmailVerificationService) Delete() {
13 unmodified lines141516171819204 unmodified lines25262728293013 unmodified linesService[models.ExternalAuth, models.AuthenticatedUser]}func (s *GoogleAuthService) Authenticate() {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 {s.Constructor.UUID = uuid.NewV4()s.Constructor.OauthProvider = "Google"createAccount := repositories.CreateAccount(models.Account{13 unmodified lines141516171819204 unmodified lines252627282930313233343513 unmodified linesService[models.ExternalAuth, models.AuthenticatedUser]}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 = trues.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 lines6970717273743 unmodified lines78798081828384858687883 unmodified lines929394959697989968 unmodified linesAccount: repositories.GetAccountById(s.Constructor.AccountID).Result,Details: userProfile.Result,}}func (s *UserProfileService) Update() {3 unmodified lines}usersCount := repositories.GetAllAccount().RowsCountvar initialName stringif *s.Constructor.Gender {initialName = "IKH_"} else {initialName = "AKH_"}initialName += strconv.Itoa(usersCount)s.Constructor.InitialName = initialNameuserProfile := repositories.UpdateAccountDetails(s.Constructor)3 unmodified liness.Exception.Message = "There is no account with given credentials!"return}s.Result = models.UserProfileResponse{Account: repositories.GetAccountById(s.Constructor.AccountID).Result,Details: userProfile.Result,}s.Result.Account.Password = "SECRET"68 unmodified lines697071727374753 unmodified lines79808182838485868788899091923 unmodified lines9697989910010110210310410510610710810911011111211311468 unmodified linesAccount: repositories.GetAccountById(s.Constructor.AccountID).Result,Details: userProfile.Result,}s.Result.Account.Password = "SECRET"}func (s *UserProfileService) Update() {3 unmodified lines}usersCount := repositories.GetAllAccount().RowsCountvar initialName stringif s.Constructor.Gender != nil {if *s.Constructor.Gender {initialName = "IKH_"} else {initialName = "AKH_"}}initialName += strconv.Itoa(usersCount)s.Constructor.InitialName = initialNameuserProfile := repositories.UpdateAccountDetails(s.Constructor)3 unmodified liness.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: account.Result,Details: userProfile.Result,}s.Result.Account.Password = "SECRET"
1234567835 unmodified lines4445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114package servicesimport ("crypto/tls""fmt""math/rand/v2""net/smtp""time"35 unmodified linessmtpHost := config.SMTP_HOSTsmtpPort := config.SMTP_PORTtlsconfig := &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)}to := []string{toEmail}for _, addr := range to {if err = client.Rcpt(addr); err != nil {panic(err)}}wc, err := client.Data()if err != nil {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)}1234567835 unmodified lines44454647484950515253545556575859606162636465package servicesimport ("fmt""log""math/rand/v2""net/smtp""time"35 unmodified linessmtpHost := config.SMTP_HOSTsmtpPort := config.SMTP_PORTauth := smtp.PlainAuth("", from, password, smtpHost)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 = errlog.Printf("Error sending verification email: %v", err)return}}(accountRepo.Result.Email, token)}
1234567835 unmodified lines44454647484950515253545556575859606162636465package servicesimport ("fmt""log""math/rand/v2""net/smtp""time"35 unmodified linessmtpHost := config.SMTP_HOSTsmtpPort := config.SMTP_PORTauth := smtp.PlainAuth("", from, password, smtpHost)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 = errlog.Printf("Error sending verification email: %v", err)return}}(accountRepo.Result.Email, token)}1234567835 unmodified lines4445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114package servicesimport ("crypto/tls""fmt""math/rand/v2""net/smtp""time"35 unmodified linessmtpHost := config.SMTP_HOSTsmtpPort := config.SMTP_PORTtlsconfig := &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)}to := []string{toEmail}for _, addr := range to {if err = client.Rcpt(addr); err != nil {panic(err)}}wc, err := client.Data()if err != nil {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 lines30313233343529 unmodified lines}type ExternalAuthRequest struct {OauthID string `json:"oauth_id" binding:"required"`OauthProvider string `json:"oauth_provider" binding:"required"`}29 unmodified lines303132333435363729 unmodified lines}type ExternalAuthRequest struct {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 lines1819202122234 unmodified lines28293031323317 unmodified liness.Exception.Message = "there is no account with given credentials!"return}if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {s.Exception.Unauthorized = trues.Exception.Message = "incorrect password!"4 unmodified linesif err_tok != nil {s.Error = errors.Join(s.Error, err_tok)}accountData.Result.Password = "SECRET"17 unmodified lines181920212223244 unmodified lines2930313233343517 unmodified liness.Exception.Message = "there is no account with given credentials!"return}if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {s.Exception.Unauthorized = trues.Exception.Message = "incorrect password!"4 unmodified linesif err_tok != nil {s.Error = errors.Join(s.Error, err_tok)return}accountData.Result.Password = "SECRET"
55 unmodified lines5657585960616212 unmodified lines75767778798081828355 unmodified lineserr := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)if err != nil {log.Printf("Error sending verification email: %v", err)}}(accountRepo.Result.Email, token)}12 unmodified liness.Exception.Unauthorized = trues.Exception.Message = "Token has expired!"repositories.UpdateExpiredEmailVerification(s.Constructor.UUID)return}s.Result = repo.Result}func (s *EmailVerificationService) Delete() {55 unmodified lines56575859606162636412 unmodified lines777879808182838485868755 unmodified lineserr := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg)if err != nil {s.Error = errlog.Printf("Error sending verification email: %v", err)return}}(accountRepo.Result.Email, token)}12 unmodified liness.Exception.Unauthorized = trues.Exception.Message = "Token has expired!"repositories.UpdateExpiredEmailVerification(s.Constructor.UUID)s.Delete()return}s.Result = repo.Results.Delete()}func (s *EmailVerificationService) Delete() {
1 unmodified line23456763 unmodified lines71727374757677781 unmodified line808182838485865 unmodified lines929394951 unmodified lineimport ("regexp""strings""api.qobiltu.id/models"63 unmodified lines}func (s *UserProfileService) Update() {phoneNumber := *s.Constructor.PhoneNumber*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)usersCount := repositories.GetAllAccount().RowsCountvar initialName stringif *s.Constructor.Gender {1 unmodified line} else {initialName = "AKH_"}initialName += string(usersCount)userProfile := repositories.UpdateAccountDetails(s.Constructor)s.Error = userProfile.RowsErrorif userProfile.NoRecord {5 unmodified linesAccount: repositories.GetAccountById(s.Constructor.AccountID).Result,Details: userProfile.Result,}}1 unmodified line234567863 unmodified lines727374757677787980811 unmodified line83848586878889905 unmodified lines969798991001 unmodified lineimport ("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)}usersCount := repositories.GetAllAccount().RowsCountvar initialName stringif *s.Constructor.Gender {1 unmodified line} else {initialName = "AKH_"}initialName += strconv.Itoa(usersCount)s.Constructor.InitialName = initialNameuserProfile := repositories.UpdateAccountDetails(s.Constructor)s.Error = userProfile.RowsErrorif userProfile.NoRecord {5 unmodified linesAccount: repositories.GetAccountById(s.Constructor.AccountID).Result,Details: userProfile.Result,}s.Result.Account.Password = "SECRET"}
14 unmodified lines15161718192014 unmodified linesreturn *repo}func GetAccountById(accountId uint) Repository[models.Account, models.Account] {repo := Construct[models.Account, models.Account](models.Account{Id: accountId},14 unmodified lines15161718192021222324252627282914 unmodified linesreturn *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 lines3334353637383932 unmodified lines})s.Constructor.AccountID = createAccount.Result.IdcreateGoogleAuth := repositories.CreateExternalAuth(s.Constructor)s.Error = createGoogleAuth.RowsErrors.Error = errors.Join(s.Error, createAccount.RowsError)}32 unmodified lines3334353637383932 unmodified lines})s.Constructor.AccountID = createAccount.Result.IdcreateGoogleAuth := repositories.CreateExternalAuth(s.Constructor)GoogleAuth.Result.AccountID = createGoogleAuth.Result.IDs.Error = createGoogleAuth.RowsErrors.Error = errors.Join(s.Error, createAccount.RowsError)}
43 unmodified lines444546474849505123 unmodified lines75767778798043 unmodified linesreturn input}func (s *UserProfileService) Create() {phoneNumber := *s.Constructor.PhoneNumber*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)userProfile := repositories.CreateAccountDetails(s.Constructor)s.Error = userProfile.RowsErrorif userProfile.NoRecord {23 unmodified linesfunc (s *UserProfileService) Update() {phoneNumber := *s.Constructor.PhoneNumber*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)userProfile := repositories.UpdateAccountDetails(s.Constructor)s.Error = userProfile.RowsErrorif userProfile.NoRecord {43 unmodified lines44454647484923 unmodified lines737475767778798081828384858643 unmodified linesreturn input}func (s *UserProfileService) Create() {userProfile := repositories.CreateAccountDetails(s.Constructor)s.Error = userProfile.RowsErrorif userProfile.NoRecord {23 unmodified linesfunc (s *UserProfileService) Update() {phoneNumber := *s.Constructor.PhoneNumber*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)usersCount := repositories.GetAllAccount().RowsCountvar initialName stringif *s.Constructor.Gender {initialName = "IKH_"} else {initialName = "AKH_"}initialName += string(usersCount)userProfile := repositories.UpdateAccountDetails(s.Constructor)s.Error = userProfile.RowsErrorif userProfile.NoRecord {
23 unmodified lines2425262728293023 unmodified linesports:- "5432:5432"volumes:- db-data:/var/lib/postgresql/datarestart: alwaysvolumes:23 unmodified lines2425262728293023 unmodified linesports:- "5432:5432"volumes:- /home/qobiltu/postgres-data:/var/lib/postgresql/datarestart: alwaysvolumes:
27 unmodified lines28293031323327 unmodified lines# Copy hasil build dari builder ke image runtimeCOPY --from=builder /app/main .# Copy file .env untuk konfigurasi environmentCOPY .env .env27 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 lines91011121314158 unmodified linesfunc Profile(c *gin.Context) {userProfile := services.UserProfileService{}userProfileController := controller.Controller[any, models.AccountDetails, models.AccountDetails]{Service: &userProfile.Service,}userProfileController.HeaderParse(c, func() {8 unmodified lines91011121314158 unmodified linesfunc Profile(c *gin.Context) {userProfile := services.UserProfileService{}userProfileController := controller.Controller[any, models.AccountDetails, models.UserProfileResponse]{Service: &userProfile.Service,}userProfileController.HeaderParse(c, func() {
123456782 unmodified lines111213141516171 unmodified line19202122232425package userimport ("fmt""api.qobiltu.id/controller""api.qobiltu.id/models""api.qobiltu.id/services"2 unmodified linesfunc UpdateProfile(c *gin.Context) {userProfile := services.UserProfileService{}userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.AccountDetails]{Service: &userProfile.Service,}1 unmodified lineuserUpdateProfileController.Service.Constructor = userUpdateProfileController.RequestuserUpdateProfileController.HeaderParse(c, func() {userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID)fmt.Println("Account ID:", userUpdateProfileController.Service.Constructor.AccountID)})userProfile.Update()},1234562 unmodified lines91011121314151 unmodified line17181920212223package userimport ("api.qobiltu.id/controller""api.qobiltu.id/models""api.qobiltu.id/services"2 unmodified linesfunc UpdateProfile(c *gin.Context) {userProfile := services.UserProfileService{}userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.UserProfileResponse]{Service: &userProfile.Service,}1 unmodified lineuserUpdateProfileController.Service.Constructor = userUpdateProfileController.RequestuserUpdateProfileController.HeaderParse(c, func() {userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID)})userProfile.Update()},
config/config.go+2
services/email_verification_service.go+100-8
space/services/external_authentication_service.go+10-6
space/space/services/email_verification_service.go+1-4
space/space/services/forgot_password_service.go+1-4
space/space/space/services/external_authentication_service.go+18-1
space/space/space/space/controller/academy/academy_controller.goAdded+31
space/space/space/space/logs/error_log.txt+2
space/space/space/space/models/database_orm_model.go+7-7
space/space/space/space/repositories/academy_repository.go+28-2
space/space/space/space/router/academy_route.goAdded+16
space/space/space/space/router/router.go+1-1
space/space/space/space/services/academy_service.go+75-11
space/space/space/space/services/email_verification_service.go+5-2
space/space/space/space/services/forgot_password_service.go+4-1
space/space/space/space/space/logs/error_log.txt-1
space/space/space/space/space/models/response_model.go+9-6
space/space/space/space/space/repositories/academy_repository.goAdded+47
space/space/space/space/space/services/academy_service.goAdded+40
space/space/space/space/space/services/external_authentication_service.go+1
space/space/space/space/space/services/forgot_password_service.go+11-7
space/space/space/space/space/space/space/go.mod+2-5
space/space/space/space/space/space/space/go.sum+17-13
space/space/space/space/space/space/space/space/models/request_model.go+1-1
space/space/space/space/space/space/space/space/models/response_model.go+10
space/space/space/space/space/space/space/space/services/forgot_password_service.go+7-3
space/space/space/space/space/space/space/space/space/controller/auth/auth_external_controller.go+1-1
space/space/space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go+28
space/space/space/space/space/space/space/space/space/controller/email/email_validate_controller.go-1
space/space/space/space/space/space/space/space/space/models/request_model.go+9-4
space/space/space/space/space/space/space/space/space/repositories/account_repository.go+2-4
space/space/space/space/space/space/space/space/space/router/auth_route.go+2
space/space/space/space/space/space/space/space/space/services/authentication_service.go+2-1
space/space/space/space/space/space/space/space/space/services/email_verification_service.go+5-1
space/space/space/space/space/space/space/space/space/services/external_authentication_service.go+6-1
space/space/space/space/space/space/space/space/space/services/forgot_password_service.goAdded+105
space/space/space/space/space/space/space/space/space/services/user_profile_service.go+20-5
space/space/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/space/space/services/email_verification_service.go+60-11
space/space/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/space/space/services/authentication_service.go+2
space/space/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/space/space/services/user_profile_service.go+8-3
space/space/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/space/space/services/external_authentication_service.go+1-1
space/space/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/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/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/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/space/space/controller/user/user_update_profile_controller.go+2-4