Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. func editUser(w http.ResponseWriter, r *http.Request) {
  2. //Checking cookie
  3. cookie, err := r.Cookie("session_id")
  4. fmt.Println(cookie.Path)
  5. if err != nil {
  6. w.Write([]byte("=("))
  7. return
  8. }
  9. // Taking JSON of modified user from edit form
  10. var modUser User
  11. _ = json.NewDecoder(r.Body).Decode(&modUser)
  12. // Getting claims from current cookie
  13. claims := checkAuth(cookie)
  14.  
  15.  
  16. // Finding user from claims in users and changing old data to modified data
  17. for _, user := range users {
  18. if user.Nickname == claims["nickname"].(string) {
  19. u := &user
  20. if modUser.Nickname != "" {
  21. u.Nickname = modUser.Nickname
  22. }
  23. if modUser.Email != "" {
  24. u.Email = modUser.Email
  25. }
  26. if modUser.Password != "" {
  27. u.Password = modUser.Password
  28. }
  29. if modUser.Region != "" {
  30. u.Region = modUser.Region
  31. }
  32. if modUser.Age != 0 {
  33. u.Age = modUser.Age
  34. }
  35. if modUser.About != "" {
  36. u.About = modUser.About
  37. }
  38. if modUser.ImgUrl != "" {
  39. u.ImgUrl = modUser.ImgUrl
  40. }
  41. json.NewEncoder(w).Encode(*u)
  42. break
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement