Skip to content

Instantly share code, notes, and snippets.

@kingsleyh
Last active January 1, 2018 17:38
Show Gist options
  • Save kingsleyh/f94f42bd032e1d188f723fba85d1d0ec to your computer and use it in GitHub Desktop.
Save kingsleyh/f94f42bd032e1d188f723fba85d1d0ec to your computer and use it in GitHub Desktop.
crystal
def isLoggedIn(context, repo)
sessionId = context.session.string?("userId")
if sessionId
user = repo.findUserByUserId(sessionId)
case user
when DB::Success
groupId = user.value["activeChannel"].as_h.fetch("groupId", "")
channelId = user.value["activeChannel"].as_h.fetch("channelId", "")
puts "logged on in groupId: #{groupId} and channelId: #{channelId}"
CurrentUser.new(user.value["name"].to_s, user.value["email"].to_s,
ActiveChannel.new(groupId.to_s, channelId.to_s),
sessionId)
else
false
end
else
false
end
end
def isLoggedIn(context, repo)
for {
sessionId = context.session.string?("userId")
user <= repo.findUserByUserId(sessionId)
groupId = user.value["activeChannel"].as_h.fetch("groupId", "")
channelId = user.value["activeChannel"].as_h.fetch("channelId", "")
yield {
puts "logged on in groupId: #{groupId} and channelId: #{channelId}"
CurrentUser.new(user.value["name"].to_s, user.value["email"].to_s,
ActiveChannel.new(groupId.to_s, channelId.to_s),
sessionId)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment