func signinWithGoogle(reqBody userReqPostBody) (*model.UserToken, *ae.Error) { person, token, err := model.GetGooglUserDetails(reqBody.GoogleKey) if err != nil { return nil, ae.DB("", err) } user := model.User{Email: person.Emails[0].Value} if err = user.GetUserByEmail(); err != nil { if err == sql.ErrNoRows { user.Verified = true user.ProfilePicURL = person.Image.Url if err1 := user.Save(); err1 != nil { return nil, ae.DB("", err1) } } else { return nil, ae.DB("", err) } } gToken := model.GoogleToken{UserID: user.UserID} gToken.Token = *token if err := gToken.Replace(); err != nil { return nil, ae.DB("", err) } userToken := model.UserToken{} userToken.UserID = user.UserID err = userToken.Add() if err != nil { return nil, ae.DB("", err) } return &userToken, nil }
func UpdateUser(w http.ResponseWriter, r *http.Request) { userID := context.Get(r, "user_id").(uint64) reqBody := userReqPutBody{} appErr := decode(r, &reqBody) if appErr != nil { reply.Err(w, appErr) return } user := model.User{UserID: userID} if err := user.Get(); err != nil { if err == sql.ErrNoRows { reply.Err(w, ae.ResourceNotFound("")) return } reply.Err(w, ae.DB("", err)) return } user.FirstName = reqBody.FirstName user.LastName = reqBody.LastName user.ProfilePicURL = reqBody.ProfilePicURL user.MetricSystem = reqBody.MetricSystem if err := user.Save(); err != nil { reply.Err(w, ae.DB("", err)) return } if err := user.Get(); err != nil { reply.Err(w, ae.DB("", err)) return } reply.OK(w, user) return }