Ejemplo n.º 1
0
func PublicUsernameGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	sess := session.Instance(r)

	var params httprouter.Params
	params = context.Get(r, "params").(httprouter.Params)
	site := params.ByName("site")
	username := params.ByName("username")

	// Display the view
	v := view.New(r)

	v.Vars["isSelf"] = false
	v.Vars["verified_email"] = false

	user_info, err := model.UserByUsername(username, site)
	if err == sql.ErrNoRows {
		v.Vars["verified_private"] = false
		v.Vars["verified_public"] = false
		v.Vars["exists"] = false
	} else if err != nil {
		log.Println(err)
		Error500(w, r)
		return
	} else {

		v.Vars["verified_email"] = isVerifiedEmail(r, int64(user_info.Id))

		v.Vars["exists"] = true

		if sess.Values["id"] != nil {
			if sess.Values["id"] == user_info.Id {
				v.Vars["isSelf"] = true
			}
		}

		if isVerifiedPublic(r, uint64(user_info.Id)) && isVerifiedPrivate(r, uint64(user_info.Id)) {
			v.Vars["verified_public"] = true

			// Get the photo information
			//user_id := strconv.Itoa(int(sess.Values["id"].(uint32)))
			user_id_string := strconv.Itoa(int(user_info.Id))
			imagesDB, err := model.PhotosByUserId(uint64(user_info.Id))

			if err != nil {
				log.Println(err)
				return
			}
			images := []Image{}
			for _, val := range imagesDB {
				img := Image{}
				img.Name = val.Path
				/*if val.Status_id == 1 {
					img.Path = "image/" + user_id_string + "/" + val.Path + ".jpg"
				} else {
					img.Path = photoPath + user_id_string + "/" + val.Path + ".jpg"
				}*/

				img.Path = "image/" + user_id_string + "/" + val.Path + ".jpg"

				img.Status_id = int(val.Status_id)
				img.Date = val.Updated_at.Format("Jan _2, 2006")

				// Only allows verified images right now
				if val.Status_id == 1 && val.Initial == 0 {
					images = append(images, img)
				}
			}
			v.Vars["site"] = user_info.Site
			v.Vars["profile"] = strings.Replace(user_info.Profile, ":name", user_info.Username, -1)

			v.Vars["images"] = images

		} else if isVerifiedPrivate(r, uint64(user_info.Id)) {
			v.Vars["verified_private"] = true
		} else {
			v.Vars["verified_private"] = false
		}
	}

	v.Name = "public_username"
	v.Vars["username"] = username
	//v.Vars["site"] = user_info.Site
	//v.Vars["profile"] = user_info.Profile
	v.Vars["home"] = user_info.Home
	v.Render(w)
}
Ejemplo n.º 2
0
func APIVerifyUserGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	//sess := session.Instance(r)

	user_id := uint64(0)
	other_user_id := uint64(0)

	userkey := r.URL.Query().Get("userkey")
	token := r.URL.Query().Get("token")

	auth_info, err := model.ApiAuthenticationByKeys(userkey, token)
	if err == sql.ErrNoRows {
		Error401(w, r)
		return
	} else if err != nil {
		log.Println(err)
		Error500(w, r)
		return
	}

	// If the user is logged in
	/*if sess.Values["id"] != nil {
		user_id = uint64(sess.Values["id"].(uint32))
	}*/

	user_id = uint64(auth_info.User_id)

	var params httprouter.Params
	params = context.Get(r, "params").(httprouter.Params)
	site := params.ByName("site")
	username := params.ByName("username")

	vn := VerifiedNinja{}

	user_info, err := model.UserByUsername(username, site)
	if err == sql.ErrNoRows {
	} else if err != nil {
		log.Println(err)
	} else {

		other_user_id = uint64(user_info.Id)

		// Get the user photos
		photos, err := model.PhotosByUserId(uint64(user_info.Id))
		if err != nil {
			log.Println(err)
		}

		for _, v := range photos {
			if v.Initial == 1 {
				if v.Status_id == 1 {
					vn.PrivatePhotoVerified = true
				}
			} else {
				if v.Status_id == 1 {
					vn.PublicPhotoVerified = true
				}
			}
		}

		// If a private photo is verified, show the page
		if vn.PrivatePhotoVerified && vn.PublicPhotoVerified {

			// Get the username information
			sites, err := model.UserinfoByUserId(uint64(user_info.Id))
			if err != nil {
				log.Println(err)
			} else {
				for _, s := range sites {
					if strings.ToLower(s.Site) == strings.ToLower(site) {
						vn.RegisteredUsername = true
						vn.VerifiedNinja = true
						break
					}
				}
			}
		}
	}

	//log.Println("API Check - is Ninja?:", username, site, vn.VerifiedNinja)

	err = model.TrackRequestAPI(user_id, r, other_user_id, vn.VerifiedNinja)
	if err != nil {
		log.Println(err)
	}

	js, err := json.Marshal(vn)
	if err != nil {
		log.Println(err)
		Error500(w, r)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(js)
}