Last active
January 1, 2018 17:38
-
-
Save kingsleyh/f94f42bd032e1d188f723fba85d1d0ec to your computer and use it in GitHub Desktop.
crystal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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