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
|
|
|
|
|
2012-12-16 20:00:43 +00:00
|
|
|
autocomplete :user, :name, :full => true
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
# GET /user/new
|
|
|
|
def new
|
2013-07-10 18:02:38 +00:00
|
|
|
|
|
|
|
flash[:notice] = "Account creation is temporarily disabled."
|
|
|
|
redirect_to root_url
|
|
|
|
return
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
@user = User.new
|
|
|
|
|
|
|
|
respond_with(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /user/edit
|
|
|
|
def edit
|
|
|
|
@user = current_user
|
|
|
|
|
|
|
|
respond_with(@user)
|
|
|
|
end
|
|
|
|
|
2013-01-18 22:08:06 +00:00
|
|
|
# GET /user/:id
|
2012-09-23 02:39:12 +00:00
|
|
|
def show
|
2012-10-26 10:59:45 +00:00
|
|
|
@user = User.find(params[:id])
|
2013-01-18 22:08:06 +00:00
|
|
|
@topics = Topic.visibleToUser(@current, @user).sort! { |a,b| b.created_at <=> a.created_at }
|
|
|
|
@topics = @topics.slice(0,3)
|
|
|
|
@synapses = Synapse.visibleToUser(@current, @user).sort! { |a,b| b.created_at <=> a.created_at }
|
|
|
|
@synapses = @synapses.slice(0,3)
|
|
|
|
@maps = Map.visibleToUser(@current, @user).sort! { |a,b| b.created_at <=> a.created_at }
|
|
|
|
@maps = @maps.slice(0,3)
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2013-01-08 00:57:04 +00:00
|
|
|
respond_with(@user, @topics, @synapses, @maps)
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /user
|
|
|
|
def create
|
2013-07-10 18:02:38 +00:00
|
|
|
|
|
|
|
# update this code
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
@session = Session.create(params[:user])
|
|
|
|
|
|
|
|
redirect_to(root_url) and return if @session.valid?
|
|
|
|
|
|
|
|
@user = User.create(params[:user])
|
|
|
|
|
2013-02-04 02:12:15 +00:00
|
|
|
#generate a random 8 letter/digit code that they can use to invite people
|
|
|
|
@user.code = rand(36**8).to_s(36)
|
2012-09-23 02:39:12 +00:00
|
|
|
@user.save
|
2012-10-29 17:52:29 +00:00
|
|
|
|
2013-02-04 02:12:15 +00:00
|
|
|
# direct them straight to the metamaps manual topic 'Click Me'
|
|
|
|
@topic = Topic.exists?(260)
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2013-02-04 02:12:15 +00:00
|
|
|
if @topic
|
|
|
|
respond_with(@user, location: topic_url(260)) do |format|
|
2012-11-03 17:45:08 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_with(@user, location: root_url) do |format|
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /user
|
|
|
|
def update
|
|
|
|
@user = current_user
|
|
|
|
@user.attributes = params[:user]
|
|
|
|
|
2013-01-26 01:49:40 +00:00
|
|
|
@m = params[:metacodes][:value]
|
|
|
|
@user.settings.metacodes=@m.split(',')
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
@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
|