2012-09-23 02:39:12 +00:00
|
|
|
class UsersController < ApplicationController
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
before_filter :require_user, only: [:edit, :update, :updatemetacodes]
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2014-01-29 04:53:13 +00:00
|
|
|
respond_to :html, :json
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
# GET /users/1.json
|
|
|
|
def show
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
|
|
|
render json: @user
|
2014-08-12 22:14:04 +00:00
|
|
|
end
|
2014-07-27 19:57:35 +00:00
|
|
|
|
2014-08-12 22:14:04 +00:00
|
|
|
# GET /users/:id/edit
|
2012-09-23 02:39:12 +00:00
|
|
|
def edit
|
|
|
|
@user = current_user
|
|
|
|
|
|
|
|
respond_with(@user)
|
|
|
|
end
|
|
|
|
|
2014-08-12 22:14:04 +00:00
|
|
|
# PUT /users/:id
|
2012-09-23 02:39:12 +00:00
|
|
|
def update
|
|
|
|
@user = current_user
|
2014-05-15 22:28:30 +00:00
|
|
|
|
2014-10-22 00:31:59 +00:00
|
|
|
if params[:user][:password] == "" && params[:user][:password_confirmation] == ""
|
|
|
|
# not trying to change the password
|
|
|
|
if @user.update_attributes(params[:user])
|
|
|
|
if params[:remove_image] == "1"
|
|
|
|
@user.image = nil
|
|
|
|
end
|
|
|
|
@user.save
|
|
|
|
sign_in(@user, :bypass => true)
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to root_url, notice: "Account updated!" }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sign_in(@user, :bypass => true)
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# trying to change the password
|
|
|
|
correct_pass = @user.valid_password?(params[:current_password])
|
|
|
|
|
|
|
|
if correct_pass && @user.update_attributes(params[:user])
|
|
|
|
if params[:remove_image] == "1"
|
|
|
|
@user.image = nil
|
|
|
|
end
|
|
|
|
@user.save
|
|
|
|
sign_in(@user, :bypass => true)
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to root_url, notice: "Account updated!" }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
if correct_pass
|
|
|
|
u = User.find(@user.id)
|
|
|
|
sign_in(u, :bypass => true)
|
|
|
|
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
|
|
|
|
else
|
|
|
|
sign_in(@user, :bypass => true)
|
|
|
|
format.html { redirect_to edit_user_path(@user), notice: "Incorrect current password" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|
|
|
|
end
|
2014-06-04 19:24:16 +00:00
|
|
|
|
|
|
|
# PUT /user/updatemetacodes
|
|
|
|
def updatemetacodes
|
|
|
|
@user = current_user
|
|
|
|
|
|
|
|
@m = params[:metacodes][:value]
|
|
|
|
@user.settings.metacodes=@m.split(',')
|
|
|
|
|
|
|
|
@user.save
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: @user }
|
|
|
|
end
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
|
|
|
|
end
|