gpt4 book ai didi

ruby - 如何配置 Gollum-wiki 以允许基本身份验证并使用用户名进行 git 提交

转载 作者:行者123 更新时间:2023-12-05 01:45:41 24 4
gpt4 key购买 nike

我正在尝试为 gollum 配置基本的 http 身份验证,但我希望将登录的用户名用于 git 提交。

我已经修改了 config.ru 以便基本身份验证可以工作,现在我只需要弄清楚如何实现与此等效的功能:

session['gollum.author'] => "%s" % loggedIn

然后我可以删除“John Smith”字符串。

顺便说一句 - 请原谅这个愚蠢的问题,我以前从未接触过 Ruby,而且已经晚了。

#!/usr/bin/env ruby
#--------------------------------------------------------------------
# - example custom rack for the Gollum wiki engine
# - file should be placed in wiki root
# - RACK_APP environment variable should be set to the filename
# - entrypoint.sh script will run this app using:
# $ rackup $RACK_APP -p 4567
#--------------------------------------------------------------------
require 'rubygems'
require 'gollum/app'

gollum_path = File.expand_path(File.dirname(__FILE__))
wiki_options = {
:live_preview => false,
:allow_editing => true,
:allow_uploads => true,
:universal_toc => false,
}

users = {'user' => 'password'}
loggedIn = "anonymous"

use Rack::Auth::Basic, 'realm' do |username, password|
users.key?(username) && users[username] == password
loggedIn = username
end

Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App

#set author
class Precious::App
before do
session['gollum.author'] = {
:name => "%s" % "john smith", # => "%s" % loggedIn
:email => "jsmith@example.com",
}
end
end

所以我可以看到 session 只存在于 Precious Class 命名空间中,所以我不能直接从我的身份验证方法中设置它:

use Rack::Auth::Basic, 'realm' do |username, password|
users.key?(username) && users[username] == password
session['gollum.author'] = {
:name => "%s" % "john smith", # => "%s" % username
:email => "jsmith@example.com",
}
end

我也试过:

use Rack::Auth::Basic, 'realm' do |username, password|
users.key?(username) && users[username] == password
loggedIn = {
:name => "%s" % username,
:email => "jsmith@example.com",
}
end

Precious::App.set(:session['gollum.author'], loggedIn)

最佳答案

这是一个解决方案,它允许您定义一系列用户,启用基本的 http 身份验证并使用登录的用户名进行合适的提交。

require 'rubygems'
require 'gollum/app'

gollum_path = File.expand_path(File.dirname(__FILE__))
wiki_options = {
:live_preview => false,
:allow_editing => true,
:allow_uploads => true,
:universal_toc => false,
}

users = {'user' => 'password',
'user2' => 'password2'}

use Rack::Auth::Basic, 'realm' do |username, password|
if users.key?(username) && users[username] == password
Precious::App.set(:loggedInUser, username)
end
end

Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App

#set author
class Precious::App
before do
session['gollum.author'] = {
:name => "%s" % settings.loggedInUser,
:email => "%s@example.com" % settings.loggedInUser,
}
end
end

关于ruby - 如何配置 Gollum-wiki 以允许基本身份验证并使用用户名进行 git 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40690778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com