Skip to content

Commit

Permalink
adds indieauth sign-in form so people can create accounts for themsel…
Browse files Browse the repository at this point in the history
…ves!
  • Loading branch information
aaronpk committed Nov 30, 2014
1 parent d2df2d1 commit 20413b2
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 139 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Expand Up @@ -13,13 +13,13 @@ gem 'dalli'
gem 'ratom', :require => 'atom'

gem 'omniauth'
gem 'omniauth-github'
gem 'omniauth-indieauth'

gem 'mechanize'
gem 'pingback'
gem 'xml-simple', :require => 'xmlsimple'
#gem 'pingback'
#gem 'xml-simple', :require => 'xmlsimple'
gem 'rest-client'
gem 'xmpp4r', :require => 'xmpp4r/client'
#gem 'xmpp4r', :require => 'xmpp4r/client'
gem 'redis'

gem 'microformats2'
Expand Down
189 changes: 95 additions & 94 deletions Gemfile.lock
@@ -1,128 +1,132 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.2.7)
backports (2.4.0)
daemons (1.1.8)
dalli (1.1.5)
data_objects (0.10.7)
activesupport (4.1.8)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.6)
backports (3.6.4)
daemons (1.1.9)
dalli (2.7.2)
data_objects (0.10.14)
addressable (~> 2.1)
dm-aggregates (1.1.0)
dm-core (~> 1.1.0)
dm-core (1.1.0)
addressable (~> 2.2.4)
dm-do-adapter (1.1.0)
data_objects (~> 0.10.2)
dm-core (~> 1.1.0)
dm-migrations (1.1.0)
dm-core (~> 1.1.0)
dm-mysql-adapter (1.1.0)
dm-do-adapter (~> 1.1.0)
do_mysql (~> 0.10.2)
dm-aggregates (1.2.0)
dm-core (~> 1.2.0)
dm-core (1.2.1)
addressable (~> 2.3)
dm-do-adapter (1.2.0)
data_objects (~> 0.10.6)
dm-core (~> 1.2.0)
dm-migrations (1.2.0)
dm-core (~> 1.2.0)
dm-mysql-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_mysql (~> 0.10.6)
dm-pager (1.1.0)
dm-aggregates (>= 0.10.1)
dm-core (>= 0.10.1)
dm-timestamps (1.1.0)
dm-core (~> 1.1.0)
do_mysql (0.10.7)
data_objects (= 0.10.7)
domain_name (0.5.2)
unf (~> 0.0.3)
dm-timestamps (1.2.0)
dm-core (~> 1.2.0)
do_mysql (0.10.14)
data_objects (= 0.10.14)
domain_name (0.5.22)
unf (>= 0.0.5, < 1.0.0)
erubis (2.7.0)
eventmachine (0.12.10)
faraday (0.8.8)
multipart-post (~> 1.2.0)
hashie (1.2.0)
httpauth (0.2.0)
json (1.6.5)
jwt (0.1.8)
multi_json (>= 1.5)
kgio (2.7.4)
libxml-ruby (2.3.3)
mechanize (2.3)
eventmachine (1.0.3)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
hashie (3.3.2)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.6.11)
json (1.8.1)
kgio (2.9.2)
libxml-ruby (2.6.0)
mechanize (2.7.3)
domain_name (~> 0.5, >= 0.5.1)
mime-types (~> 1.17, >= 1.17.2)
http-cookie (~> 1.0)
mime-types (~> 2.0)
net-http-digest_auth (~> 1.1, >= 1.1.1)
net-http-persistent (~> 2.5, >= 2.5.2)
nokogiri (~> 1.4)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (~> 0.0, >= 0.0.9)
microformats2 (1.0.2)
webrobots (>= 0.0.9, < 0.2)
microformats2 (2.0.1)
activesupport
json
nokogiri
mime-types (1.18)
multi_json (1.8.2)
multipart-post (1.2.0)
mime-types (2.4.3)
mini_portile (0.6.1)
minitest (5.4.3)
multi_json (1.10.1)
multipart-post (2.0.0)
mysql2 (0.3.7)
net-http-digest_auth (1.2)
net-http-persistent (2.5.2)
nokogiri (1.5.2)
net-http-digest_auth (1.4)
net-http-persistent (2.9.4)
netrc (0.8.0)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
ntlm-http (0.1.1)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.0.3)
hashie (~> 1.2)
rack
omniauth-github (1.1.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-indieauth (0.1.3)
faraday (~> 0.9.0)
microformats2 (>= 2.0.1)
omniauth (~> 1.0)
pingback (1.1.0)
nokogiri
rack
rack (1.4.1)
rack-protection (1.2.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
rack-test (0.6.1)
rack-test (0.6.2)
rack (>= 1.0)
rainbows (4.3.1)
rainbows (4.6.2)
kgio (~> 2.5)
rack (~> 1.1)
unicorn (~> 4.1)
raindrops (0.8.0)
rake (0.9.2.2)
ratom (0.7.2)
libxml-ruby (~> 2.3.2)
redis (3.0.5)
rest-client (1.6.7)
mime-types (>= 1.16)
unicorn (~> 4.8)
raindrops (0.13.0)
rake (10.4.0)
ratom (0.8.2)
libxml-ruby (~> 2.6.0)
redis (3.1.0)
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
shotgun (0.9)
rack (>= 1.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sinatra-contrib (1.3.1)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-contrib (1.4.2)
backports (>= 2.0)
eventmachine
multi_json
rack-protection
rack-test
sinatra (~> 1.3.0)
sinatra (~> 1.4.0)
tilt (~> 1.3)
sinatra-namespace (1.0)
sinatra-contrib
sinatra-support (1.2.2)
sinatra (>= 1.0)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
unf (0.0.5)
thin (1.6.3)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0)
rack (~> 1.0)
thread_safe (0.3.4)
tilt (1.4.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.4)
unicorn (4.2.0)
unf_ext (0.0.6)
unicorn (4.8.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
webrobots (0.0.13)
xml-simple (1.1.1)
xmpp4r (0.5)
webrobots (0.1.1)

PLATFORMS
ruby
Expand All @@ -142,8 +146,7 @@ DEPENDENCIES
microformats2
mysql2 (= 0.3.7)
omniauth
omniauth-github
pingback
omniauth-indieauth
rainbows
rake
ratom
Expand All @@ -154,5 +157,3 @@ DEPENDENCIES
sinatra-namespace
sinatra-support
thin
xml-simple
xmpp4r
9 changes: 2 additions & 7 deletions config.yml.template
@@ -1,13 +1,8 @@
development:
database_url: "mysql://root@127.0.0.1/pingback"
database_url: "mysql://webmention:webmention@127.0.0.1/webmention"
session_secret: SUPERSECRET
ga_id:
geoloqi:
api_key:
api_secret:
github:
client_id:
client_secret:
base_url: "https://webmention.io"
redis:
host: 127.0.0.1
port: 6379
Expand Down
24 changes: 2 additions & 22 deletions controller.rb
Expand Up @@ -9,7 +9,7 @@ class Controller < Sinatra::Base
if request.path.match /[a-zA-Z0-9_\.]\/(xmlrpc|webmention)/ or request.path.match /^\/api\// or request.path.match /^\/webmention/
# No login required for /xmlrpc routes
else
if !["/", "/auth/github", "/auth/github/callback"].include? request.path
if !["/", "/auth/indieauth", "/auth/indieauth/callback"].include? request.path
puts request.body.read
require_login
end
Expand All @@ -24,7 +24,7 @@ def require_login
redirect "/"
end

@user = User.get session[:user_id]
@user = Account.get session[:user_id]
if @user.nil?
puts "No user found. Redirecting."
redirect "/"
Expand All @@ -43,26 +43,6 @@ def require_login

# Authentication

get '/auth/github/callback' do
auth = request.env["omniauth.auth"]
user = User.first :username => auth["info"]["nickname"]
if user.nil?
puts "Unauthorized github login"
title "Unauthorized"
@message = "Sorry, you are not authorized to log in"
erb :error
else
user.last_login_date = Time.now
if user.email == '' && auth["info"]["email"]
user.email = auth["info"]["email"]
end
user.save
session[:user_id] = user[:id]
puts "User successfully logged in"
redirect "/dashboard/"
end
end

get '/auth/failure' do
@message = "The authentication provider replied with an error: #{params['message']}"
title "Error"
Expand Down
2 changes: 1 addition & 1 deletion controllers/api.rb
Expand Up @@ -220,7 +220,7 @@ class Controller < Sinatra::Base
links: link_array
}
else
base_url = "http://webmention.io"
base_url = "https://webmention.io"
atom_url = "#{base_url}/api/mentions.atom"
feed = Atom::Feed.new{|f|
f.title = "Mentions"
Expand Down
30 changes: 30 additions & 0 deletions controllers/auth.rb
@@ -0,0 +1,30 @@
class Controller < Sinatra::Base

get '/auth/start' do
redirect "https://indieauth.com/auth?client_id=#{SiteConfig.base_url}/&redirect_uri=#{SiteConfig.base_url}/auth/callback"
end

get '/auth/indieauth/callback' do
auth = request.env["omniauth.auth"]
puts auth.info.url.inspect
domain = URI.parse(auth.info.url).host.downcase

user = Account.first :domain => domain

if user.nil?
user = Account.new
user.username = domain
user.domain = domain
user.created_at = Time.now
user.updated_at = Time.now
end

user.last_login = Time.now
user.save

session[:user_id] = user[:id]
puts "User successfully logged in"
redirect "/dashboard"
end

end
2 changes: 1 addition & 1 deletion environment.rb
Expand Up @@ -42,7 +42,7 @@ class Controller < Sinatra::Base
set :protection, :except => [:frame_options, :json_csrf]

use OmniAuth::Builder do
use OmniAuth::Strategies::GitHub, SiteConfig.github.client_id, SiteConfig.github.client_secret
provider :indieauth, :client_id => SiteConfig.base_url
end

DataMapper.finalize
Expand Down
2 changes: 2 additions & 0 deletions models/account.rb
Expand Up @@ -3,6 +3,7 @@ class Account
property :id, Serial

property :username, String, :length => 255
property :domain, String, :length => 255
property :email, String, :length => 255
property :xmpp_to, String, :length => 255
property :xmpp_user, String, :length => 255
Expand All @@ -15,5 +16,6 @@ class Account

property :created_at, DateTime
property :updated_at, DateTime
property :last_login, DateTime

end
2 changes: 1 addition & 1 deletion models/site.rb
Expand Up @@ -6,7 +6,7 @@ class Site

belongs_to :account
has n, :pages
property :public_access, Boolean, :default => false
property :public_access, Boolean, :default => true
property :irc_channel, String, :length => 255
property :xmpp_notify, Boolean, :default => false

Expand Down
2 changes: 1 addition & 1 deletion views/about.erb
Expand Up @@ -5,7 +5,7 @@

<p>This is a hosted pingback service.</p>

<p>To set up your own, check out <a href="http://pingback.me/">pingback.me</a></p>
<p>To set up your own, check out <a href="http://webmention.io/">webmention.io</a></p>

</div>
</div><!-- row -->
Expand Down

0 comments on commit 20413b2

Please sign in to comment.