Last active
July 3, 2018 19:35
-
-
Save 5outh/1891496de6e7bed696c564594a09339d to your computer and use it in GitHub Desktop.
Authorized
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
orNotFound :: MaybeT Handler a -> Handler a | |
orNotFound mHandler = do | |
act <- runMaybeT mHandler | |
maybe notFound act | |
withStudentToken :: (StudentId -> CourseId -> Handler a) -> MaybeT Handler a | |
withStudentToken action = do | |
mStudentToken <- MaybeT optionalStudentToken | |
case mStudentToken of | |
Nothing -> mempty | |
Just (StudentAuth studentId courseId) -> MaybeT $ action studentId courseId | |
withTeacherToken :: (TeacherId -> Handler a) -> MaybeT Handler a | |
withTeacherToken action = do | |
mTeacherToken <- MaybeT optionalTeacherToken | |
case mTeacherToken of | |
Nothing -> mempty | |
Just (TeacherAuth teacherId) -> MaybeT $ action teacherId | |
myHandler = orNotFound $ withStudentToken handleStudent <|> withTeacherToken handleTeacher |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment