Advertisement
Guest User

Untitled

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