work on controllers/views started
This commit is contained in:
@@ -1,2 +1,7 @@
|
||||
class Admin::UsersController < ApplicationController
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
before_filter :set_current_user
|
||||
before_filter :initialize_cookies
|
||||
layout "default"
|
||||
|
||||
protected
|
||||
def access_denied
|
||||
@@ -25,25 +26,15 @@ protected
|
||||
end
|
||||
|
||||
def set_current_user
|
||||
if @current_user == nil && session[:user_id]
|
||||
if session[:user_id]
|
||||
@current_user = User.find_by_id(session[:user_id])
|
||||
end
|
||||
|
||||
if @current_user == nil && params[:user]
|
||||
@current_user = User.authenticate(params[:user][:name], params[:user][:password])
|
||||
end
|
||||
|
||||
if @current_user == nil && params[:api]
|
||||
@current_user = User.authenticate(params[:api][:key], params[:api][:hash])
|
||||
end
|
||||
|
||||
if @current_user
|
||||
if @current_user.is_banned? && @current_user.ban && @current_user.ban.expires_at < Time.now
|
||||
@current_user.update_attribute(:is_banned, false)
|
||||
Ban.destroy_all("user_id = #{@current_user.id}")
|
||||
end
|
||||
|
||||
session[:user_id] = @current_user.id
|
||||
else
|
||||
@current_user = AnonymousUser.new
|
||||
end
|
||||
|
||||
@@ -1,16 +1,39 @@
|
||||
class PostsController < ApplicationController
|
||||
before_filter :member_only, :except => [:show, :index]
|
||||
after_filter :save_recent_tags, :only => [:create, :update]
|
||||
after_filter :save_recent_tags, :only => [:update]
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@post_set = PostSet.new(params[:tags], params[:page], @current_user, params[:before_id])
|
||||
respond_with(@post_set) do |fmt|
|
||||
fmt.js
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@post = Post.find(params[:id])
|
||||
respond_with(@post)
|
||||
end
|
||||
|
||||
def update
|
||||
@post = Post.find(params[:id])
|
||||
@post.update_attributes(params[:post].merge(:updater_id => @current_user.id, :updater_ip_addr => request.remote_ip))
|
||||
respond_with(@post)
|
||||
end
|
||||
|
||||
def revert
|
||||
@post = Post.find(params[:id])
|
||||
@version = PostVersion.find(params[:version_id])
|
||||
@post.revert_to!(@version, @current_user.id, request.remote_ip)
|
||||
respond_width(@post)
|
||||
end
|
||||
|
||||
private
|
||||
def save_recent_tags
|
||||
if params[:tags] || (params[:post] && params[:post][:tags])
|
||||
tags = Tag.scan_tags(params[:tags] || params[:post][:tags])
|
||||
tags = TagAlias.to_aliased(tags) + Tag.scan_tags(session[:recent_tags])
|
||||
session[:recent_tags] = tags.uniq.slice(0, 40).join(" ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
class SessionsController < ApplicationController
|
||||
before_filter :member_only, :only => [:destroy]
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
if User.authenticate(params[:name], params[:password])
|
||||
@user = User.find_by_name(params[:name])
|
||||
session[:user_id] = @user.id
|
||||
redirect_to(params[:url] || posts_path, :notice => "You have logged in")
|
||||
else
|
||||
render :action => "edit", :flash => "Password was incorrect"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
session[:user_id] = nil
|
||||
redirect_to(posts_path, :notice => "You have logged out")
|
||||
end
|
||||
end
|
||||
|
||||
10
app/controllers/user_maintenance_controller.rb
Normal file
10
app/controllers/user_maintenance_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class UserMaintenanceController < ApplicationController
|
||||
def delete_account
|
||||
end
|
||||
|
||||
def login_reminder
|
||||
end
|
||||
|
||||
def reset_password
|
||||
end
|
||||
end
|
||||
@@ -1,17 +1,28 @@
|
||||
class UsersController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
unless @current_user.is_admin?
|
||||
@user = @current_user
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(params[:user])
|
||||
flash[:notice] = "You have succesfully created a new account." if @user.save
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
Reference in New Issue
Block a user