OSDN Git Service

approve complated v031_mvbrowse
authoryasushiito <yas@pen-chan.jp>
Sat, 14 Jan 2012 04:51:26 +0000 (13:51 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 14 Jan 2012 04:51:26 +0000 (13:51 +0900)
app/controllers/system_controller.rb
app/models/admin.rb
app/views/layouts/system.html.erb
app/views/system/auth_token.html.erb
app/views/system/index.html.erb
app/views/system/waiting_list.html.erb

index d8276f8..69c0a93 100644 (file)
@@ -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
index b4a6f9c..abff349 100644 (file)
@@ -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\r
   
   def active_for_authentication?\r
-    super && (self.approve == 1)\r
+    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
index 8424da2..7aaa4b9 100644 (file)
@@ -31,7 +31,7 @@
 </div>
 <div>
   <%= 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%>
 </div>
 <%= yield %>
index 08e1178..9a8226b 100644 (file)
@@ -2,7 +2,14 @@
  <p class="notice"><%= notice %></p>
  <p class="alert"><%= alert %></p>
 </div>
+<div>
 authentication_token:<%= current_admin.authentication_token %>
+</div>
 
-<%= link_to 'generate token', :action => :create_token %>
-<%= link_to 'delete token', :action => :delete_token %>
+<div>
+  <% if current_admin.authentication_token %>
+    <%= link_to 'delete token', :action => :delete_token %>
+  <% else %>
+    <%= link_to 'generate token', :action => :create_token %>
+  <% end %>
+</div>
index 0543ff4..779d5f1 100644 (file)
@@ -6,6 +6,9 @@
   <%= link_to 'browse', :action => :browse %>
 </div>
 <div>
+  <%= link_to 'approve', :action => :waiting_list %>
+</div>
+<div>
   <%= link_to 'auth token', :action => :auth_token %>
 </div>
 <div>
index c6e8fe5..4bc9ec7 100644 (file)
@@ -1,15 +1,34 @@
-<h1>Listing artists</h1>
+<div>
+ <p class="notice"><%= notice %></p>
+ <p class="alert"><%= alert %></p>
+</div>
+<h1>Listing waiting admins</h1>
 
 <table>
   <tr>
-    <th>author</th>
-    <th></th>
+    <th>id</th>
+    <th>email</th>
+    <th>sign_in_count</th>
+    <th>current_sign_in_at</th>
+    <th>last_sign_in_at</th>
+    <th>current_sign_in_ip</th>
+    <th>last_sign_in_ip</th>
+    <th>created_at</th>
+    <th>updated_at</th>
   </tr>
 
-<% @artists.each do |artist| %>
+<% @waits.each do |admin| %>
   <tr>
-    <td><%= artist.author_id %></td>
-    <td><%= link_to 'Show', artist %></td>
+    <td><%= admin.id %></td>
+    <td><%= h(admin.email) %></td>
+    <td><%= admin.sign_in_count %></td>
+    <td><%= admin.current_sign_in_at %></td>
+    <td><%= admin.last_sign_in_at %></td>
+    <td><%= admin.current_sign_in_ip %></td>
+    <td><%= admin.last_sign_in_ip %></td>
+    <td><%= admin.created_at %></td>
+    <td><%= admin.updated_at %></td>
+    <td><%= link_to 'approve', :controller => '/system', :action => :approve, :id => admin.id %></td>
   </tr>
 <% end %>
 </table>