Class: Lesli::UserSessionService

Inherits:
ApplicationLesliService show all
Defined in:
app/services/lesli/user_session_service.rb

Instance Method Summary collapse

Methods inherited from ApplicationLesliService

#delete, #error, #errors, #errors_as_sentence, #find, #found?, #index, #initialize, #list, #result, #show, #successful?, #update

Constructor Details

This class inherits a constructor from Lesli::ApplicationLesliService

Instance Method Details

#create(user_agent, remote_ip, session_source = "devise_standard_session") ⇒ Object

create a new session



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/services/lesli/user_session_service.rb', line 38

def create(user_agent, remote_ip, session_source="devise_standard_session")

    # register a new unique session
    current_session = current_user.sessions.create({
        :remote => remote_ip,

        :agent_os => user_agent[:os] || "unknown",
        :agent_platform => user_agent[:platform] || "unknown",
        :agent_browser => user_agent[:browser] || "unknown",
        :agent_version => user_agent[:version] || "unknown",
        
        :session_source => session_source,
        :last_used_at => Date2.new.get,

        :usage_count => 1
    })

    # register a successful sign-in log for the current user
    current_user.logs.update(
        session_id: current_session[:id], 
        title: "session_creation_successful", 
        description: current_session[:session_source] 
    )

    # register or sync the current_user with the user representation on Firebase
    #Courier::One::Firebase::User.sync_user(@resource) if defined? CloudOne

    return current_session

end