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
|
|
|
|
|
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
|
2014-02-12 18:51:25 +00:00
|
|
|
user = User.real_for_nickname!(params[:nickname])
|
2014-02-01 00:26:58 +00:00
|
|
|
render locals: { page: UserPagePresenter.build(user, current_user) }
|
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
|