Module: Pasaporte::Views
- Defined in:
- lib/pasaporte.rb
Instance Method Summary collapse
- #_approval_block(appr) ⇒ Object
- #_cbox(obj_name, field, opts = {}) ⇒ Object
-
#_h(s) ⇒ Object
HTML esc.
-
#_openid_delegate_uri ⇒ Object
Render either our identity URL or the URL of the delegate.
-
#_openid_server_uri ⇒ Object
Render either our endpoint URL or the URL of the delegate.
-
#_our_endpoint_uri ⇒ Object
Canonicalized URL of our endpoint.
- #_our_identity_url ⇒ Object
-
#_profile_url ⇒ Object
Canonicalized identity URL of the current profile.
-
#_s(file) ⇒ Object
link to a static file.
- #_tf(obj_name, field, t, opts = {}) ⇒ Object
- #_toolbar ⇒ Object
- #approvals_page ⇒ Object
-
#bailout ⇒ Object
Harsh but necessary.
-
#dash ⇒ Object
Render the dash.
-
#decide ⇒ Object
Let the user decide what data he wants to transfer.
-
#endpoint_splash ⇒ Object
A dummy page that gets shown if the user hides his profile info or he hasn’t authenticated with us yet.
- #layout ⇒ Object
- #profile_form ⇒ Object
-
#profile_public_page ⇒ Object
Render the public profile page.
- #signon_form ⇒ Object
Instance Method Details
#_approval_block(appr) ⇒ Object
931 932 933 934 |
# File 'lib/pasaporte.rb', line 931 def _approval_block(appr) h4 appr a "Remove this site", :href => R(DeleteApproval, @nickname, appr) end |
#_cbox(obj_name, field, opts = {}) ⇒ Object
957 958 959 960 961 962 963 964 965 966 967 |
# File 'lib/pasaporte.rb', line 957 def _cbox(obj_name, field, opts = {}) obj, field_name = instance_variable_get("@#{obj_name}"), "#{obj_name}[#{field}]" input :type=>:hidden, :name => field_name, :value => 0 opts[:id] ||= "#{obj_name}_#{field}" if !!obj.send(field) input opts.merge(:type=>:checkbox, :name => field_name, :value => 1, :checked => :checked) else input opts.merge(:type=>:checkbox, :name => field_name, :value => 1) end end |
#_h(s) ⇒ Object
HTML esc. snatched off ERB
898 899 900 |
# File 'lib/pasaporte.rb', line 898 def _h(s) s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<") end |
#_openid_delegate_uri ⇒ Object
Render either our identity URL or the URL of the delegate
881 882 883 |
# File 'lib/pasaporte.rb', line 881 def _openid_delegate_uri (@profile && @profile.delegates_openid?) ? @profile.openid_delegate : _our_identity_url end |
#_openid_server_uri ⇒ Object
Render either our endpoint URL or the URL of the delegate
876 877 878 |
# File 'lib/pasaporte.rb', line 876 def _openid_server_uri (@profile && @profile.delegates_openid?) ? @profile.openid_server : _our_endpoint_uri end |
#_our_endpoint_uri ⇒ Object
Canonicalized URL of our endpoint
886 887 888 889 890 |
# File 'lib/pasaporte.rb', line 886 def _our_endpoint_uri uri = "#{@env.HTTPS.to_s.downcase == 'on' ? 'https' : 'http'}://" + [env["HTTP_HOST"], env["SCRIPT_NAME"], R(Openid, @nickname)].join('/').squeeze('/') OpenID::URINorm.urinorm(uri) uri end |
#_our_identity_url ⇒ Object
892 893 894 895 |
# File 'lib/pasaporte.rb', line 892 def _our_identity_url uri = "#{@env.HTTPS.to_s.downcase == 'on' ? 'https' : 'http'}://" + [env["HTTP_HOST"], env["SCRIPT_NAME"], R(ProfilePage, @nickname)].join('/').squeeze('/') OpenID::URINorm.urinorm(uri) end |
#_profile_url ⇒ Object
Canonicalized identity URL of the current profile
1062 1063 1064 |
# File 'lib/pasaporte.rb', line 1062 def _profile_url "http://" + [env["HTTP_HOST"], env["SCRIPT_NAME"], @profile.nickname].join('/').squeeze('/') end |
#_s(file) ⇒ Object
link to a static file
871 872 873 |
# File 'lib/pasaporte.rb', line 871 def _s(file) R(Assets, file) end |
#_tf(obj_name, field, t, opts = {}) ⇒ Object
949 950 951 952 953 954 955 |
# File 'lib/pasaporte.rb', line 949 def _tf(obj_name, field, t, opts = {}) obj, field_name, id = instance_variable_get("@#{obj_name}"), "#{obj_name}[#{field}]", "#{obj_name}_#{field}" label.fb(:for => id) do self << t input opts.merge(:type => "text", :value => obj[field], :id => id, :name => field_name) end end |
#_toolbar ⇒ Object
926 927 928 929 |
# File 'lib/pasaporte.rb', line 926 def # my profile button # log me out button end |
#approvals_page ⇒ Object
936 937 938 939 940 941 942 943 944 945 946 947 |
# File 'lib/pasaporte.rb', line 936 def approvals_page h2 "The sites you trust" if @approvals.any? p { "These sites will be able to automatically log you in without first asking you to approve" } p { "Removing a site from the list will force that site to ask your permission next time when checking your OpenID" } ul.apprList! do @approvals.map { | ap | li { _approval_block(ap) } } end else p "You did not yet authorize any sites to use your OpenID" end end |
#bailout ⇒ Object
Harsh but necessary
785 786 787 788 |
# File 'lib/pasaporte.rb', line 785 def bailout h2 "Sorry but it's true" self << p(@report) end |
#dash ⇒ Object
Render the dash
791 792 793 794 795 796 797 798 799 800 |
# File 'lib/pasaporte.rb', line 791 def dash h2 { "Welcome <b>#{@nickname}</b>, nice to have you back" } p { "Your OpenID is <b>#{_our_identity_url}</b>" } ul.bigz! do li.profButn! { a "Change your profile", :href => R(EditProfile, @nickname) } if @profile.approvals.count > 0 li.apprButn! { a "See the sites that logged you in", :href => R(ApprovalsPage, @nickname) } end end end |
#decide ⇒ Object
Let the user decide what data he wants to transfer
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
# File 'lib/pasaporte.rb', line 903 def decide h2{ "Please approve <b>#{_h(@oid_request.trust_root)}</b>" } p "You never logged into that site with us. Do you want us to confirm that you do have an account here?" when_sreg_is_required(@oid_request) do | asked_fields, policy | p{ "Additionally, the site wants to know your <b>#{asked_fields.to_sentence}.</b> These will be sent along."} if policy p do self << "That site has a " a("policy on it's handling of user data", :href => policy) self << " that you might want to read beforehand." end end end form :method => :post do _csrf_token input :name => :pleasedo, :type => :submit, :value => " Yes, do allow " self << ' ' input :name => :nope, :type => :submit, :value => " No, they are villains! " end end |
#endpoint_splash ⇒ Object
A dummy page that gets shown if the user hides his profile info or he hasn’t authenticated with us yet
1068 1069 1070 |
# File 'lib/pasaporte.rb', line 1068 def endpoint_splash h3 { "This is <b>#{@nickname}'s</b> page" } end |
#layout ⇒ Object
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
# File 'lib/pasaporte.rb', line 831 def layout @headers['Cache-Control'] = 'no-cache; must-revalidate' @headers['Content-Type'] ||= 'text/html' if @skip_layout self << yield; return end xhtml_transitional do head do self << '<meta http-equiv="X-XRDS-Location" content="%s/yadis" />' % _our_identity_url link :rel => "openid.server", :href => _openid_server_uri link :rel => "openid.delegate", :href => _openid_delegate_uri link :rel => "stylesheet", :href => _s("pasaporte.css") script :type=>'text/javascript', :src => _s("pasaporte.js") title(@title || ('%s : pasaporte' % env['SERVER_NAME'])) end body :class => @ctr do unless @no_toolbar div. do if is_logged_in? b.profBtn! "Logged in as #{@nickname.capitalize}" a.loginBtn! "Log out", :href => R(Signout, @nickname) else b.loginBtn! "You are not logged in" end img :src => _s('openid.png'), :alt => 'OpenID system' end end div.work! :class => (is_logged_in? ? "logdin" : "notAuth") do returning(@err || @msg) {| m | div.msg!(:class =>(@err ? 'e' : 'm')){m} if m } self << yield end end end end |
#profile_form ⇒ Object
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
# File 'lib/pasaporte.rb', line 969 def profile_form form(:method => :post) do h2 "Your profile" _csrf_token label.cblabel :for => :share_info do _cbox :profile, :shared, :id => :share_info self << '  Share your info on your OpenID page' self << " (" b { a(:href => _profile_url, :target => '_new') { _profile_url } } self << ")" end div.persinfo! :style => "display: #{@profile.shared? ? 'block' : 'none'}" do textarea(:rows => 10, :name => 'profile[info]') { @profile.info } end script(:type=>"text/javascript") do self << %Q[ attachCheckbox("share_info", "persinfo");] end h2 "Simple registration info" p.sml 'When you register on some sites they can ' + 'use this info to fill their registration forms ' + 'for you' _tf(:profile, :fullname, "Your full name:") _tf(:profile, :email, "Your e-mail:") div.rad do self << "You are  " {'m' => ' a guy ', 'f' => ' a gal '}.each_pair do | v, t | opts = {:id => "gend_#{v}", :type=>:radio, :name => 'profile[gender]', :value => v} opts[:checked] = :checked if @profile.gender == v label(:for => opts[:id]) { input(opts); self << t } end end label.sel(:for => 'countries') do self << "Your country of residence" select :id=>:countries, :name => 'profile[country]' do COUNTRIES.values.sort.map do | c | code = COUNTRIES.index(c) opts = {:value => code} if (@profile.country && @profile.country == code) || DEFAULT_COUNTRY == code opts[:selected] = true end option(opts) { c } end end end label.sel do self << "Your date of birth" span.inlineSelects do self << date_select(:profile, :dob, :start_year => 1930, :end_year => (Date.today.year - 15)) end end label "The timezone you are in" select :name => 'profile[timezone]', :style => 'width: 100%' do TIMEZONES.map do | formal, humane | opts = {:value => formal} opts.merge! :selected => :selected if (formal == @profile.timezone) option(humane, opts) end end if ALLOW_DELEGATION h2 "OpenID delegation" label.cblabel :for => :delegate do _cbox(:profile, :delegates_openid) self << "  Use another site " + "as your <a href='http://openid.net/wiki/index.php/Delegation'>OpenID provider.</a>" end div.smaller :id => 'delegationDetails' do p "The site that you want to use for OpenID should have given you the necessary URLs." _tf(:profile, :openid_server, "Server URL:") _tf(:profile, :openid_delegate, "Delegate URL:") end end script(:type=>"text/javascript") do self << %Q[ attachCheckbox("profile_delegates_openid", "delegationDetails");] end hr input :type=>:submit, :value=>'Save my settings' # or Cancel end end |
#profile_public_page ⇒ Object
Render the public profile page
803 804 805 806 807 808 |
# File 'lib/pasaporte.rb', line 803 def profile_public_page h2 do _h(@profile.fullname.blank? ? @profile.nickname : @profile.fullname) end p _h(@profile.info) end |
#signon_form ⇒ Object
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/pasaporte.rb', line 810 def signon_form form.signon! :method => :post do label :for => 'login' do self << "Your name:" # We include a hidden input here but it's only ever used by PublicSignon if @nickname && @state.pending_openid b(@nickname) input(:name => "login", :value => @nickname, :type => :hidden) else input.login!(:name => "login", :value => @nickname) end end label :for => 'pass' do self << "Your password:" input.pass! :name => "pass", :type => "password" end _csrf_token input :type => :submit, :value => 'Log me in' end end |