asciinema.org/app/controllers/sessions_controller.rb

42 lines
753 B
Ruby
Raw Normal View History

class SessionsController < ApplicationController
def create
2014-10-12 18:36:31 +00:00
user = login_service.validate(params[:token].to_s.strip)
if user
self.current_user = user
2014-10-17 15:28:22 +00:00
redirect_to_profile(user)
else
2014-10-12 18:36:31 +00:00
render :error
2012-03-05 23:25:21 +00:00
end
end
def destroy
self.current_user = nil
2014-10-12 18:36:31 +00:00
redirect_to root_path, notice: "See you later!"
end
private
2014-10-12 18:36:31 +00:00
def login_service
EmailLoginService.new
2012-03-10 13:58:10 +00:00
end
2014-10-17 15:28:22 +00:00
def redirect_to_profile(user)
if user.username
redirect_back_or_to profile_path(user), notice: login_notice(user)
else
redirect_to new_username_path, notice: login_notice(user)
end
end
2014-10-12 18:36:31 +00:00
def login_notice(user)
if user.first_login?
"Welcome to asciinema!"
2014-10-12 18:36:31 +00:00
else
"Welcome back!"
end
2013-10-19 16:25:30 +00:00
end
end