2016-07-07 20:50:32 +08:00
|
|
|
import Storage from '/imports/ui/services/storage/session';
|
2016-06-29 02:50:44 +08:00
|
|
|
import { callServer } from '/imports/ui/services/api';
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
class Auth {
|
|
|
|
constructor() {
|
|
|
|
this._meetingID = Storage.getItem('meetingID');
|
|
|
|
this._userID = Storage.getItem('userID');
|
|
|
|
this._authToken = Storage.getItem('authToken');
|
|
|
|
this._logoutURL = Storage.getItem('logoutURL');
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
if (!this._logoutURL) {
|
|
|
|
this._setLogOut();
|
|
|
|
}
|
|
|
|
}
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
get meetingID() {
|
|
|
|
return this._meetingID;
|
|
|
|
}
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
set meetingID(meetingID) {
|
|
|
|
this._meetingID = meetingID;
|
|
|
|
Storage.setItem('meetingID', this._meetingID);
|
|
|
|
}
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
get userID() {
|
|
|
|
return this._userID;
|
|
|
|
}
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
set userID(userID) {
|
|
|
|
this._userID = userID;
|
|
|
|
Storage.setItem('userID', this._userID);
|
|
|
|
}
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
get token() {
|
|
|
|
return this._authToken;
|
2016-06-25 07:09:32 +08:00
|
|
|
}
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
set token(authToken) {
|
|
|
|
this._authToken = authToken;
|
|
|
|
Storage.setItem('authToken', this._authToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
get logoutURL() {
|
|
|
|
return this._logoutURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
set logoutURL(logoutURL) {
|
|
|
|
this._logoutURL = logoutURL;
|
|
|
|
Storage.setItem('logoutURL', this._logoutURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
setCredentials(meeting, user, token) {
|
|
|
|
this.meetingID = meeting;
|
|
|
|
this.userID = user;
|
|
|
|
this.token = token;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCredentials() {
|
|
|
|
return {
|
|
|
|
meetingId: this.meetingID,
|
|
|
|
requesterUserId: this.userID,
|
|
|
|
requesterToken: this.token,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
clearCredentials(callback) {
|
|
|
|
this.meetingID = null;
|
|
|
|
this.userID = null;
|
|
|
|
this.token = null;
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
};
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
completeLogout() {
|
|
|
|
let logoutURL = this.logoutURL;
|
|
|
|
callServer('userLogout');
|
|
|
|
|
2016-09-08 03:17:15 +08:00
|
|
|
this.clearCredentials(() => {
|
2016-07-11 21:45:24 +08:00
|
|
|
document.location.href = logoutURL;
|
|
|
|
});
|
2016-06-25 07:09:32 +08:00
|
|
|
};
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
_setLogOut() {
|
|
|
|
let request;
|
|
|
|
let handleLogoutUrlError;
|
|
|
|
|
|
|
|
handleLogoutUrlError = function () {
|
|
|
|
console.log('Error : could not find the logoutURL');
|
|
|
|
this.logoutURL = document.location.hostname;
|
|
|
|
};
|
|
|
|
|
|
|
|
// obtain the logoutURL
|
|
|
|
request = $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/bigbluebutton/api/enter',
|
|
|
|
});
|
|
|
|
|
|
|
|
request.done(data => {
|
|
|
|
if (data.response.logoutURL != null) {
|
|
|
|
this.logoutURL = data.response.logoutURL;
|
2016-06-25 07:09:32 +08:00
|
|
|
} else {
|
|
|
|
return handleLogoutUrlError();
|
|
|
|
}
|
2016-07-11 21:45:24 +08:00
|
|
|
});
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
return request.fail(() => handleLogoutUrlError());
|
|
|
|
}
|
2016-06-29 02:50:44 +08:00
|
|
|
};
|
|
|
|
|
2016-07-11 21:45:24 +08:00
|
|
|
let AuthSingleton = new Auth();
|
|
|
|
export default AuthSingleton;
|