Permalink
Browse files

That whole devise view generation thing was a confusing red herring. …

…Did it myself...
  • Loading branch information...
1 parent 21c9895 commit a9a8f6fba066f019a30947f614d93381b0a6b8fa August committed with August Fietkau Sep 22, 2011
View
65 app/controllers/users_controller.rb
@@ -0,0 +1,65 @@
+class UsersController < ApplicationController
+ respond_to :html, :xml, :json
+ before_filter :authenticate_user!
+
+ # GET /users
+ # GET /users.xml
+ def index
+ @users = User.order('name ASC').all
+ respond_with(@users)
+ end
+
+ # GET /users/1
+ # GET /users/1.xml
+ def show
+ if !current_user && params[:id] != current_user.id && current_user.is_admin == false
+ raise "You are not authorized to access this function"
+ end
+ @user = User.find(params[:id])
+ respond_with(@user)
+ end
+
+ # GET /users/new
+ # GET /users/new.xml
+ def new
+ @user = User.new
+ respond_with(@user)
+ end
+
+ # GET /users/1/edit
+ def edit
+ if params[:id] != current_user.id && current_user.is_admin == false
+ raise "You are not authorized to access this function"
+ end
+ @user = current_user
+ end
+
+ # POST /users
+ # POST /users.xml
+ def create
+ @user = User.new(params[:user])
+ flash[:notice] = "User successfully created" if @user.save
+ respond_with(@user)
+ end
+
+ # PUT /users/1
+ # PUT /users/1.xml
+ def update
+ if params[:id] != current_user.id && current_user.is_admin == false
+ raise "You are not authorized to access this function"
+ end
+ @user = current_user
+ @user.update_attributes(params[:user])
+ respond_with(@user)
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.xml
+ def destroy
+ if params[:id] != current_user.id && current_user.is_admin == false
+ raise "You are not authorized to access this function"
+ end
+ @user = User.find(params[:id]).destroy
+ respond_with(@user)
+ end
+end
View
2 app/views/elements/_footer.html.erb
@@ -13,7 +13,7 @@
<div style="float:right; width:28%; text-align:right;">
<% if user_signed_in? %>
<p class="small">Welcome <%= current_user.name %>!</p>
- <p class="small"><%#= link_to "Edit Account", edit_user_path(current_user) %> | <%= link_to 'Logout', destroy_user_session_path, :confirm => 'Are you sure?' %></p>
+ <p class="small"><%= link_to "Edit Account", edit_user_path(current_user) %> | <%= link_to 'Logout', destroy_user_session_path, :confirm => 'Are you sure?' %></p>
<% else %>
<p class="small"><%= link_to 'Site Login', new_user_session_path %></p>
<% end %>
View
27 app/views/users/_form.html.erb
@@ -0,0 +1,27 @@
+<%= form_for(@user) do |f| %>
+ <%= f.error_messages %>
+
+ <div class="field">
+ <%= f.label :is_admin %><br />
+ <%= f.check_box :is_admin %>
+ </div>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
12 app/views/users/confirmations/new.html.erb
@@ -1,12 +0,0 @@
-<h2>Resend confirmation instructions</h2>
-
-<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.submit "Resend confirmation instructions" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
View
6 app/views/users/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
View
11 app/views/users/index.html.erb
@@ -0,0 +1,11 @@
+<hgroup>
+ <h1>Users List</h1>
+ <% if current_user %>
+ <h2><%= link_to "Create New User", new_user_path %></h2>
+ <% end %>
+</hgroup>
+<ul>
+ <% @users.each do |user| %>
+ <li><%= user.name %> <% if current_user %>(<%= link_to "Edit", edit_user_path(user) %>, <%= link_to "Delete", user, :confirm => 'Are you sure you want to delete this user?', :method => :delete %>)<% end %></li>
+ <% end %>
+</ul>
View
5 app/views/users/mailer/confirmation_instructions.html.erb
@@ -1,5 +0,0 @@
-<p>Welcome <%= @resource.email %>!</p>
-
-<p>You can confirm your account through the link below:</p>
-
-<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
View
8 app/views/users/mailer/reset_password_instructions.html.erb
@@ -1,8 +0,0 @@
-<p>Hello <%= @resource.email %>!</p>
-
-<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
-
-<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
-
-<p>If you didn't request this, please ignore this email.</p>
-<p>Your password won't change until you access the link above and create a new one.</p>
View
7 app/views/users/mailer/unlock_instructions.html.erb
@@ -1,7 +0,0 @@
-<p>Hello <%= @resource.email %>!</p>
-
-<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
-
-<p>Click the link below to unlock your account:</p>
-
-<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
View
5 app/views/users/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
View
16 app/views/users/passwords/edit.html.erb
@@ -1,16 +0,0 @@
-<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 %>
-
- <div><%= f.label :password, "New password" %><br />
- <%= f.password_field :password %></div>
-
- <div><%= f.label :password_confirmation, "Confirm new password" %><br />
- <%= f.password_field :password_confirmation %></div>
-
- <div><%= f.submit "Change my password" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
View
12 app/views/users/passwords/new.html.erb
@@ -1,12 +0,0 @@
-<h2>Forgot your password?</h2>
-
-<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.submit "Send me reset password instructions" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
View
25 app/views/users/registrations/edit.html.erb
@@ -1,25 +0,0 @@
-<h2>Edit <%= resource_name.to_s.humanize %></h2>
-
-<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
- <%= f.password_field :password %></div>
-
- <div><%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %></div>
-
- <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
- <%= f.password_field :current_password %></div>
-
- <div><%= f.submit "Update" %></div>
-<% end %>
-
-<h3>Cancel my account</h3>
-
-<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
-
-<%= link_to "Back", :back %>
View
18 app/views/users/registrations/new.html.erb
@@ -1,18 +0,0 @@
-<h2>Sign up</h2>
-
-<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.label :password %><br />
- <%= f.password_field :password %></div>
-
- <div><%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %></div>
-
- <div><%= f.submit "Sign up" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
View
17 app/views/users/sessions/new.html.erb
@@ -1,17 +0,0 @@
-<h2>Sign in</h2>
-
-<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.label :password %><br />
- <%= f.password_field :password %></div>
-
- <% if devise_mapping.rememberable? -%>
- <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
- <% end -%>
-
- <div><%= f.submit "Sign in" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
View
25 app/views/users/shared/_links.erb
@@ -1,25 +0,0 @@
-<%- if controller_name != 'sessions' %>
- <%= link_to "Sign in", new_session_path(resource_name) %><br />
-<% end -%>
-
-<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
- <%= link_to "Sign up", new_registration_path(resource_name) %><br />
-<% end -%>
-
-<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
- <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
-<% end -%>
-
-<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
- <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
-<% end -%>
-
-<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
- <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
-<% end -%>
-
-<%- if devise_mapping.omniauthable? %>
- <%- resource_class.omniauth_providers.each do |provider| %>
- <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
- <% end -%>
-<% end -%>
View
12 app/views/users/show.html.erb
@@ -0,0 +1,12 @@
+ <b>Name:</b>
+ <%= @user.name %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
View
12 app/views/users/unlocks/new.html.erb
@@ -1,12 +0,0 @@
-<h2>Resend unlock instructions</h2>
-
-<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.submit "Resend unlock instructions" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
View
5 config/routes.rb
@@ -1,5 +1,6 @@
ConcOrg2::Application.routes.draw do
devise_for :users
+ resources :users
root :to => "frontpage#index"
@@ -39,10 +40,6 @@
end
end
- resources :user_sessions
-
- resources :users
-
resources :pages do
resources :columns
end

0 comments on commit a9a8f6f

Please sign in to comment.