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())
|
||||
w.WriteHeader(http.StatusOK)
|
||||
expirationTime := time.Now().Add(5 * time.Hour)
|
||||
newClaims := &Claims{
|
||||
newClaims := &Claims{
|
||||
Username: claims["username"].(string),
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
ExpiresAt: expirationTime.Unix(),
|
||||
|
|
|
@ -2,6 +2,7 @@ package users
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/jwtauth"
|
||||
|
@ -15,10 +16,10 @@ var (
|
|||
)
|
||||
|
||||
type User struct {
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Country string `json:"country"`
|
||||
Bio string `json:"bio"`
|
||||
Username string `json:"username",db:"username"`
|
||||
Email string `json:"email",db:"email"`
|
||||
Country string `json:"country",db:"country"`
|
||||
Bio string `json:"bio",db:"bio"`
|
||||
}
|
||||
|
||||
func Init() {
|
||||
|
@ -64,6 +65,22 @@ func updateUser(w http.ResponseWriter, r *http.Request) {
|
|||
w.WriteHeader(http.StatusUnauthorized)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue