2012-03-04 22:07:45 +00:00
|
|
|
class UsersController < ApplicationController
|
2013-10-19 16:25:30 +00:00
|
|
|
|
2012-07-25 18:24:20 +00:00
|
|
|
PER_PAGE = 15
|
2012-03-04 22:07:45 +00:00
|
|
|
|
2012-04-09 12:42:22 +00:00
|
|
|
before_filter :ensure_authenticated!, :only => [:edit, :update]
|
|
|
|
|
2013-10-19 16:25:30 +00:00
|
|
|
def new
|
2013-10-19 18:59:39 +00:00
|
|
|
@user = build_user
|
2013-10-19 16:25:30 +00:00
|
|
|
end
|
|
|
|
|
2012-03-04 22:07:45 +00:00
|
|
|
def show
|
2013-05-27 20:04:31 +00:00
|
|
|
@user = User.find_by_nickname!(params[:nickname]).decorate
|
2012-04-29 08:47:33 +00:00
|
|
|
|
2012-04-06 21:01:38 +00:00
|
|
|
collection = @user.asciicasts.
|
2012-08-21 18:25:50 +00:00
|
|
|
includes(:user).
|
2012-03-08 14:00:10 +00:00
|
|
|
order("created_at DESC").
|
|
|
|
page(params[:page]).
|
|
|
|
per(PER_PAGE)
|
2012-04-06 21:01:38 +00:00
|
|
|
|
2013-05-27 20:04:31 +00:00
|
|
|
@asciicasts = PaginatingDecorator.new(collection)
|
2012-03-04 22:07:45 +00:00
|
|
|
end
|
2012-03-05 23:25:21 +00:00
|
|
|
|
|
|
|
def create
|
2013-10-19 18:59:39 +00:00
|
|
|
@user = build_user
|
2012-07-25 18:24:20 +00:00
|
|
|
|
2012-03-05 23:25:21 +00:00
|
|
|
if @user.save
|
2013-10-19 18:59:39 +00:00
|
|
|
store.delete(:new_user_email)
|
2012-03-05 23:25:21 +00:00
|
|
|
self.current_user = @user
|
2013-11-18 17:04:06 +00:00
|
|
|
redirect_to docs_path('getting-started'), notice: "Welcome to Asciinema!"
|
2012-03-05 23:25:21 +00:00
|
|
|
else
|
2013-10-19 18:59:39 +00:00
|
|
|
render :new, :status => 422
|
2012-03-05 23:25:21 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-10 13:58:10 +00:00
|
|
|
|
2012-04-09 12:42:22 +00:00
|
|
|
def edit
|
|
|
|
@user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-10-23 08:00:26 +00:00
|
|
|
@user = User.find(current_user.id)
|
|
|
|
|
|
|
|
if @user.update_attributes(params[:user])
|
|
|
|
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
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
def store
|
|
|
|
session
|
2012-03-10 13:58:10 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
def build_user
|
|
|
|
user = User.new(params[:user])
|
|
|
|
user.email = store[:new_user_email]
|
|
|
|
|
|
|
|
user
|
2012-03-10 13:58:10 +00:00
|
|
|
end
|
2013-10-19 16:25:30 +00:00
|
|
|
|
2012-03-04 22:07:45 +00:00
|
|
|
end
|