-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (31 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const auth = require('./authentication');
const co = require('co');
exports.createMiddleware = function(options) {
auth.setDatabaseFilename(options ? options.databaseFilename : undefined);
return function* () {
this.simpleauth = auth;
this.simpleauth.user = yield auth.getUserByChatId(this.chatId);
this.simpleauth.isUserAuthenticated = () => {
return !!this.simpleauth.user;
};
this.simpleauth.isCurrentUserAdmin = () => {
if (!this.simpleauth.user) {
return false;
}
return !!this.simpleauth.user.admin;
};
this.simpleauth.makeCurrentUserAdminAsync = co.wrap(function* () {
yield this.simpleauth.setUserAdminByChatId(true, this.chatId);
}.bind(this));
this.simpleauth.registerCurrentTelegramUserWithCodeAsync = co.wrap(function* (code) {
yield this.simpleauth.registerUser(
this.msg.from.username,
this.msg.from.first_name,
this.msg.from.last_name,
this.chatId,
code
);
}.bind(this));
}
};