diff options
author | Azul <azul@leap.se> | 2013-01-22 12:02:18 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-01-22 13:06:37 +0100 |
commit | de48efcf2a6b5fb096fd209b1efea482f743c19c (patch) | |
tree | c555b53719f67fd48bd6b742ff2f5e2ede7b7c53 | |
parent | ed1caa740f0e58cfd5f2d908946461154db68174 (diff) |
some basic webfinger routes, controller, presenters, views
-rw-r--r-- | users/app/controllers/webfinger_controller.rb | 15 | ||||
-rw-r--r-- | users/app/helpers/users_helper.rb.orig | 47 | ||||
-rw-r--r-- | users/app/models/user.rb | 2 | ||||
-rw-r--r-- | users/app/views/emails/_email.html.haml.orig | 12 | ||||
-rw-r--r-- | users/app/views/webfinger/host_meta.erb | 11 | ||||
-rw-r--r-- | users/app/views/webfinger/search.erb | 6 | ||||
-rw-r--r-- | users/config/routes.rb | 2 | ||||
-rw-r--r-- | users/lib/.webfinger.rb.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | users/lib/leap_web_users/engine.rb | 2 | ||||
-rw-r--r-- | users/lib/webfinger.rb | 6 | ||||
-rw-r--r-- | users/lib/webfinger/host_meta_presenter.rb | 17 | ||||
-rw-r--r-- | users/lib/webfinger/user_presenter.rb | 16 |
12 files changed, 136 insertions, 0 deletions
diff --git a/users/app/controllers/webfinger_controller.rb b/users/app/controllers/webfinger_controller.rb new file mode 100644 index 0000000..e86cd2d --- /dev/null +++ b/users/app/controllers/webfinger_controller.rb @@ -0,0 +1,15 @@ +class WebfingerController < ApplicationController + + layout false + + def host_meta + @host_meta = Webfinger::HostMetaPresenter.new(request) + end + + def search + username = params[:q].split('@')[0].to_s.downcase + + user = User.find_by_login(username) + @subject = Webfinger::UserPresenter.new(user, request) + end +end diff --git a/users/app/helpers/users_helper.rb.orig b/users/app/helpers/users_helper.rb.orig new file mode 100644 index 0000000..ed027d3 --- /dev/null +++ b/users/app/helpers/users_helper.rb.orig @@ -0,0 +1,47 @@ +module UsersHelper + + def user_form_with(partial, options = {}) + user_form(options) do |f| + options[:f] = f + render :partial => partial, + :layout => 'legend_and_submit', + :locals => options + end + end + + def user_form(options = {}) + simple_form_for @user, + :html => user_form_html_options(options), + :validate => true do |f| + yield f + end + end + + def user_form_html_options(options) + { :class => user_form_html_classes(options).join(" "), + :id => dom_id(@user, options[:legend]) + } + end + + def user_form_html_classes(options) + classes = %W/form-horizontal user form/ + classes << options[:legend] + classes << (@user.new_record? ? 'new' : 'edit') + classes.compact + end + +<<<<<<< HEAD + def user_field(field) + value = @user.send(field) + value = value.to_s(:long) if field.end_with? '_at' + value || 'not set' +======= + def wrapped(item, options = {}) + options[:as] ||= :div + content_tag options[:as], :class => dom_class(item), :id => dom_id(item) do + yield + end +>>>>>>> more flexible email partial + end + +end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 292fb13..eff7abd 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -9,6 +9,8 @@ class User < CouchRest::Model::Base property :email_forward, String, :accessible => true property :email_aliases, [LocalEmail] + property :public_key + validates :login, :password_salt, :password_verifier, :presence => true diff --git a/users/app/views/emails/_email.html.haml.orig b/users/app/views/emails/_email.html.haml.orig new file mode 100644 index 0000000..440870d --- /dev/null +++ b/users/app/views/emails/_email.html.haml.orig @@ -0,0 +1,12 @@ +<<<<<<< HEAD +%li.pull-right + %code= email + - if params[:action] == 'edit' +======= += wrapped(email, local_assigns) do + = email + - if local_assigns[:with].try(:include?, :delete) +>>>>>>> more flexible email partial + = link_to(user_email_alias_path(@user, email), :method => :delete) do + %i.icon-remove +.clearfix diff --git a/users/app/views/webfinger/host_meta.erb b/users/app/views/webfinger/host_meta.erb new file mode 100644 index 0000000..23b4039 --- /dev/null +++ b/users/app/views/webfinger/host_meta.erb @@ -0,0 +1,11 @@ + <?xml version='1.0' encoding='UTF-8'?> + <XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'> + + <Subject><%= @host_meta.subject %></Subject> + + + <Link rel='lrdd' + type='application/xrd+xml' + template='<%= @host_meta.webfinger_template %>' /> + + </XRD> diff --git a/users/app/views/webfinger/search.erb b/users/app/views/webfinger/search.erb new file mode 100644 index 0000000..0bcb7e5 --- /dev/null +++ b/users/app/views/webfinger/search.erb @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"> + <Subject>acct:<%= @subject.email_identifier %></Subject> + <Alias>"<%= user_url(@subject.subject) %>"</Alias> + <Link rel="public-key" type = 'PGP' href="<%= @subject.key %>"/> +</XRD> diff --git a/users/config/routes.rb b/users/config/routes.rb index 0c2d8d9..4127862 100644 --- a/users/config/routes.rb +++ b/users/config/routes.rb @@ -18,4 +18,6 @@ Rails.application.routes.draw do resources :email_aliases, :only => [:destroy], :id => /.*/ end + get "/.well-known/host-meta" => 'webfinger#host_meta' + get "/webfinger" => 'webfinger#search' end diff --git a/users/lib/.webfinger.rb.swp b/users/lib/.webfinger.rb.swp Binary files differnew file mode 100644 index 0000000..09528c6 --- /dev/null +++ b/users/lib/.webfinger.rb.swp diff --git a/users/lib/leap_web_users/engine.rb b/users/lib/leap_web_users/engine.rb index 7033576..f8ed71c 100644 --- a/users/lib/leap_web_users/engine.rb +++ b/users/lib/leap_web_users/engine.rb @@ -7,6 +7,8 @@ require "ruby-srp" require "warden/session_serializer" require "warden/strategies/secure_remote_password" +require "webfinger" + module LeapWebUsers class Engine < ::Rails::Engine diff --git a/users/lib/webfinger.rb b/users/lib/webfinger.rb new file mode 100644 index 0000000..dd49b41 --- /dev/null +++ b/users/lib/webfinger.rb @@ -0,0 +1,6 @@ +module Webfinger + + autoload :HostMetaPresenter, 'webfinger/host_meta_presenter' + autoload :UserPresenter, 'webfinger/user_presenter' + +end diff --git a/users/lib/webfinger/host_meta_presenter.rb b/users/lib/webfinger/host_meta_presenter.rb new file mode 100644 index 0000000..3901a28 --- /dev/null +++ b/users/lib/webfinger/host_meta_presenter.rb @@ -0,0 +1,17 @@ +require 'uri' + +class Webfinger::HostMetaPresenter + def initialize(request) + @request = request + end + + def subject + url = URI.parse(@request.url) + url.path = '' + url.to_s + end + + def webfinger_template(path = 'webfinger', query_param='q') + "#{subject}/#{path}?#{query_param}={uri}" + end +end diff --git a/users/lib/webfinger/user_presenter.rb b/users/lib/webfinger/user_presenter.rb new file mode 100644 index 0000000..bbfc908 --- /dev/null +++ b/users/lib/webfinger/user_presenter.rb @@ -0,0 +1,16 @@ +class Webfinger::UserPresenter + attr_accessor :subject + + def initialize(subject, request) + @subject = subject + @request = request + end + + def email_identifier + "#{@subject.username}@#{@request.host}" + end + + def key + Base64.encode64(@subject.public_key.to_s) + end +end |