Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. const validateLogin = auth => {
  2. const checkUsername = auth => auth.username
  3. ? Right.of(auth)
  4. : Left.of('No Username')
  5. const checkPassword = auth => auth.password
  6. ? Right.of(auth)
  7. : Left.of('Password Empty')
  8. const checkMatch = auth => (auth.username === 'jihad' && auth.password === 'jihad123')
  9. ? Right.of(auth.username)
  10. : Left.of('Username && password mismatch')
  11.  
  12. const formatError = e => `error: ${e}`
  13. const successfulMsg = username => `Welcome back, ${username}!`
  14.  
  15. return Either.of(auth)
  16. .bind(checkUsername)
  17. .bind(checkPassword)
  18. .bind(checkMatch)
  19. .cata(formatError, successfulMsg)
  20. }
  21.  
  22. console.log(validateLogin(auth)())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement