Skip to content

Instantly share code, notes, and snippets.

@RX14
Forked from kingsleyh/cr1.cr
Last active January 1, 2018 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RX14/3bcfbedb71ac39353ea079a3ab79b9dc to your computer and use it in GitHub Desktop.
Save RX14/3bcfbedb71ac39353ea079a3ab79b9dc 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)
sessionId = context.session.string?("userId")
return false unless sessionId
user = repo.findUserByUserId(sessionId)
return false unless user.is_a? 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)
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