From 22f84a3ea8bc39eb4cb91575d35dfca683336032 Mon Sep 17 00:00:00 2001 From: Date: Sat, 4 Aug 2007 00:43:54 -0400 Subject: [PATCH] Well, it seems I forgot to add the acts_as_authenticated to the repository on my last commit, but they're there now. Also, I recently added the Gruff graphing plugin, and created a new controller for the graphs, with a method I ported from pollarize to chart how many people have voted per day. The basic_login page works, and the create user sstem works, but is unpolished and still points to a poem as the index page, so if you read a poem, it's supposed to happen. The quickvote creation from the homepage is NOT working however, and is about to be investigated. I'm not sure how much else isn't working. I noted details abotu acts_as_authenticated adn Gruff in the README. --- README | 33 +- app/controllers/account_controller.rb | 45 + app/controllers/application.rb | 1 + app/controllers/graphs_controller.rb | 87 ++ app/controllers/quickvote_controller.rb | 1 + app/controllers/site_controller.rb | 2 +- app/helpers/account_helper.rb | 2 + app/models/account.rb | 0 app/views/account/index.rhtml | 56 + app/views/account/login.rhtml | 14 + app/views/account/signup.rhtml | 16 + app/views/layouts/hc.rhtml | 2 +- db/create.sql | 1 + db/migrate/004_create_users.rb | 18 + lib/authenticated_system.rb | 120 ++ lib/authenticated_test_helper.rb | 113 ++ test/fixtures/users.yml | 17 + test/functional/account_controller_test.rb | 129 ++ test/functional/graphs_controller_test.rb | 24 + test/unit/user_test.rb | 75 ++ .../plugins/acts_as_authenticated/CHANGELOG | 86 ++ vendor/plugins/acts_as_authenticated/README | 20 + .../generators/authenticated/USAGE | 1 + .../authenticated/authenticated_generator.rb | 102 ++ .../templates/authenticated_system.rb | 121 ++ .../templates/authenticated_test_helper.rb | 113 ++ .../authenticated/templates/controller.rb | 43 + .../authenticated/templates/fixtures.yml | 17 + .../templates/functional_test.rb | 129 ++ .../authenticated/templates/helper.rb | 2 + .../authenticated/templates/index.rhtml | 56 + .../authenticated/templates/login.rhtml | 14 + .../authenticated/templates/migration.rb | 18 + .../authenticated/templates/model.rb | 64 + .../authenticated/templates/signup.rhtml | 16 + .../authenticated/templates/unit_test.rb | 75 ++ .../generators/authenticated_mailer/USAGE | 1 + .../authenticated_mailer_generator.rb | 27 + .../templates/activation.rhtml | 3 + .../templates/notifier.rb | 22 + .../templates/notifier_test.rb | 27 + .../templates/observer.rb | 9 + .../templates/signup_notification.rhtml | 8 + .../plugins/acts_as_authenticated/install.rb | 1 + vendor/plugins/gruff/MIT-LICENSE | 20 + vendor/plugins/gruff/README | 15 + vendor/plugins/gruff/Rakefile | 23 + vendor/plugins/gruff/about.yml | 7 + .../gruff/generators/gruff/gruff_generator.rb | 63 + .../generators/gruff/templates/controller.rb | 32 + .../gruff/templates/functional_test.rb | 24 + vendor/plugins/gruff/lib/gruff.rb | 24 + .../gruff/lib/gruff/accumulator_bar.rb | 27 + vendor/plugins/gruff/lib/gruff/area.rb | 58 + vendor/plugins/gruff/lib/gruff/bar.rb | 84 ++ .../plugins/gruff/lib/gruff/bar_conversion.rb | 46 + vendor/plugins/gruff/lib/gruff/base.rb | 1051 +++++++++++++++++ vendor/plugins/gruff/lib/gruff/deprecated.rb | 39 + vendor/plugins/gruff/lib/gruff/line.rb | 94 ++ vendor/plugins/gruff/lib/gruff/mini/bar.rb | 32 + vendor/plugins/gruff/lib/gruff/mini/legend.rb | 77 ++ vendor/plugins/gruff/lib/gruff/mini/pie.rb | 36 + .../plugins/gruff/lib/gruff/mini/side_bar.rb | 22 + vendor/plugins/gruff/lib/gruff/net.rb | 142 +++ vendor/plugins/gruff/lib/gruff/photo_bar.rb | 100 ++ vendor/plugins/gruff/lib/gruff/pie.rb | 108 ++ vendor/plugins/gruff/lib/gruff/scene.rb | 197 +++ vendor/plugins/gruff/lib/gruff/side_bar.rb | 117 ++ .../gruff/lib/gruff/side_stacked_bar.rb | 71 ++ vendor/plugins/gruff/lib/gruff/spider.rb | 130 ++ vendor/plugins/gruff/lib/gruff/stacked_bar.rb | 49 + 71 files changed, 4416 insertions(+), 3 deletions(-) create mode 100644 app/controllers/account_controller.rb create mode 100644 app/controllers/graphs_controller.rb create mode 100644 app/helpers/account_helper.rb create mode 100644 app/models/account.rb create mode 100644 app/views/account/index.rhtml create mode 100644 app/views/account/login.rhtml create mode 100644 app/views/account/signup.rhtml create mode 100644 db/migrate/004_create_users.rb create mode 100644 lib/authenticated_system.rb create mode 100644 lib/authenticated_test_helper.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/functional/account_controller_test.rb create mode 100644 test/functional/graphs_controller_test.rb create mode 100644 test/unit/user_test.rb create mode 100644 vendor/plugins/acts_as_authenticated/CHANGELOG create mode 100644 vendor/plugins/acts_as_authenticated/README create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/USAGE create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/authenticated_generator.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/authenticated_system.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/authenticated_test_helper.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/controller.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/fixtures.yml create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/functional_test.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/helper.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/index.rhtml create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/login.rhtml create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/migration.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/model.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/signup.rhtml create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated/templates/unit_test.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/USAGE create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/authenticated_mailer_generator.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/templates/activation.rhtml create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/templates/notifier.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/templates/notifier_test.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/templates/observer.rb create mode 100644 vendor/plugins/acts_as_authenticated/generators/authenticated_mailer/templates/signup_notification.rhtml create mode 100644 vendor/plugins/acts_as_authenticated/install.rb create mode 100644 vendor/plugins/gruff/MIT-LICENSE create mode 100644 vendor/plugins/gruff/README create mode 100644 vendor/plugins/gruff/Rakefile create mode 100644 vendor/plugins/gruff/about.yml create mode 100644 vendor/plugins/gruff/generators/gruff/gruff_generator.rb create mode 100644 vendor/plugins/gruff/generators/gruff/templates/controller.rb create mode 100644 vendor/plugins/gruff/generators/gruff/templates/functional_test.rb create mode 100644 vendor/plugins/gruff/lib/gruff.rb create mode 100644 vendor/plugins/gruff/lib/gruff/accumulator_bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/area.rb create mode 100644 vendor/plugins/gruff/lib/gruff/bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/bar_conversion.rb create mode 100644 vendor/plugins/gruff/lib/gruff/base.rb create mode 100644 vendor/plugins/gruff/lib/gruff/deprecated.rb create mode 100644 vendor/plugins/gruff/lib/gruff/line.rb create mode 100644 vendor/plugins/gruff/lib/gruff/mini/bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/mini/legend.rb create mode 100644 vendor/plugins/gruff/lib/gruff/mini/pie.rb create mode 100644 vendor/plugins/gruff/lib/gruff/mini/side_bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/net.rb create mode 100644 vendor/plugins/gruff/lib/gruff/photo_bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/pie.rb create mode 100644 vendor/plugins/gruff/lib/gruff/scene.rb create mode 100644 vendor/plugins/gruff/lib/gruff/side_bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/side_stacked_bar.rb create mode 100644 vendor/plugins/gruff/lib/gruff/spider.rb create mode 100644 vendor/plugins/gruff/lib/gruff/stacked_bar.rb diff --git a/README b/README index 341ef6d..8c02056 100644 --- a/README +++ b/README @@ -22,4 +22,35 @@ http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated is the best site for documentation regarding acts_as_authenticaed. Also, currently it only stores the user_id in the session, but i just found a guide to help me make it store the entire user object, so I'll do that while my battery -charges. \ No newline at end of file +charges. + +08/03/07 +Handy trick: use the command 'gem_server' from a shell to create a server at +http://localhost:8008 that is an easy to navigate locally-hosted website with +all the documentation on local gems you have in a easy to read format. + +jlsharps: I added the Gruff plug-in today, which is viewable under the folder +vender/plugins/gruff. I installed it directly using the Gruff plug-in and +included controller generate utility. The version 0.1.2, which doesn't seem to +be the latest version. I've looked into it and it see and it seems that the +latest version is 0.2.8. However, I wasn't sure how including a gem w/o a plugin +would function in end-game rails so I just what I used for now. If you guys +(mako of john) know how to do it, it'd probably be better to upgrade, but it +didn't seem like the best use of my time right now. I got the plug-in here: +http://topfunky.net/svn/plugins/gruff. You can get the gruff gem v 0.2.8 by +typing "sudo gem install gruff", I believe it's also hosted on RubyForge. + +I created the GraphsController for Gruff methods to use. In Pollarize I put them +in the ApplicationContorller file, so they would be accessible to all. While +that it also an option here, it would also mean there wouldn't be much room for +playing around because everything in the Application file has to be perfect or +it seems to throw Error Code 500 (basically everything breaks). The show() +is a sample sample provided with Gruff. + +Documentation is here:http://gruff.rubyforge.org/ Alternately, if you have the +gem installed, you can use the ri command, or the above mentioned gem_server. + +If you guys want more helpful stuff here, let me know. + + + diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb new file mode 100644 index 0000000..c13203b --- /dev/null +++ b/app/controllers/account_controller.rb @@ -0,0 +1,45 @@ +class AccountController < ApplicationController + layout 'hc' + + # Be sure to include AuthenticationSystem in Application Controller instead + include AuthenticatedSystem + # If you want "remember me" functionality, add this before_filter to Application Controller + before_filter :login_from_cookie + + # say something nice, you goof! something sweet. + def index + redirect_to(:action => 'signup') unless logged_in? || User.count > 0 + end + + def login + return unless request.post? + self.current_user = User.authenticate(params[:login], params[:password]) + if logged_in? + if params[:remember_me] == "1" + self.current_user.remember_me + cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } + end + redirect_back_or_default(:controller => '/account', :action => 'index') + flash[:notice] = "Logged in successfully" + end + end + + def signup + @user = User.new(params[:user]) + return unless request.post? + @user.save! + self.current_user = @user + redirect_back_or_default(:controller => '/account', :action => 'index') + flash[:notice] = "Thanks for signing up!" + rescue ActiveRecord::RecordInvalid + render :action => 'signup' + end + + def logout + self.current_user.forget_me if logged_in? + cookies.delete :auth_token + reset_session + flash[:notice] = "You have been logged out." + redirect_back_or_default(:controller => '/account', :action => 'index') + end +end diff --git a/app/controllers/application.rb b/app/controllers/application.rb index d92ab97..a5bb108 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -2,6 +2,7 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base + include AuthenticatedSystem helper :user model :user end diff --git a/app/controllers/graphs_controller.rb b/app/controllers/graphs_controller.rb new file mode 100644 index 0000000..c810853 --- /dev/null +++ b/app/controllers/graphs_controller.rb @@ -0,0 +1,87 @@ +class GraphsController < ApplicationController + + # To make caching easier, add a line like this to config/routes.rb: + # map.graph "graph/:action/:id/image.png", :controller => "graph" + # + # Then reference it with the named route: + # image_tag graph_url(:action => 'show', :id => 42) + + def show + g = Gruff::Line.new + # Uncomment to use your own theme or font + # See http://colourlovers.com or http://www.firewheeldesign.com/widgets/ for color ideas +# g.theme = { +# :colors => ['#663366', '#cccc99', '#cc6633', '#cc9966', '#99cc99'], +# :marker_color => 'white', +# :background_colors => ['black', '#333333'] +# } +# g.font = File.expand_path('artwork/fonts/VeraBd.ttf', RAILS_ROOT) + + g.title = "Gruff-o-Rama" + + g.data("Apples", [1, 2, 3, 4, 4, 3]) + g.data("Oranges", [4, 8, 7, 9, 8, 9]) + g.data("Watermelon", [2, 3, 1, 5, 6, 8]) + g.data("Peaches", [9, 9, 10, 8, 7, 9]) + + g.labels = {0 => '2004', 2 => '2005', 4 => '2006'} + + send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png") + end + + #The following section has been pasted directly fromworking pollarize graphs + #and hasn't been adopted to fit Selectricity yet + + def day_votes + @poll = Poll.find(params[:id]) + line = Gruff::Line.new + line.title = "Voters Per Day" + line.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf', RAILS_ROOT) + line.data("#{@poll.name}", voter_days["voters_per_day"] ) + line.labels = voter_days["days_hash"] + line.x_axis_label = "Date" + line.y_axis_label = "Number of Votes" + line.minimum_value = 0.0 + line.draw + send_data(line.to_blob, + :disposition => 'inline', + :type => 'image/png', + :filename => "dayvotes#{@poll.id}.png") + end + + def voter_days + @poll = Poll.find(params[:id]) + voter_times = Array.new + unique_days = Array.new + voters_per_day = Array.new + days_hash = Hash.new + + @poll.questions.each do |qstn| + qstn.votes.each do |vote| + voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time} + end + end + voter_times.sort! + #find all times in voter_times with the same date, and then concatenate + #that number onto votes_per_day + # + #doesn't work jsut yet + voter_times.each_with_index do |time, index| + count = 1 + unless unique_days.any? { |d1| d1.eql?(time.mon.to_s+"/"+time.day.to_s) } + unique_days << (time.mon.to_s+"/"+time.day.to_s) + count += (voter_times[(index+1)..-1].find_all {|t| t.mon == time.mon && t.day == time.day}).size + voters_per_day << count + end + end + + unique_days.each_with_index do |fmtdate, index| + days_hash[index] = fmtdate + end + return { "voters_per_day" => voters_per_day, "days_hash" => days_hash } + + end + #end copy/pasted section + + +end diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index 10815b3..61a4c69 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -10,6 +10,7 @@ class QuickvoteController < ApplicationController ############################################################# def create + breakpoint if params[:quickvote] @quickvote = QuickVote.new(params[:quickvote]) diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 3307d88..dd049f7 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -10,7 +10,7 @@ class SiteController < ApplicationController # check to see that we actually have record of them if User.find_all(["id = ?", session[:user].id]).length == 1 # if we have record of them, grab the list of their elections - session[:user] = User.find(session[:user].id) + session[:user] = User.find(session[:user]) @current_elections = session[:user].elections.sort do |a,b| b.enddate <=> a.enddate end diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb new file mode 100644 index 0000000..1b63056 --- /dev/null +++ b/app/helpers/account_helper.rb @@ -0,0 +1,2 @@ +module AccountHelper +end \ No newline at end of file diff --git a/app/models/account.rb b/app/models/account.rb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/account/index.rhtml b/app/views/account/index.rhtml new file mode 100644 index 0000000..d600d59 --- /dev/null +++ b/app/views/account/index.rhtml @@ -0,0 +1,56 @@ +

In the Caboose.

+ +<% content_for 'poem' do -%> +"Train delayed? and what's to say?" +"Blocked by last night's snow they say." +Seven hours or so to wait; +Well, that's pleasant! but there's the freight. +Depot loafing no one fancies, +We'll try the caboose and take our chances. + +Cool this morning in Watertown, +Somewhat frosty___mercury down; +Enter caboose___roaring fire, +With never an air-hole; heat so dire +That we shrivel and pant; we are roasted through- +Outside, thermometer thirty-two. + +We start with a jerk and suddenly stop. +"What's broke?" says one; another "What's up?", +"Oh, nothing," they answer, "That's our way: +You must stand the jerking, sorry to say." +We "stand it" with oft this painful thought: +Are our heads on yet, or are they not? + +Comrades in misery___let me see; +Girl like a statue opposite me; +Back and forth the others jostle___ +She never winks, nor moves a muscle; +See her, as she sits there now; +She's "well balanced," anyhow. + +Woman in trouble, tearful eyes, +Sits by the window, softly cries, +Pity___for griefs we may not know, +For breasts that ache, for tears that flow, +Though we know not why. Her eyelids red +Tell a sorrowful tale___some hope is dead. + +Man who follows the Golden Rule, +And lends his papers___a pocket full, +Has a blank book___once in a minute +Has an idea, and writes it in it. +Guess him? Yes, of course I can, +He's a___well___a newspaper man. + +Blue-eyed fairy, wrapped in fur; +Sweet young mother tending her. +Fairy thinks it's "awful far," +Wants to get off this "naughty car." +So do we, young golden-hair; +All this crowd are with you there! +<% end -%> + +<%= simple_format @content_for_poem %> + +

-- Ellen P. Allerton.

\ No newline at end of file diff --git a/app/views/account/login.rhtml b/app/views/account/login.rhtml new file mode 100644 index 0000000..a14ff99 --- /dev/null +++ b/app/views/account/login.rhtml @@ -0,0 +1,14 @@ +<% form_tag do -%> +


+<%= text_field_tag 'login' %>

+ +


+<%= password_field_tag 'password' %>

+ + + +

<%= submit_tag 'Log in' %>

+<% end -%> diff --git a/app/views/account/signup.rhtml b/app/views/account/signup.rhtml new file mode 100644 index 0000000..c0012a7 --- /dev/null +++ b/app/views/account/signup.rhtml @@ -0,0 +1,16 @@ +<%= error_messages_for :user %> +<% form_for :user do |f| -%> +


+<%= f.text_field :login %>

+ +


+<%= f.text_field :email %>

+ +


+<%= f.password_field :password %>

+ +


+<%= f.password_field :password_confirmation %>

+ +

<%= submit_tag 'Sign up' %>

+<% end -%> diff --git a/app/views/layouts/hc.rhtml b/app/views/layouts/hc.rhtml index 2408083..13b2e72 100755 --- a/app/views/layouts/hc.rhtml +++ b/app/views/layouts/hc.rhtml @@ -17,7 +17,7 @@