Module: Hippo::API::Handlers::UserSession

Defined in:
lib/hippo/api/handlers/user_session.rb

Class Method Summary collapse

Class Method Details

.checkObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hippo/api/handlers/user_session.rb', line 23

def self.check
    lambda do
        wrap_reply do
            user = Hippo::API::AuthenticationProvider.user_for_request(self)
            if user
                { success: true, message: "Login succeeded",
                  data: user.workspace_data.merge(
                      csrf: session[:csrf]
                  )
                }
            else
                { success: true, message: "not logged in", errors: { login: 'none' }, data: {} }
            end
        end
    end
end

.createObject


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hippo/api/handlers/user_session.rb', line 8

def self.create
    lambda do
        wrap_reply(with_transaction: false) do
            user = Hippo::User.(data['login']).first
            if user && user.authenticate(data['password'])
                { success: true, message: "Login succeeded",
                  data: user.workspace_data }
            else
                { success: false, message: "Login failed", errors: { login: 'failed' }, data: {} }
            end
        end
    end
end