Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func editUser(w http.ResponseWriter, r *http.Request) {
- //Checking cookie
- cookie, err := r.Cookie("session_id")
- fmt.Println(cookie.Path)
- if err != nil {
- w.Write([]byte("=("))
- return
- }
- // Taking JSON of modified user from edit form
- var modUser User
- _ = json.NewDecoder(r.Body).Decode(&modUser)
- // Getting claims from current cookie
- claims := checkAuth(cookie)
- // Finding user from claims in users and changing old data to modified data
- for _, user := range users {
- if user.Nickname == claims["nickname"].(string) {
- u := &user
- if modUser.Nickname != "" {
- u.Nickname = modUser.Nickname
- }
- if modUser.Email != "" {
- u.Email = modUser.Email
- }
- if modUser.Password != "" {
- u.Password = modUser.Password
- }
- if modUser.Region != "" {
- u.Region = modUser.Region
- }
- if modUser.Age != 0 {
- u.Age = modUser.Age
- }
- if modUser.About != "" {
- u.About = modUser.About
- }
- if modUser.ImgUrl != "" {
- u.ImgUrl = modUser.ImgUrl
- }
- json.NewEncoder(w).Encode(*u)
- break
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement