added user controller and views, started to customize devise controllers

This commit is contained in:
Thomas Buchöster
2011-06-10 02:16:30 +02:00
parent 61de00cad7
commit 028ef78436
13 changed files with 90 additions and 7 deletions
@@ -0,0 +1,31 @@
class DeviseAuth::RegistrationsController < Devise::RegistrationsController
def new
resource = build_resource({})
respond_with_navigational(resource) { render :partial => "devise/registrations/new" }
end
def edit
render :partial => "devise/registrations/edit"
end
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
redirect_to user_path(resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s if is_navigational_format?
expire_session_data_after_sign_in!
redirect_to user_path(resource)
end
else
clean_up_passwords(resource)
respond_with_navigational(resource) { render :partial => "devise/registrations/new" }
end
end
end
@@ -0,0 +1,15 @@
class DeviseAuth::SessionsController < Devise::SessionsController
def new
resource = build_resource
clean_up_passwords(resource)
respond_with_navigational(resource, stub_options(resource)){ render :partial => "devise/sessions/new" }
end
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
redirect_to "/#!/home", :partial => "devise/registrations/new"
end
end
+8
View File
@@ -0,0 +1,8 @@
class UsersController < ApplicationController
def show
@user = User.find params[:id]
puts @user.inspect
render :partial => "show", :locals => { :user => @user }
end
end
+8
View File
@@ -0,0 +1,8 @@
module UsersHelper
def validate_avatar_url url
return url if url.present? and FileTest.exists? url
"examples/user-big.jpg"
end
end
+1
View File
@@ -1,3 +1,4 @@
class Playlist < ActiveRecord::Base
has_many :tracks, :through => :playlists_tracks
belongs_to :user
end
+4 -3
View File
@@ -1,9 +1,10 @@
class User < ActiveRecord::Base
has_and_belongs_to_many :artists
has_many :playlist
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
# :token_authenticatable, :encryptable, :confirmable, :lockable, :recoverable, :timeoutable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
:rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
@@ -35,4 +36,4 @@ class User < ActiveRecord::Base
end
end
end
end
+2 -2
View File
@@ -1,9 +1,9 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<%= link_to "Sign in", "/#!/login" %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<%= link_to "Sign up", "/#!/register" %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
+2 -2
View File
@@ -27,7 +27,7 @@
%li.active= link_to "home", "/#!/home"
%li= link_to "charts", "/#!/charts"
%li= link_to "about", "#"
%li= link_to "register", "#"
%li= link_to "register", "/#!/register"
%li.search
= form_tag '/search', :method => 'get', :id => "search_form", :remote=>true do
= text_field_tag 'q', params[:q], :class => "text", :placeholder => "Search here ..."
@@ -74,4 +74,4 @@
%li
%h3
%div= "Firework"
%span= "Katie Perry"
%span= "Katie Perry"
+2
View File
@@ -0,0 +1,2 @@
%h1 Users#edit
%p Find me in app/views/users/edit.html.haml
+17
View File
@@ -0,0 +1,17 @@
#user_left
=image_tag validate_avatar_url(user.avatar.url), :class => "picture"
.information
%h1= user.username
%ul.nav
%li=image_tag "icons/artist-info.png"
%li=image_tag "icons/artist-links.png"
%ul.con
%li="#{user.playcount} Plays"
%li="#{user.playlist.count} Playlists"
.tabs.tabs_js.w02
%ul.nav
%li profile
%li playlist
.content
%div SONGS
%div ALBUMS