2012-03-04 22:07:45 +00:00
|
|
|
class UsersController < ApplicationController
|
2013-10-19 16:25:30 +00:00
|
|
|
|
2012-04-09 12:42:22 +00:00
|
|
|
before_filter :ensure_authenticated!, :only => [:edit, :update]
|
|
|
|
|
2014-02-01 00:16:28 +00:00
|
|
|
attr_reader :user
|
|
|
|
|
2012-03-04 22:07:45 +00:00
|
|
|
def show
|
2014-10-05 17:53:00 +00:00
|
|
|
if params[:username]
|
|
|
|
user = User.for_username!(params[:username])
|
|
|
|
else
|
|
|
|
user = User.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2014-06-25 15:35:13 +00:00
|
|
|
render locals: { page: UserPagePresenter.build(user, current_user, params[:page]) }
|
2012-03-04 22:07:45 +00:00
|
|
|
end
|
2012-03-05 23:25:21 +00:00
|
|
|
|
2012-04-09 12:42:22 +00:00
|
|
|
def edit
|
|
|
|
@user = current_user
|
2014-07-05 12:59:42 +00:00
|
|
|
authorize @user
|
2012-04-09 12:42:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-04-12 10:39:59 +00:00
|
|
|
@user = User.find(current_user.id)
|
2014-07-05 12:59:42 +00:00
|
|
|
authorize @user
|
2013-10-23 08:00:26 +00:00
|
|
|
|
2014-02-12 19:22:20 +00:00
|
|
|
if @user.update_attributes(update_params)
|
2013-10-23 08:00:26 +00:00
|
|
|
redirect_to profile_path(@user), notice: 'Account settings saved.'
|
|
|
|
else
|
|
|
|
render :edit, status: 422
|
|
|
|
end
|
2012-04-09 12:42:22 +00:00
|
|
|
end
|
|
|
|
|
2012-03-10 13:58:10 +00:00
|
|
|
private
|
|
|
|
|
2014-02-12 19:22:20 +00:00
|
|
|
def update_params
|
2014-06-30 21:26:25 +00:00
|
|
|
params.require(:user).permit(:username, :name, :email, :theme_name)
|
2014-02-12 19:22:20 +00:00
|
|
|
end
|
|
|
|
|
2012-03-04 22:07:45 +00:00
|
|
|
end
|