asciinema.org/app/controllers/users_controller.rb

56 lines
1002 B
Ruby
Raw Normal View History

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]
attr_reader :user
2013-10-19 16:25:30 +00:00
def new
@user = build_user
2013-10-19 16:25:30 +00:00
end
2012-03-04 22:07:45 +00:00
def show
user = User.find_by_nickname!(params[:nickname])
render locals: { page: UserPresenter.build(user, current_user) }
2012-03-04 22:07:45 +00:00
end
2012-03-05 23:25:21 +00:00
def create
@user = build_user
2012-07-25 18:24:20 +00:00
2012-03-05 23:25:21 +00:00
if @user.save
store.delete(:new_user_email)
2012-03-05 23:25:21 +00:00
self.current_user = @user
redirect_to docs_path('getting-started'), notice: "Welcome to Asciinema!"
2012-03-05 23:25:21 +00:00
else
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
def store
session
2012-03-10 13:58:10 +00:00
end
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