Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include(USER_RESOURCE.PHP_EXT);
- class auth {
- public function create_session($data) {
- $response = array();
- $user_file_path = FORTKNOX_DATA_PATH.USER_RESOURCE_PATH.'/'.md5($data['email']).'/'.USER_RESOURCE_PATH.JSON_EXT;
- if (!file_exists($user_file_path)) {
- $response['code'] = HTTP_BAD_REQUEST;
- $response['data'] = array('error' => 'Wrong email or password');
- return $response;
- } else {
- $user = json_decode(file_get_contents($user_file_path), true);
- if (password_verify($data['password'], $user['password'])) {
- $auth_key = sha1(time().md5(file_get_contents($user_file_path)));
- if (!file_exists(FORTKNOX_DATA_PATH.'sessions/')) {
- mkdir(FORTKNOX_DATA_PATH.'sessions/');
- }
- file_put_contents(FORTKNOX_DATA_PATH.'sessions/'.$auth_key.JSON_EXT, json_encode(array('key' => $user['key'], 'created' => time())));
- $ur = USER_RESOURCE;
- $u = new $ur();
- $user_response = $u->read(array('key' => $user['key']));
- $user_response['data']['auth_key'] = $auth_key;
- return $user_response;
- } else {
- $response['code'] = HTTP_BAD_REQUEST;
- $response['data'] = array('error' => 'Wrong email or password');
- return $response;
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement