mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Added session service
This commit is contained in:
parent
e5d7294b69
commit
b6cf34450f
@ -7,24 +7,21 @@ import { Provider } from 'react-redux'
|
||||
|
||||
import { WebApi } from 'src/web-api.js'
|
||||
import { Database } from 'src/database.js'
|
||||
//import { Session } from 'src/model/session.js';
|
||||
|
||||
import { SessionService } from 'src/service/session-service.js';
|
||||
|
||||
import { Log } from 'src/log.js'
|
||||
|
||||
|
||||
let debugMode = true;
|
||||
let clientId = 'A7D301DA7D301DA7D301DA7D301DA7D3';
|
||||
|
||||
let db = new Database();
|
||||
db.setDebugEnabled(debugMode);
|
||||
db.open();
|
||||
|
||||
|
||||
// let test = {
|
||||
// 'abcd' : 123,
|
||||
// 'efgh' : 456,
|
||||
// }
|
||||
|
||||
// for (let [key, value] of test) {
|
||||
// console.info(key, value);
|
||||
// }
|
||||
|
||||
let defaultState = {
|
||||
'myButtonLabel': 'clicko123456',
|
||||
@ -129,16 +126,12 @@ class App extends Component {
|
||||
|
||||
}
|
||||
|
||||
// let api = new WebApi('http://192.168.1.2', 'A7D301DA7D301DA7D301DA7D301DA7D3');
|
||||
// api.exec('POST', 'sessions', null, {
|
||||
// 'email': 'laurent@cozic.net',
|
||||
// 'password': '12345678',
|
||||
// })
|
||||
// .then(function(data) {
|
||||
// let api = new WebApi('http://192.168.1.2');
|
||||
// let sessionService = new SessionService(api);
|
||||
// sessionService.login('laurent@cozic.net', '12345678', clientId).then((session) => {
|
||||
// console.info('GOT DATA:');
|
||||
// console.info(data);
|
||||
// })
|
||||
// .catch(function(error) {
|
||||
// console.info(session);
|
||||
// }).catch(function(error) {
|
||||
// console.warn('GOT ERROR:');
|
||||
// console.warn(error);
|
||||
// })
|
||||
|
5
ReactNativeClient/src/base-model.js
Normal file
5
ReactNativeClient/src/base-model.js
Normal file
@ -0,0 +1,5 @@
|
||||
class BaseModel {
|
||||
|
||||
}
|
||||
|
||||
export { BaseModel };
|
9
ReactNativeClient/src/base-service.js
Normal file
9
ReactNativeClient/src/base-service.js
Normal file
@ -0,0 +1,9 @@
|
||||
class BaseService {
|
||||
|
||||
constructor(webApi) {
|
||||
this.api_ = webApi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { BaseService };
|
11
ReactNativeClient/src/model/session.js
Normal file
11
ReactNativeClient/src/model/session.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { BaseModel } from 'src/base-model.js';
|
||||
|
||||
class Session extends BaseModel {
|
||||
|
||||
static login(email, password) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Session };
|
15
ReactNativeClient/src/service/session-service.js
Normal file
15
ReactNativeClient/src/service/session-service.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { BaseService } from 'src/base-service.js';
|
||||
|
||||
class SessionService extends BaseService {
|
||||
|
||||
login(email, password, clientId) {
|
||||
return this.api_.post('sessions', null, {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'client_id': clientId,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { SessionService };
|
@ -2,9 +2,8 @@ const queryString = require('query-string');
|
||||
|
||||
class WebApi {
|
||||
|
||||
constructor(baseUrl, clientId) {
|
||||
constructor(baseUrl) {
|
||||
this.baseUrl_ = baseUrl;
|
||||
this.clientId_ = clientId;
|
||||
}
|
||||
|
||||
makeRequest(method, path, query, data) {
|
||||
@ -36,11 +35,15 @@ class WebApi {
|
||||
fetch(r.url, r.options).then(function(response) {
|
||||
let responseClone = response.clone();
|
||||
return response.json().then(function(data) {
|
||||
if (data && data.error) {
|
||||
reject(data);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
responseClone.text().then(function(text) {
|
||||
reject('Cannot parse JSON: ' + text);
|
||||
reject(new Error('Cannot parse JSON: ' + text));
|
||||
});
|
||||
});
|
||||
})
|
||||
|
@ -29,8 +29,6 @@ class Session extends BaseModel {
|
||||
$ok = self::verifyPassword($password, $user->password);
|
||||
if (!$ok) throw new AuthException();
|
||||
|
||||
if (!$clientId) throw new \Exception('clientId is required');
|
||||
|
||||
$session = new Session();
|
||||
$session->owner_id = $user->id;
|
||||
$session->client_id = $clientId;
|
||||
|
Loading…
Reference in New Issue
Block a user