diff --git a/handlers/pages/pages.go b/handlers/pages/pages.go index eeb4c48..eedb327 100644 --- a/handlers/pages/pages.go +++ b/handlers/pages/pages.go @@ -93,11 +93,21 @@ func (p *pagesHandler) HandlePrivacyPage(w http.ResponseWriter, r *http.Request) } func (p *pagesHandler) HandleProfilePage(w http.ResponseWriter, r *http.Request) { + tokenPayload := p.getRequestSessionTokenPayload(r) + dbProfile, err := p.profileRepo.GetByConds("username = ?", tokenPayload["username"].(string)) + if err != nil { + if p.isNoReload(r) { + w.Header().Set("HX-Redirect", "/") + } else { + http.Redirect(w, r, config.Env().Hostname, http.StatusTemporaryRedirect) + } + return + } + profile := entities.Profile{ - Email: "pub@mbaraa.com", - Name: "Baraa Al-Masri", - PfpLink: "", - Username: "mbaraa", + Name: dbProfile[0].Name, + PfpLink: dbProfile[0].PfpLink, + Username: dbProfile[0].Username, } if p.isNoReload(r) { diff --git a/services/login/email.go b/services/login/email.go index f5adabd..9a56a63 100644 --- a/services/login/email.go +++ b/services/login/email.go @@ -49,8 +49,9 @@ func (e *EmailLoginService) Login(user entities.LoginRequest) (string, error) { profile[0].AccountId = account[0].Id verificationToken, err := e.jwtUtil.Sign(map[string]string{ - "name": profile[0].Name, - "email": profile[0].Account.Email, + "name": profile[0].Name, + "email": profile[0].Account.Email, + "username": profile[0].Username, }, jwt.VerificationToken, time.Hour/2) if err != nil { return "", err @@ -78,8 +79,9 @@ func (e *EmailLoginService) Signup(user entities.SignupRequest) (string, error) } verificationToken, err := e.jwtUtil.Sign(map[string]string{ - "name": profile.Name, - "email": profile.Account.Email, + "name": profile.Name, + "email": profile.Account.Email, + "username": profile.Username, }, jwt.VerificationToken, time.Hour/2) if err != nil { return "", err @@ -105,6 +107,11 @@ func (e *EmailLoginService) VerifyOtp(token string, otp entities.OtpRequest) (st if !nameExists { return "", errors.New("missing name") } + username, usernameExists := mappedUser["username"].(string) + // TODO: ADD THE FUCKING ERRORS SUKA + if !usernameExists { + return "", errors.New("missing username") + } account, err := e.accountRepo.GetByConds("email = ?", email) if err != nil { @@ -126,8 +133,9 @@ func (e *EmailLoginService) VerifyOtp(token string, otp entities.OtpRequest) (st } sessionToken, err := e.jwtUtil.Sign(map[string]string{ - "email": email, - "name": name, + "email": email, + "name": name, + "username": username, }, jwt.SessionToken, time.Hour*24*30) if err != nil { return "", err diff --git a/services/login/google.go b/services/login/google.go index 71bc5fe..713dfab 100644 --- a/services/login/google.go +++ b/services/login/google.go @@ -80,8 +80,9 @@ func (g *GoogleLoginService) Login(state, code string) (string, error) { profile[0].AccountId = account[0].Id verificationToken, err := g.jwtUtil.Sign(map[string]string{ - "name": profile[0].Name, - "email": profile[0].Account.Email, + "name": profile[0].Name, + "email": profile[0].Account.Email, + "username": profile[0].Username, }, jwt.SessionToken, time.Hour*24*30) if err != nil { return "", err @@ -97,6 +98,7 @@ func (g *GoogleLoginService) Signup(googleUser oauthUserInfo) (string, error) { IsOAuth: true, }, Name: googleUser.FullName, + PfpLink: googleUser.PfpLink, Username: googleUser.Email, } // creating a new account will create the account underneath it. @@ -106,8 +108,9 @@ func (g *GoogleLoginService) Signup(googleUser oauthUserInfo) (string, error) { } verificationToken, err := g.jwtUtil.Sign(map[string]string{ - "name": profile.Name, - "email": profile.Account.Email, + "name": profile.Name, + "email": profile.Account.Email, + "username": profile.Username, }, jwt.SessionToken, time.Hour*24*30) if err != nil { return "", err diff --git a/views/pages/profile.templ b/views/pages/profile.templ index 377b8ea..57e43d8 100644 --- a/views/pages/profile.templ +++ b/views/pages/profile.templ @@ -39,7 +39,7 @@ templ profile(prfl entities.Profile) { alt="Profile picture" />