From: yasushiito Date: Sat, 14 Jan 2012 04:51:26 +0000 (+0900) Subject: approve complated X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=2f5f78baba91a15f9c7bbf20293bbdaf062daf2a approve complated --- diff --git a/app/controllers/system_controller.rb b/app/controllers/system_controller.rb index d8276f82..69c0a934 100644 --- a/app/controllers/system_controller.rb +++ b/app/controllers/system_controller.rb @@ -16,11 +16,37 @@ class SystemController < ApplicationController def auth_token end - def approbe + def create_token + @admin = current_admin + respond_to do |format| + if @admin.create_token + format.html { redirect_to({:action => :auth_token}, {:notice => 'admin token was successfully created.'}) } + else + format.html { render action: "auth_token" } + end + end + end + + def delete_token + current_admin.delete_token + respond_to do |format| + format.html { redirect_to :action => :auth_token} + end + end + + def approve + @admin = Admin.find params[:id] + respond_to do |format| + if @admin.apv + format.html { redirect_to({:action => :waiting_list}, {:notice => 'admin was successfully approved.'}) } + else + format.html { render action: "waiting_list" } + end + end end def waiting_list - @newadmins = Admin.find(:all, :conditions => ['activate = 0']) + @waits = Admin.find(:all, :conditions => ['approve = 0']) end def accept_admin diff --git a/app/models/admin.rb b/app/models/admin.rb index b4a6f9c8..abff349e 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -6,14 +6,34 @@ class Admin < ActiveRecord::Base # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me - before_save :ensure_authentication_token def active_for_authentication? - super && (self.approve == 1) + super && (self.approve == 1) end + def create_token + self.ensure_authentication_token + self.save + end + + def delete_token + self.authentication_token = nil + self.save + end + + def apv + self.approve = 1 + self.save + end + def self.start(email, passwd) - a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd + a = Admin.find(:first, :conditions => ['email = ?', email]) + if a + a.password = passwd + a.password_confirmation = passwd + else + a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd + end a.approve = 1 a.save! end diff --git a/app/views/layouts/system.html.erb b/app/views/layouts/system.html.erb index 8424da2d..7aaa4b99 100644 --- a/app/views/layouts/system.html.erb +++ b/app/views/layouts/system.html.erb @@ -31,7 +31,7 @@
<%= link_to "browse", :controller => '/system', :action => :browse%> - <%= link_to "approbe", :controller => '/system', :action => :approbe%> + <%= link_to "approve", :controller => '/system', :action => :waiting_list%> <%= link_to "token", :controller => '/system', :action => :auth_token%>
<%= yield %> diff --git a/app/views/system/auth_token.html.erb b/app/views/system/auth_token.html.erb index 08e1178b..9a8226b1 100644 --- a/app/views/system/auth_token.html.erb +++ b/app/views/system/auth_token.html.erb @@ -2,7 +2,14 @@

<%= notice %>

<%= alert %>

+
authentication_token:<%= current_admin.authentication_token %> +
-<%= link_to 'generate token', :action => :create_token %> -<%= link_to 'delete token', :action => :delete_token %> +
+ <% if current_admin.authentication_token %> + <%= link_to 'delete token', :action => :delete_token %> + <% else %> + <%= link_to 'generate token', :action => :create_token %> + <% end %> +
diff --git a/app/views/system/index.html.erb b/app/views/system/index.html.erb index 0543ff42..779d5f1e 100644 --- a/app/views/system/index.html.erb +++ b/app/views/system/index.html.erb @@ -6,6 +6,9 @@ <%= link_to 'browse', :action => :browse %>
+ <%= link_to 'approve', :action => :waiting_list %> +
+
<%= link_to 'auth token', :action => :auth_token %>
diff --git a/app/views/system/waiting_list.html.erb b/app/views/system/waiting_list.html.erb index c6e8fe53..4bc9ec7e 100644 --- a/app/views/system/waiting_list.html.erb +++ b/app/views/system/waiting_list.html.erb @@ -1,15 +1,34 @@ -

Listing artists

+
+

<%= notice %>

+

<%= alert %>

+
+

Listing waiting admins

- - + + + + + + + + + -<% @artists.each do |artist| %> +<% @waits.each do |admin| %> - - + + + + + + + + + + <% end %>
authoridemailsign_in_countcurrent_sign_in_atlast_sign_in_atcurrent_sign_in_iplast_sign_in_ipcreated_atupdated_at
<%= artist.author_id %><%= link_to 'Show', artist %><%= admin.id %><%= h(admin.email) %><%= admin.sign_in_count %><%= admin.current_sign_in_at %><%= admin.last_sign_in_at %><%= admin.current_sign_in_ip %><%= admin.last_sign_in_ip %><%= admin.created_at %><%= admin.updated_at %><%= link_to 'approve', :controller => '/system', :action => :approve, :id => admin.id %>