• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang utils.GetCurrentUser函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/stevenleeg/gobb/utils.GetCurrentUser函数的典型用法代码示例。如果您正苦于以下问题:Golang GetCurrentUser函数的具体用法?Golang GetCurrentUser怎么用?Golang GetCurrentUser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetCurrentUser函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewThread

func NewThread(w http.ResponseWriter, r *http.Request) {
	db := models.GetDbSession()
	board_id_str := mux.Vars(r)["id"]
	board_id, _ := strconv.Atoi(board_id_str)
	err, board := models.GetBoard(board_id)

	if err != nil {
		http.NotFound(w, r)
		return
	}

	current_user := utils.GetCurrentUser(r)
	if current_user == nil {
		http.NotFound(w, r)
		return
	}

	if r.Method == "POST" {
		title := r.FormValue("title")
		content := r.FormValue("content")

		post := models.NewPost(current_user, board, title, content)
		post.LatestReply = time.Now()
		db.Insert(post)

		http.Redirect(w, r, fmt.Sprintf("/board/%d/%d", board.Id, post.Id), http.StatusFound)
		return
	}

	utils.RenderTemplate(w, r, "new_thread.html", map[string]interface{}{
		"board": board,
	})
}
开发者ID:ChimeraCoder,项目名称:gobb,代码行数:33,代码来源:new_thread.go


示例2: ActionLockThread

func ActionLockThread(w http.ResponseWriter, r *http.Request) {
	user := utils.GetCurrentUser(r)
	if !user.CanModerate() {
		http.NotFound(w, r)
		return
	}

	thread_id_str := r.FormValue("post_id")
	thread_id, err := strconv.Atoi(thread_id_str)

	if err != nil {
		http.NotFound(w, r)
		return
	}

	db := models.GetDbSession()
	obj, err := db.Get(&models.Post{}, thread_id)
	thread := obj.(*models.Post)

	if thread == nil || err != nil {
		http.NotFound(w, r)
		return
	}

	thread.Locked = !(thread.Locked)
	db.Update(thread)

	http.Redirect(w, r, fmt.Sprintf("/board/%d/%d", thread.BoardId, thread.Id), http.StatusFound)
}
开发者ID:nota-ja,项目名称:gobb,代码行数:29,代码来源:actions.go


示例3: AdminUsers

func AdminUsers(w http.ResponseWriter, r *http.Request) {
	current_user := utils.GetCurrentUser(r)
	if current_user == nil || !current_user.IsAdmin() {
		http.NotFound(w, r)
		return
	}

	err := ""
	success := false

	starts_with := r.FormValue("starts_with")
	last_seen := r.FormValue("last_seen")

	db := models.GetDbSession()
	var users []*models.User
	if len(starts_with) == 1 {
		db.Select(&users, "SELECT * FROM users WHERE username LIKE $1", starts_with+"%")
	} else if last_seen == "1" {
		db.Select(&users, "SELECT * FROM users ORDER BY last_seen DESC")
	} else {
		db.Select(&users, "SELECT * FROM users ORDER BY id DESC")
	}

	utils.RenderTemplate(w, r, "admin_users.html", map[string]interface{}{
		"error":   err,
		"success": success,
		"users":   users,
	}, nil)
}
开发者ID:nota-ja,项目名称:gobb,代码行数:29,代码来源:admin_users.go


示例4: Index

func Index(w http.ResponseWriter, request *http.Request) {
	current_user := utils.GetCurrentUser(request)
	boards, err := models.GetBoardsUnread(current_user)

	if err != nil {
		fmt.Printf("[error] Could not get boards (%s)\n", err.Error())
	}

	user_count, _ := models.GetUserCount()
	latest_user, _ := models.GetLatestUser()
	total_posts, _ := models.GetPostCount()

	utils.RenderTemplate(w, request, "index.html", map[string]interface{}{
		"boards":       boards,
		"user_count":   user_count,
		"online_users": models.GetOnlineUsers(),
		"latest_user":  latest_user,
		"total_posts":  total_posts,
	}, map[string]interface{}{
		"IsUnread": func(join *models.JoinBoardView) bool {
			latest_post := join.Board.GetLatestPost()

			if current_user != nil && !current_user.LastUnreadAll.Time.Before(latest_post.Op.LatestReply) {
				return false
			}

			return !join.ViewedOn.Valid || join.ViewedOn.Time.Before(latest_post.Op.LatestReply)
		},
	})
}
开发者ID:nota-ja,项目名称:gobb,代码行数:30,代码来源:index.go


示例5: ActionMarkAllRead

func ActionMarkAllRead(w http.ResponseWriter, r *http.Request) {
	user := utils.GetCurrentUser(r)
	if user == nil {
		http.NotFound(w, r)
		return
	}

	db := models.GetDbSession()
	user.LastUnreadAll = pq.NullTime{Time: time.Now(), Valid: true}
	db.Update(user)

	http.Redirect(w, r, "/", http.StatusFound)
}
开发者ID:nota-ja,项目名称:gobb,代码行数:13,代码来源:actions.go


示例6: Thread

func Thread(w http.ResponseWriter, r *http.Request) {
	page_id_str := r.FormValue("page")
	page_id, err := strconv.Atoi(page_id_str)
	if err != nil {
		page_id = 0
	}

	board_id_str := mux.Vars(r)["board_id"]
	board_id, _ := strconv.Atoi(board_id_str)
	err, board := models.GetBoard(board_id)

	post_id_str := mux.Vars(r)["post_id"]
	post_id, _ := strconv.Atoi(post_id_str)
	err, op, posts := models.GetThread(post_id, page_id)

	if r.Method == "POST" {
		db := models.GetDbSession()
		title := r.FormValue("title")
		content := r.FormValue("content")

		current_user := utils.GetCurrentUser(r)
		if current_user == nil {
			http.NotFound(w, r)
			return
		}

		post := models.NewPost(current_user, board, title, content)
		post.ParentId = sql.NullInt64{int64(post_id), true}
		op.LatestReply = time.Now()
		db.Insert(post)
		db.Update(op)

		err, op, posts = models.GetThread(post_id, page_id)
	}

	if err != nil {
		http.NotFound(w, r)
		return
	}

	num_pages := op.GetPagesInThread()

	utils.RenderTemplate(w, r, "thread.html", map[string]interface{}{
		"board":     board,
		"op":        op,
		"posts":     posts,
		"prev_page": (page_id != 0),
		"next_page": (page_id < num_pages),
		"page_id":   page_id,
	})
}
开发者ID:ChimeraCoder,项目名称:gobb,代码行数:51,代码来源:thread.go


示例7: ActionMoveThread

func ActionMoveThread(w http.ResponseWriter, r *http.Request) {
	current_user := utils.GetCurrentUser(r)
	if current_user == nil || !current_user.CanModerate() {
		http.NotFound(w, r)
		return
	}

	thread_id_str := r.FormValue("post_id")
	thread_id, err := strconv.Atoi(thread_id_str)
	board_id_str := r.FormValue("to")
	board_id, err := strconv.Atoi(board_id_str)

	op, err := models.GetPost(thread_id)
	//	boards, _ := models.GetBoardsfor(current_user.GroupId)
	boards, _ := models.GetBoards()

	if op == nil || err != nil {
		http.NotFound(w, r)
		return
	}

	if board_id_str != "" {
		db := models.GetDbSession()
		new_board, _ := models.GetBoard(board_id)
		if new_board == nil {
			http.NotFound(w, r)
			return
		}

		_, err := db.Exec("UPDATE posts SET board_id=$1 WHERE parent_id=$2", new_board.Id, op.Id)
		op.BoardId = new_board.Id
		db.Update(op)
		if err != nil {
			http.NotFound(w, r)
			fmt.Printf("Error moving post: %s\n", err.Error())
			return
		}
		http.Redirect(w, r, fmt.Sprintf("/board/%d/%d", op.BoardId, op.Id), http.StatusFound)
	}

	board, err := models.GetBoard(int(op.BoardId))

	utils.RenderTemplate(w, r, "action_move_thread.html", map[string]interface{}{
		"board":  board,
		"thread": op,
		"boards": boards,
	}, nil)
}
开发者ID:s2607,项目名称:gobb,代码行数:48,代码来源:actions.go


示例8: Board

func Board(w http.ResponseWriter, r *http.Request) {
	db := models.GetDbSession()

	page_id_str := r.FormValue("page")
	page_id, err := strconv.Atoi(page_id_str)
	if err != nil {
		page_id = 0
	}

	board_id_str := mux.Vars(r)["id"]
	board_id, _ := strconv.Atoi(board_id_str)
	obj, err := db.Get(&models.Board{}, board_id)
	if err != nil || obj == nil {
		http.NotFound(w, r)
		return
	}
	board := obj.(*models.Board)

	if err != nil {
		http.NotFound(w, r)
		return
	}

	current_user := utils.GetCurrentUser(r)
	threads, err := board.GetThreads(page_id, current_user)
	if err != nil {
		fmt.Printf("[error] Could not get posts (%s)\n", err.Error())
	}

	num_pages := board.GetPagesInBoard()

	utils.RenderTemplate(w, r, "board.html", map[string]interface{}{
		"board":     board,
		"threads":   threads,
		"page_id":   page_id,
		"prev_page": (page_id != 0),
		"next_page": (page_id < num_pages),
	}, map[string]interface{}{
		"IsUnread": func(join *models.JoinThreadView) bool {
			if current_user != nil && !current_user.LastUnreadAll.Time.Before(join.LatestReply) {
				return false
			}
			return !join.ViewedOn.Valid || join.ViewedOn.Time.Before(join.LatestReply)
		},
	})
}
开发者ID:nota-ja,项目名称:gobb,代码行数:46,代码来源:board.go


示例9: Login

func Login(w http.ResponseWriter, r *http.Request) {
	if utils.GetCurrentUser(r) != nil {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	if r.Method == "POST" {
		username := r.FormValue("username")
		password := r.FormValue("password")

		var error string
		err, _ := models.AuthenticateUser(username, password)
		if err != nil {
			error = "Invalid username or password"
		}

		if error != "" {
			utils.RenderTemplate(w, r, "login.html", map[string]interface{}{
				"error": error,
			})
			return
		}

		session, _ := utils.Store.Get(r, "sirsid")
		session.Values["username"] = username
		session.Values["password"] = password
		fmt.Println("[notice] Auth success!")

		err = session.Save(r, w)
		if err != nil {
			fmt.Printf("[error] Could not save session (%s)\n", err.Error())
		}

		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	utils.RenderTemplate(w, r, "login.html", nil)
}
开发者ID:ChimeraCoder,项目名称:gobb,代码行数:39,代码来源:login.go


示例10: ActionDeleteThread

func ActionDeleteThread(w http.ResponseWriter, r *http.Request) {
	user := utils.GetCurrentUser(r)
	thread_id_str := r.FormValue("post_id")
	thread_id, err := strconv.Atoi(thread_id_str)

	if err != nil {
		http.NotFound(w, r)
		return
	}

	db := models.GetDbSession()
	obj, err := db.Get(&models.Post{}, thread_id)
	thread := obj.(*models.Post)

	if thread == nil || err != nil {
		http.NotFound(w, r)
		return
	}

	if (thread.AuthorId != user.Id) && !user.CanModerate() {
		http.NotFound(w, r)
		return
	}

	redirect_board := true
	if thread.ParentId.Valid {
		redirect_board = false
	}

	thread.DeleteAllChildren()
	db.Delete(thread)

	if redirect_board {
		http.Redirect(w, r, fmt.Sprintf("/board/%d", thread.BoardId), http.StatusFound)
	} else {
		http.Redirect(w, r, fmt.Sprintf("/board/%d/%d", thread.BoardId, thread.ParentId.Int64), http.StatusFound)
	}

}
开发者ID:nota-ja,项目名称:gobb,代码行数:39,代码来源:actions.go


示例11: Register

func Register(w http.ResponseWriter, r *http.Request) {
	if utils.GetCurrentUser(r) != nil {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	if r.Method == "POST" {
		username := r.FormValue("username")
		password := r.FormValue("password")
		confirm := r.FormValue("password2")

		var error string
		if password != confirm {
			error = "Passwords don't match"
		}

		if error != "" {
			utils.RenderTemplate(w, r, "register.html", map[string]interface{}{
				"error": error,
			})
			return
		}

		// We're good, let's make it
		db_map := models.GetDbSession()
		user := models.NewUser(username, password)
		err := db_map.Insert(user)

		if err != nil {
			fmt.Printf("[error] Could not insert user (%s)\n", err.Error())
		} else {
			http.Redirect(w, r, "/login", http.StatusFound)
			return
		}
	}

	utils.RenderTemplate(w, r, "register.html", nil)
}
开发者ID:ChimeraCoder,项目名称:gobb,代码行数:38,代码来源:register.go


示例12: UserSettings

func UserSettings(w http.ResponseWriter, r *http.Request) {
	user_id_str := mux.Vars(r)["id"]
	user_id, _ := strconv.Atoi(user_id_str)

	current_user := utils.GetCurrentUser(r)

	if int64(user_id) != current_user.Id {
		http.NotFound(w, r)
		return
	}

	success := false
	if r.Method == "POST" {
		db := models.GetDbSession()
		current_user.Avatar = r.FormValue("avatar_url")
		db.Update(current_user)
		success = true
	}

	utils.RenderTemplate(w, r, "user_settings.html", map[string]interface{}{
		"success": success,
	})
}
开发者ID:ChimeraCoder,项目名称:gobb,代码行数:23,代码来源:user_settings.go


示例13: Admin

func Admin(w http.ResponseWriter, r *http.Request) {
	current_user := utils.GetCurrentUser(r)
	if current_user == nil || !current_user.IsAdmin() {
		http.NotFound(w, r)
		return
	}

	var err error
	success := false
	stylesheet, _ := models.GetStringSetting("theme_stylesheet")
	favicon, _ := models.GetStringSetting("favicon_url")
	current_template, _ := models.GetStringSetting("template")

	if r.Method == "POST" {
		stylesheet = r.FormValue("theme_stylesheet")
		favicon = r.FormValue("favicon_url")
		current_template = r.FormValue("template")
		models.SetStringSetting("theme_stylesheet", stylesheet)
		models.SetStringSetting("favicon_url", favicon)
		models.SetStringSetting("template", current_template)
		success = true
	}

	utils.RenderTemplate(w, r, "admin.html", map[string]interface{}{
		"error":            err,
		"success":          success,
		"theme_stylesheet": stylesheet,
		"favicon_url":      favicon,
		"current_template": current_template,
		"templates":        utils.ListTemplates(),
	}, map[string]interface{}{
		"IsCurrentTemplate": func(name string) bool {
			return name == current_template
		},
	})
}
开发者ID:nota-ja,项目名称:gobb,代码行数:36,代码来源:admin.go


示例14: Register

func Register(w http.ResponseWriter, r *http.Request) {
	if utils.GetCurrentUser(r) != nil {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	if r.Method == "POST" {
		username := r.FormValue("username")
		password := r.FormValue("password")
		confirm := r.FormValue("password2")

		var error string
		if password != confirm {
			error = "Passwords don't match"
		}

		// See if a user with this name already exists
		db := models.GetDbSession()
		count, err := db.SelectInt("SELECT COUNT(*) FROM users WHERE username=$1", username)
		if count > 0 || err != nil {
			error = "This username is already taken."
		}

        if len(username) < 3 {
            error = "Username must be greater than 3 characters."
        }

		if error != "" {
			utils.RenderTemplate(w, r, "register.html", map[string]interface{}{
				"error": error,
			}, nil)
			return
		}

		// We're good, let's make it
		user := models.NewUser(username, password)
		err = db.Insert(user)

		if err != nil {
			fmt.Printf("[error] Could not insert user (%s)\n", err.Error())
			return;
		}

		// Adminify the first user
		id, err := db.SelectInt("SELECT lastval()")
		if err == nil && id == 1 {
			user.GroupId = 2
			count, err = db.Update(user)

			if err != nil {
				fmt.Printf("[error] Could not adminify user (%s)\n", err.Error())
				return;
			}
		}

		http.Redirect(w, r, "/login", http.StatusFound)
		return
	}

	utils.RenderTemplate(w, r, "register.html", nil, nil)
}
开发者ID:nmbook,项目名称:gobb,代码行数:61,代码来源:register.go


示例15: UserSettings

func UserSettings(w http.ResponseWriter, r *http.Request) {
	enable_signatures, _ := config.Config.GetBool("gobb", "enable_signatures")

	user_id_str := mux.Vars(r)["id"]
	user_id, _ := strconv.Atoi(user_id_str)

	current_user := utils.GetCurrentUser(r)

	if current_user == nil || int64(user_id) != current_user.Id {
		http.NotFound(w, r)
		return
	}

	success := false
	var form_error string
	if r.Method == "POST" {
		db := models.GetDbSession()
		current_user.Avatar = r.FormValue("avatar_url")
		current_user.UserTitle = r.FormValue("user_title")
		current_user.StylesheetUrl = sql.NullString{
			Valid:  true,
			String: r.FormValue("stylesheet_url"),
		}
		if r.FormValue("signature") == "" {
			current_user.Signature = sql.NullString{
				Valid:  false,
				String: r.FormValue("signature"),
			}
		} else {
			current_user.Signature = sql.NullString{
				Valid:  true,
				String: r.FormValue("signature"),
			}
		}

		// Change hiding settings
		current_user.HideOnline = false
		if r.FormValue("hide_online") == "1" {
			current_user.HideOnline = true
		}

		// Update password?
		old_pass := r.FormValue("password_old")
		new_pass := r.FormValue("password_new")
		new_pass2 := r.FormValue("password_new2")
		if old_pass != "" {
			err, user := models.AuthenticateUser(current_user.Username, old_pass)
			if user == nil || err != nil {
				form_error = "Invalid password"
			} else if len(new_pass) < 5 {
				form_error = "Password must be greater than 4 characters"
			} else if new_pass != new_pass2 {
				form_error = "Passwords didn't match"
			} else {
				current_user.SetPassword(new_pass)
				session, _ := utils.GetCookieStore(r).Get(r, "sirsid")
				session.Values["password"] = new_pass
				session.Save(r, w)
			}
		}

		if form_error == "" {
			db.Update(current_user)
			success = true
		}
	}

	stylesheet := ""
	if current_user.StylesheetUrl.Valid {
		stylesheet = current_user.StylesheetUrl.String
	}
	signature := ""
	if current_user.Signature.Valid {
		signature = current_user.Signature.String
	}

	utils.RenderTemplate(w, r, "user_settings.html", map[string]interface{}{
		"error":             form_error,
		"success":           success,
		"user_stylesheet":   stylesheet,
		"user_signature":    signature,
		"enable_signatures": enable_signatures,
	}, nil)
}
开发者ID:nota-ja,项目名称:gobb,代码行数:84,代码来源:user_settings.go


示例16: PostEditor

func PostEditor(w http.ResponseWriter, r *http.Request) {
	db := models.GetDbSession()

	var err error
	var board *models.Board
	var post *models.Post

	// Attempt to get a board
	board_id_str := mux.Vars(r)["board_id"]
	if board_id_str != "" {
		board_id, _ := strconv.Atoi(board_id_str)
		board, err = models.GetBoard(board_id)
	}

	// Otherwise, a post
	post_id_str := r.FormValue("post_id")
	if post_id_str != "" {
		post_id, _ := strconv.Atoi(post_id_str)
		post_tmp, _ := db.Get(&models.Post{}, post_id)
		post = post_tmp.(*models.Post)
	}

	if err != nil {
		fmt.Println("something went wrong")
		http.NotFound(w, r)
		return
	}

	current_user := utils.GetCurrentUser(r)
	if current_user == nil {
		http.NotFound(w, r)
		return
	}
	if post != nil && (post.AuthorId != current_user.Id && !current_user.CanModerate()) {
		http.NotFound(w, r)
		return
	}

	if r.Method == "POST" {
		title := r.FormValue("title")
		content := r.FormValue("content")

		if post == nil {
			post = models.NewPost(current_user, board, title, content)
			post.LatestReply = time.Now()

			err = post.Validate()
			if err != nil {
				renderPostEditor(w, r, board, post, err)
				return
			}

			err = db.Insert(post)
		} else {
			post.Title = title
			post.Content = content
			post.LastEdit = time.Now()
			post.LatestReply = time.Now()

			err = post.Validate()
			if err != nil {
				renderPostEditor(w, r, board, post, err)
				return
			}

			_, err = db.Update(post)
		}

		if err != nil {
			fmt.Printf("[error] Could not save post (%s)", err.Error())
			return
		}

		http.Redirect(w, r, post.GetLink(), http.StatusFound)
		return
	}

	renderPostEditor(w, r, board, post, err)
}
开发者ID:nota-ja,项目名称:gobb,代码行数:79,代码来源:post_editor.go


示例17: AdminUser

func AdminUser(w http.ResponseWriter, r *http.Request) {
	current_user := utils.GetCurrentUser(r)
	if current_user == nil || !current_user.IsAdmin() {
		http.NotFound(w, r)
		return
	}

	id_str := mux.Vars(r)["id"]
	id, _ := strconv.Atoi(id_str)

	user, err := models.GetUser(id)

	if err != nil || user == nil {
		http.NotFound(w, r)
		return
	}

	var form_error string
	success := false
	if r.Method == "POST" {
		db := models.GetDbSession()
		user.Username = r.FormValue("username")
		user.Avatar = r.FormValue("avatar_url")
		user.UserTitle = r.FormValue("user_title")
		user.StylesheetUrl = sql.NullString{
			Valid:  true,
			String: r.FormValue("stylesheet_url"),
		}
		if r.FormValue("signature") == "" {
			user.Signature = sql.NullString{
				Valid:  false,
				String: r.FormValue("signature"),
			}
		} else {
			user.Signature = sql.NullString{
				Valid:  true,
				String: r.FormValue("signature"),
			}
		}

		// Change hiding settings
		user.HideOnline = false
		if r.FormValue("hide_online") == "1" {
			user.HideOnline = true
		}

		// Update the username?
		if len(user.Username) < 3 {
			form_error = "Username must at least 3 characters"
		}

		// Update password?
		new_pass := r.FormValue("password_new")
		new_pass2 := r.FormValue("password_new2")
		if len(new_pass) > 0 {
			if len(new_pass) < 5 {
				form_error = "Password must be greater than 4 characters"
			} else if new_pass != new_pass2 {
				form_error = "Passwords didn't match"
			} else {
				user.SetPassword(new_pass)
			}
		}

		group_id, _ := strconv.Atoi(r.FormValue("group_id"))
		user.GroupId = int64(group_id)

		if form_error == "" {
			db.Update(user)
			success = true
		}
	}

	utils.RenderTemplate(w, r, "admin_user.html", map[string]interface{}{
		"error":   form_error,
		"success": success,
		"user":    user,
	}, nil)
}
开发者ID:nota-ja,项目名称:gobb,代码行数:79,代码来源:admin_users.go


示例18: AdminBoards

func AdminBoards(w http.ResponseWriter, r *http.Request) {
	current_user := utils.GetCurrentUser(r)
	if current_user == nil || !current_user.IsAdmin() {
		http.NotFound(w, r)
		return
	}

	db := models.GetDbSession()
	// Creating a board
	if r.Method == "POST" && r.FormValue("create_board") != "" {
		name := r.FormValue("title")
		desc := r.FormValue("description")
		form_order := r.FormValue("order")
		var order int

		if form_order != "" {
			if len(form_order) == 0 {
				order = 1
			} else {
				order, _ = strconv.Atoi(form_order)
			}
		} else {
			order = 1
		}

		board := models.NewBoard(name, desc, order)

		db.Insert(board)
	}

	// Update the boards
	if r.Method == "POST" && r.FormValue("update_boards") != "" {
		err := r.ParseForm()

		// loop through the post data, entries correspond via index in the map
		for i := 0; i < len(r.Form["board_id"]); i++ {
			// basically repeat the process for inserting a board
			form_id, _ := strconv.Atoi(r.Form["board_id"][i])
			id := int64(form_id)
			name := r.Form["name"][i]
			desc := r.Form["description"][i]
			form_order := r.Form["order"][i]
			groupidst := r.Form["groupid"][i]
			var order int
			var groupid int64
			if form_order != "" {
				if len(form_order) == 0 {
					order = 1
				} else {
					order, _ = strconv.Atoi(form_order)
				}
			} else {
				order = 1
			}
			if len(groupidst) < 1 {
				groupid = 0
			} else {
				groupid, _ = strconv.ParseInt(groupidst, 10, 64)
			}
			board := models.UpdateBoard(name, desc, order, id, groupid)

			db.Update(board)
		}

		if err != nil {
			http.NotFound(w, r)
			return
		}
	}

	// Delete a board
	if id := r.FormValue("delete"); id != "" {
		obj, _ := db.Get(&models.Board{}, id)

		if obj == nil {
			http.NotFound(w, r)
			return
		}

		board := obj.(*models.Board)
		board.Delete()
	}

	boards, _ := models.GetBoards()

	utils.RenderTemplate(w, r, "admin_boards.html", map[string]interface{}{
		"boards": boards,
	}, nil)
}
开发者ID:s2607,项目名称:gobb,代码行数:89,代码来源:admin_boards.go


示例19: Thread

func Thread(w http.ResponseWriter, r *http.Request) {
	page_id_str := r.FormValue("page")
	page_id, err := strconv.Atoi(page_id_str)
	if err != nil {
		page_id = 0
	}

	board_id_str := mux.Vars(r)["board_id"]
	board_id, _ := strconv.Atoi(board_id_str)
	board, err := models.GetBoard(board_id)

	post_id_str := mux.Vars(r)["post_id"]
	post_id, _ := strconv.Atoi(post_id_str)
	err, op, posts := models.GetThread(post_id, page_id)

	var posting_error error

	current_user := utils.GetCurrentUser(r)
	if r.Method == "POST" {
		db := models.GetDbSession()
		title := r.FormValue("title")
		content := r.FormValue("content")

		if current_user == nil {
			http.NotFound(w, r)
			return
		}

		if op.Locked && !current_user.CanModerate() {
			http.NotFound(w, r)
			return
		}

		post := models.NewPost(current_user, board, title, content)
		post.ParentId = sql.NullInt64{int64(post_id), true}
		op.LatestReply = time.Now()

		posting_error = post.Validate()

		if posting_error == nil {
			db.Insert(post)
			db.Update(op)

			if page := post.GetPageInThread(); page != page_id {
				http.Redirect(w, r, fmt.Sprintf("/board/%d/%d?page=%d#post_%d", post.BoardId, op.Id, page, post.Id), http.StatusFound)
			}

			err, op, posts = models.GetThread(post_id, page_id)
		}
	}

	if err != nil {
		http.NotFound(w, r)
		fmt.Printf("[error] Something went wrong in posts (%s)\n", err.Error())
		return
	}

	num_pages := op.GetPagesInThread()

	if page_id > num_pages {
		http.NotFound(w, r)
		return
	}

	var previous_text string
	if posting_error != nil {
		previous_text = r.FormValue("content")
	}

	// Mark the thread as read
	if current_user != nil {
		models.AddView(current_user, op)
	}

	utils.RenderTemplate(w, r, "thread.html", map[string]interface{}{
		"board":         board,
		"op":            op,
		"posts":         posts,
		"first_page":    (page_id > 0),
		"prev_page":     (page_id > 1),
		"next_page":     (page_id < num_pages-1),
		"last_page":     (page_id < num_pages),
		"page_id":       page_id,
		"posting_error": posting_error,
		"previous_text": previous_text,
	}, map[string]interface{}{

		"CurrentUserCanModerateThread": func(thread *models.Post) bool {
			current_user := utils.GetCurrentUser(r)
			if current_user == nil {
				return false
			}

			return (current_user.CanModerate() && thread.ParentId.Valid == false)
		},

		"CurrentUserCanDeletePost": func(thread *models.Post) bool {
			current_user := utils.GetCurrentUser(r)
			if current_user == nil {
				return false
//.........这里部分代码省略.........
开发者ID:nmbook,项目名称:gobb,代码行数:101,代码来源:thread.go



注:本文中的github.com/stevenleeg/gobb/utils.GetCurrentUser函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gkvlite.Collection类代码示例发布时间:2022-05-28
下一篇:
Golang models.GetDbSession函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap