func InitialPhotoGET(w http.ResponseWriter, r *http.Request) { // Get session sess := session.Instance(r) user_id := uint64(sess.Values["id"].(uint32)) demo, err := model.DemographicByUserId(user_id) if err != sql.ErrNoRows { //log.Println(err) } // Force the user to enter in demographic information if len(demo.Gender) < 1 { UserInformationGET(w, r) return } // If the user has no photos, show this page // If the user has only unverified photos, show the waiting screen // Get the user photos photos, err := model.PhotosByUserId(uint64(sess.Values["id"].(uint32))) if err != nil { log.Println(err) } verified_private := false unverified_private := false //rejected_private := false any_private := false for _, v := range photos { if v.Initial == 1 { if v.Status_id == 1 { verified_private = true } else if v.Status_id == 2 { unverified_private = true } else if v.Status_id == 3 { //rejected_private = true } any_private = true } } // Redirect to profile to handle caess where all private photos are rejected if len(photos) < 1 || verified_private || !any_private { // Get the user verification code token_info, err := model.UserTokenByUserId(user_id) if err == sql.ErrNoRows { token_info.Token = random.Generate(6) token_info.User_id = uint32(user_id) err = model.UserTokenCreate(user_id, token_info.Token) } else if err != nil { log.Println(err) Error500(w, r) return } // Display the view v := view.New(r) v.Name = "user_step1" v.Vars["user_token"] = token_info.Token v.Vars["first_name"] = sess.Values["first_name"] v.Render(w) } else if unverified_private { http.Redirect(w, r, "/profile", http.StatusFound) } else { //Error404(w, r) http.Redirect(w, r, "/profile", http.StatusFound) } }
// Displays the default home page func AdminAllGET(w http.ResponseWriter, r *http.Request) { dirs, err := filepath.Glob(photoPath + "*") if err != nil { log.Println(err) } users := []User{} ds := string(os.PathSeparator) for _, v := range dirs { u := User{} idRaw := v[strings.LastIndex(v, ds)+1:] u.Id, err = strconv.Atoi(idRaw) if err != nil { log.Println(err) continue } info, err := model.UserNameById(u.Id) if err == sql.ErrNoRows { log.Println("User is not found in database:", u.Id) continue } else if err != nil { log.Println(err) continue } u.FirstName = info.First_name u.LastName = info.Last_name /*files, err := filepath.Glob(photoPath + idRaw + "/*") if err != nil { log.Println(err) continue } for _, v := range files { i := Image{} i.Name = v[strings.LastIndex(v, ds)+1:] iid, _ := strconv.Atoi(strings.Replace(i.Name, `.jpg`, ``, -1)) i.Id = iid i.Path = strings.Replace(v, `\`, `/`, -1) u.Images = append(u.Images, i) }*/ // Get the photo information user_id := strconv.Itoa(u.Id) imagesDB, err := model.PhotosByUserId(uint64(u.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 + "/" + val.Path + ".jpg" } else { img.Path = photoPath + user_id + "/" + val.Path + ".jpg" }*/ img.Path = "image/" + user_id + "/" + val.Path + ".jpg" img.Status_id = int(val.Status_id) img.Date = val.Updated_at.Format("Jan _2, 2006") img.Initial = int(val.Initial) u.Images = append(u.Images, img) } //uid := sess.Values["id"].(uint32) // Get the user verification code token_info, err := model.UserTokenByUserId(uint64(u.Id)) if err == sql.ErrNoRows { log.Println(err) token_info.Token = "TOKEN IS MISSING" } else if err != nil { log.Println(err) token_info.Token = "TOKEN IS MISSING" } u.Token = token_info.Token users = append(users, u) } // Display the view v := view.New(r) v.Name = "admin_all" v.Vars["users"] = users v.Render(w) }
// Displays the default home page func AdminGET(w http.ResponseWriter, r *http.Request) { dirs, err := filepath.Glob(photoPath + "*") if err != nil { log.Println(err) } users := []User{} ds := string(os.PathSeparator) for _, v := range dirs { u := User{} idRaw := v[strings.LastIndex(v, ds)+1:] u.Id, err = strconv.Atoi(idRaw) if err != nil { log.Println(err) continue } info, err := model.UserNameById(u.Id) if err == sql.ErrNoRows { log.Println("User is not found in database:", u.Id) continue } else if err != nil { log.Println(err) continue } u.FirstName = info.First_name u.LastName = info.Last_name privateVerifiedCount := 0 publicVerifiedCount := 0 // Get the photo information user_id := strconv.Itoa(u.Id) imagesDB, err := model.PhotosByUserId(uint64(u.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 { u.VerifiedCount += 1 if val.Initial == 1 { privateVerifiedCount += 1 } else if val.Initial == 0 { publicVerifiedCount += 1 } } else if val.Status_id == 2 { u.UnverifiedCount += 1 } img.Path = "image/" + user_id + "/" + val.Path + ".jpg" img.Status_id = int(val.Status_id) img.Date = val.Updated_at.Format("Jan _2, 2006") img.Initial = int(val.Initial) u.Images = append(u.Images, img) } // Get the user verification code token_info, err := model.UserTokenByUserId(uint64(u.Id)) if err == sql.ErrNoRows { log.Println(err) token_info.Token = "TOKEN IS MISSING" } else if err != nil { log.Println(err) token_info.Token = "TOKEN IS MISSING" } u.Token = token_info.Token // Get the username information sites, err := model.UserinfoByUserId(uint64(u.Id)) if err != nil { log.Println(err) return } u.SiteCount = len(sites) u.Email = isVerifiedEmail(r, int64(u.Id)) if u.SiteCount > 0 && privateVerifiedCount > 0 && publicVerifiedCount > 0 && u.Email { u.Ninja = true } users = append(users, u) } // Display the view v := view.New(r) v.Name = "admin" v.Vars["users"] = users v.Render(w) }
// Displays the default home page func AdminUserGET(w http.ResponseWriter, r *http.Request) { var params = context.Get(r, "params").(httprouter.Params) userid := params.ByName("userid") user_id, _ := strconv.Atoi(userid) users := []User{} for _, v := range []int{user_id} { u := User{} u.Id = v info, err := model.UserNameById(u.Id) if err == sql.ErrNoRows { log.Println("User is not found in database:", u.Id) continue } else if err != nil { log.Println(err) continue } u.FirstName = info.First_name u.LastName = info.Last_name // Get the photo information user_id := strconv.Itoa(u.Id) imagesDB, err := model.PhotosByUserId(uint64(u.Id)) if err != nil { log.Println(err) return } //images := []Image{} for _, val := range imagesDB { img := Image{} img.Name = val.Path img.Path = "image/" + user_id + "/" + val.Path + ".jpg" img.Status_id = int(val.Status_id) img.Date = val.Updated_at.Format("Jan _2, 2006") img.Initial = int(val.Initial) u.Images = append(u.Images, img) } // Get the user verification code token_info, err := model.UserTokenByUserId(uint64(u.Id)) if err == sql.ErrNoRows { log.Println(err) token_info.Token = "TOKEN IS MISSING" } else if err != nil { log.Println(err) token_info.Token = "TOKEN IS MISSING" } u.Token = token_info.Token users = append(users, u) } // Display the view v := view.New(r) v.Name = "admin_all" v.Vars["users"] = users v.Render(w) }