Skip to content

Commit

Permalink
Added some styles to application and added a last login column to use…
Browse files Browse the repository at this point in the history
…rs table
  • Loading branch information
Justin Camerer committed May 8, 2008
1 parent 4a9f3a6 commit 2e62315
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 14 deletions.
5 changes: 4 additions & 1 deletion app/controllers/session_controller.rb
Expand Up @@ -6,13 +6,16 @@ def new
def create
self.current_user = User.authenticate(params[:login], params[:password])
if logged_in?
current_user.update_attribute(:last_login_at, Time.now)

if params[:remember_me] == "1"
current_user.remember_me unless current_user.remember_token?
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
redirect_back_or_default('/')
flash[:notice] = "Logged in successfully"
else
flash[:error] = "Incorrect username or password"
render :action => 'new'
end
end
Expand All @@ -22,7 +25,7 @@ def destroy
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default('/')
redirect_to login_url
end

def logout
Expand Down
24 changes: 17 additions & 7 deletions app/views/layouts/application.html.haml
@@ -1,12 +1,22 @@
!!!
%html
%head
= stylesheet_link_tag "main"
%body
- if flash[:notice]
#notice
= "Notice: #{flash[:notice]}"
- if flash[:error]
#error
= "Error: #{flash[:error]}"
= yield :layout
%div#page
%ul#nav
%li= link_to "Home", "/"
%li= link_to "Users", users_url
- if current_user.nil?
%li= link_to "Login", login_url
- else
%li= link_to "Account", "/user"
%li= link_to "Logout", logout_url

- if flash[:notice]
#notice= "Notice: #{flash[:notice]}"
- if flash[:error]
#error= "Error: #{flash[:error]}"

= yield :layout

13 changes: 12 additions & 1 deletion app/views/user/show.html.haml
@@ -1,3 +1,14 @@

= link_to @user.login, :controller => 'user', :action => 'edit'
%h1= @user.login

%table
%tr
%td Email
%td= @user.email
%tr
%td Last Login
%td= @user.last_login_at


= link_to "Edit", :controller => 'user', :action => 'edit'

4 changes: 2 additions & 2 deletions config/boot.rb
Expand Up @@ -24,9 +24,8 @@ def vendor_rails?
File.exist?("#{RAILS_ROOT}/vendor/rails")
end

# FIXME : Ruby 1.9
def preinitialize
load(preinitializer_path) if File.exists?(preinitializer_path)
load(preinitializer_path) if File.exist?(preinitializer_path)
end

def preinitializer_path
Expand All @@ -44,6 +43,7 @@ def run
class VendorBoot < Boot
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
end
end

Expand Down
2 changes: 2 additions & 0 deletions config/environment.rb
Expand Up @@ -13,6 +13,8 @@
HOST = "http://localhost:3000/"

Rails::Initializer.run do |config|
config.gem 'haml', :version => '>= 1.9.0'

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Expand Up @@ -24,8 +24,8 @@
# XXX: Not sure if we actually HAVE to have 'user/login' or if
# 'sessions/new' will suffice, but this will make the acceptance
# test pass.
map.login 'user/login', :controller => 'session', :action => :new
map.logout 'user/logout', :controller => 'session', :action => :logout
map.login 'session/login', :controller => 'session', :action => :new
map.logout 'session/logout', :controller => 'session', :action => :logout

# XXX: Can take this out later
map.index '/', :controller => 'index', :action => :index
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20080508031419_add_last_login_at_to_users.rb
@@ -0,0 +1,9 @@
class AddLastLoginAtToUsers < ActiveRecord::Migration
def self.up
add_column :users, :last_login_at, :datetime
end

def self.down
remove_column :users, :last_login_at
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 5) do
ActiveRecord::Schema.define(:version => 20080508031419) do

create_table "roles", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -37,6 +37,7 @@
t.string "password_reset_code", :limit => 40
t.datetime "password_reset_code_expires_at"
t.boolean "suspended"
t.datetime "last_login_at"
end

end
35 changes: 35 additions & 0 deletions public/stylesheets/main.css
@@ -0,0 +1,35 @@

body {
font-size: 62.5%;
font-size: 1.0em;
}

div#page {
background-color: #eee;
width: 80%;
margin: 1em auto;
padding: 1em;
padding-top: 0;
}

ul#nav {
padding: 0;
margin: 0;
margin-left: 1em;
}

ul#nav li {
display: inline;
}

ul#nav li a {
padding: 7px 10px;
background-color: #80b9f2;
color: #fff;
text-decoration: none;
}

ul#nav li a:hover {
background-color: #68ace3;
}

0 comments on commit 2e62315

Please sign in to comment.