-
-
Save RX14/3bcfbedb71ac39353ea079a3ab79b9dc 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) | |
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 |
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