asciinema.org/app/controllers/users_controller.rb

64 lines
1.1 KiB
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
2014-02-12 19:51:01 +00:00
user = User.real_for_username!(params[:username])
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
@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
@user = User.find(current_user.id)
2013-10-23 08:00:26 +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
def store
session
2012-03-10 13:58:10 +00:00
end
def build_user
user = User.new(create_params)
user.email = store[:new_user_email]
user
2012-03-10 13:58:10 +00:00
end
2013-10-19 16:25:30 +00:00
def create_params
2014-02-12 19:51:01 +00:00
params.fetch(:user, {}).permit(:username, :name)
end
def update_params
2014-02-12 19:51:01 +00:00
params.require(:user).permit(:username, :name, :email)
end
2012-03-04 22:07:45 +00:00
end