Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. include(USER_RESOURCE.PHP_EXT);
  4.  
  5. class auth {
  6. public function create_session($data) {
  7. $response = array();
  8. $user_file_path = FORTKNOX_DATA_PATH.USER_RESOURCE_PATH.'/'.md5($data['email']).'/'.USER_RESOURCE_PATH.JSON_EXT;
  9. if (!file_exists($user_file_path)) {
  10. $response['code'] = HTTP_BAD_REQUEST;
  11. $response['data'] = array('error' => 'Wrong email or password');
  12. return $response;
  13. } else {
  14. $user = json_decode(file_get_contents($user_file_path), true);
  15. if (password_verify($data['password'], $user['password'])) {
  16. $auth_key = sha1(time().md5(file_get_contents($user_file_path)));
  17. if (!file_exists(FORTKNOX_DATA_PATH.'sessions/')) {
  18. mkdir(FORTKNOX_DATA_PATH.'sessions/');
  19. }
  20. file_put_contents(FORTKNOX_DATA_PATH.'sessions/'.$auth_key.JSON_EXT, json_encode(array('key' => $user['key'], 'created' => time())));
  21. $ur = USER_RESOURCE;
  22. $u = new $ur();
  23. $user_response = $u->read(array('key' => $user['key']));
  24. $user_response['data']['auth_key'] = $auth_key;
  25. return $user_response;
  26. } else {
  27. $response['code'] = HTTP_BAD_REQUEST;
  28. $response['data'] = array('error' => 'Wrong email or password');
  29. return $response;
  30. }
  31. }
  32. }
  33. }
  34.  
  35.  
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement