Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lesson 13 - authentication with devise
- Loading branch information
1 parent
cc9af89
commit 761d016
Showing
27 changed files
with
576 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ end | |
gem 'paperclip' | ||
gem 'RedCloth' | ||
gem 'jquery-rails' | ||
gem 'menu_builder' | ||
gem 'menu_builder' | ||
gem 'devise' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class Admin::BaseController < ApplicationController | ||
|
||
layout 'admin' | ||
before_filter :authenticate_user! | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Admin::PasswordsController < Devise::PasswordsController | ||
layout "admin" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Admin::SessionsController < Devise::SessionsController | ||
layout 'admin' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class Admin::UsersController < Admin::BaseController | ||
|
||
menu_item :users | ||
|
||
def index | ||
@users = User.all | ||
respond_with @users | ||
end | ||
|
||
def new | ||
@user = User.new | ||
respond_with @user | ||
end | ||
|
||
def edit | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
def create | ||
@user = User.new(params[:user]) | ||
flash[:notice] = 'User was successfully created.' if @user.save | ||
respond_with @user, :location => [:admin, :users] | ||
end | ||
|
||
def update | ||
@user = User.find(params[:id]) | ||
flash[:notice] = 'User was successfully updated.' if @user.update_attributes(params[:user]) | ||
respond_with @user, :location => [:admin, :users] | ||
end | ||
|
||
def destroy | ||
@user = User.find(params[:id]) | ||
@user.destroy | ||
respond_with @user, :location => [:admin, :users] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= form_for [:admin, @user] do |f| %> | ||
<%= error_messages_for @user %> | ||
|
||
<p><%= f.text_field :full_name, :placeholder => "full name" %></p> | ||
<p><%= f.text_field :email, :placeholder => "email" %></p> | ||
<p><%= f.password_field :password, :placeholder => "password" %></p> | ||
<p><%= f.password_field :password_confirmation, :placeholder => "password confirmation" %></p> | ||
|
||
<hr class="thick" /> | ||
|
||
<p> | ||
<%= f.submit :class => "button" %> | ||
or <%= link_to "cancel", admin_users_path %> | ||
</p> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h2>Edit user</h2> | ||
|
||
<%= render 'form' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h2>Users</h2> | ||
|
||
<ul class="list"> | ||
<% @users.each do |user| %> | ||
<%= content_tag_for :li, user, :class => cycle(:odd, :even) do %> | ||
<%= link_to "#{user.full_name} (#{user.email})", [:admin, user] %> | ||
|
||
<div class="right"> | ||
<%= link_to_edit [:edit, :admin, user] %> | ||
<%= link_to_destroy [:admin, user] unless current_user == user %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</ul> | ||
|
||
<hr class="thick" /> | ||
|
||
<div class="bar"> | ||
<div class="right"> | ||
<%= link_to 'New user', new_admin_user_path, :class => "button" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h2>New user</h2> | ||
|
||
<%= render 'form' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<h2>Change your password</h2> | ||
|
||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %> | ||
<%= devise_error_messages! %> | ||
<%= f.hidden_field :reset_password_token %> | ||
|
||
<p><%= f.password_field :password, :placeholder => "password" %></p> | ||
<p><%= f.password_field :password_confirmation, :placeholder => "password confirmation" %></p> | ||
|
||
<hr class="thick" /> | ||
|
||
<p> | ||
<%= f.submit "Change my password", :class => "button" %> | ||
or <%= link_to "cancel", new_user_session_path %> | ||
</p> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h2>Forgot your password?</h2> | ||
|
||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %> | ||
<%= devise_error_messages! %> | ||
|
||
<p> | ||
<%= f.text_field :email, :placeholder => "email" %> | ||
</p> | ||
|
||
<hr class="thick" /> | ||
|
||
<p> | ||
<%= f.submit "Send reset instructions", :class => "button" %> | ||
or <%= link_to "cancel", new_user_session_path %> | ||
</p> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h2>Sign in</h2> | ||
|
||
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> | ||
|
||
<p><%= f.text_field :email, :placeholder => ta(User, :email) %></p> | ||
<p><%= f.password_field :password, :placeholder => ta(User, :password) %></p> | ||
|
||
<% if devise_mapping.rememberable? -%> | ||
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p> | ||
<% end -%> | ||
|
||
<hr class="thick" /> | ||
|
||
<p> | ||
<%= f.submit "Sign in", :class => "button" %> | ||
or <%= link_to "forgot your password?", new_password_path(resource_name) %> | ||
</p> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
atom_feed do |feed| | ||
feed.title "Rails feed" | ||
feed.updated @posts.last.try(:updated_at) | ||
|
||
@posts.each do |post| | ||
feed.entry post do |entry| | ||
|
||
entry.title post.title | ||
entry.content textilize(post.body), :type => 'html' | ||
entry.updated post.updated_at | ||
|
||
entry.author do |author| | ||
author.name post.author_full_name | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.