Add proper updating of profiles
This commit is contained in:
parent
a9b09ce4da
commit
b68dba10cb
2 changed files with 22 additions and 5 deletions
|
@ -163,7 +163,7 @@ func refresh(w http.ResponseWriter, r *http.Request) {
|
||||||
_, claims, _ := jwtauth.FromContext(r.Context())
|
_, claims, _ := jwtauth.FromContext(r.Context())
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
expirationTime := time.Now().Add(5 * time.Hour)
|
expirationTime := time.Now().Add(5 * time.Hour)
|
||||||
newClaims := &Claims{
|
newClaims := &Claims{
|
||||||
Username: claims["username"].(string),
|
Username: claims["username"].(string),
|
||||||
StandardClaims: jwt.StandardClaims{
|
StandardClaims: jwt.StandardClaims{
|
||||||
ExpiresAt: expirationTime.Unix(),
|
ExpiresAt: expirationTime.Unix(),
|
||||||
|
|
|
@ -2,6 +2,7 @@ package users
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-chi/chi"
|
"github.com/go-chi/chi"
|
||||||
"github.com/go-chi/jwtauth"
|
"github.com/go-chi/jwtauth"
|
||||||
|
@ -15,10 +16,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username",db:"username"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email",db:"email"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country",db:"country"`
|
||||||
Bio string `json:"bio"`
|
Bio string `json:"bio",db:"bio"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
@ -64,6 +65,22 @@ func updateUser(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
user := &User{}
|
||||||
|
err := json.NewDecoder(r.Body).Decode(user)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.Username = username
|
||||||
|
updateProfileStatement := `
|
||||||
|
UPDATE user_profiles
|
||||||
|
SET username = $1,
|
||||||
|
email = $2,
|
||||||
|
country = $3,
|
||||||
|
bio = $4
|
||||||
|
WHERE username = $5`
|
||||||
|
_, err = DB.Exec(updateProfileStatement, user.Username, user.Email, user.Country, user.Bio, username)
|
||||||
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue