Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // check user credentials and return fake jwt token if valid
  2. let found: User = USERS.find((user: User) => {return (params.username === user.username);});
  3. if (found) {
  4. if(params.password === found.password) {
  5. connection.mockRespond(new Response(
  6. new ResponseOptions({status: 200, body: {token: 'fake-token-jwt', user: found}})
  7. ));
  8. }else{
  9. connection.mockError(new MockError(new ResponseOptions({type:ResponseType.Error, status:400, body: JSON.stringify({code: 2, message: 'The password does not match '})})));
  10. }
  11. } else {
  12. connection.mockError(new MockError(new ResponseOptions({type:ResponseType.Error, status:400, body: JSON.stringify({code: 1, message: 'Username does not exists'})})));
  13. }
  14.  
  15. }
  16.  
  17. if (connection.request.url.endsWith('/api/authenticate/logout') && connection.request.method === RequestMethod.Post) {
  18. let params = JSON.parse(connection.request.getBody());
  19. connection.mockRespond(new Response(
  20. new ResponseOptions({status: 200, body: true})
  21. ));
  22. }
  23. }, 500);`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement