2012-09-23 02:39:12 +00:00
|
|
|
class UsersController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :require_no_user, only: [:new, :create]
|
2012-10-26 10:04:52 +00:00
|
|
|
before_filter :require_user, only: [:edit, :update]
|
2012-09-23 02:39:12 +00:00
|
|
|
|
|
|
|
respond_to :html, :json
|
|
|
|
|
|
|
|
# GET /user/new
|
|
|
|
def new
|
|
|
|
@user = User.new
|
|
|
|
|
|
|
|
respond_with(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /user/edit
|
|
|
|
def edit
|
|
|
|
@user = current_user
|
|
|
|
|
|
|
|
respond_with(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /user
|
|
|
|
def show
|
2012-10-26 10:59:45 +00:00
|
|
|
@user = User.find(params[:id])
|
2012-09-23 02:39:12 +00:00
|
|
|
|
|
|
|
respond_with(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /user
|
|
|
|
def create
|
|
|
|
@session = Session.create(params[:user])
|
|
|
|
|
|
|
|
redirect_to(root_url) and return if @session.valid?
|
|
|
|
|
|
|
|
@user = User.create(params[:user])
|
|
|
|
|
|
|
|
@user.save
|
|
|
|
|
2012-10-26 10:04:52 +00:00
|
|
|
respond_with(@user, location: root_url) do |format|
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /user
|
|
|
|
def update
|
|
|
|
@user = current_user
|
|
|
|
@user.attributes = params[:user]
|
|
|
|
|
|
|
|
@user.save
|
|
|
|
|
2012-10-26 10:04:52 +00:00
|
|
|
respond_with(@user, location: user_url(@user)) do |format|
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|