@common_ch/common 1.0.112 → 1.0.114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,6 +10,7 @@ export interface UserAttrs {
|
|
|
10
10
|
planName?: string;
|
|
11
11
|
startTimePlan?: string;
|
|
12
12
|
exTimePlan?: string;
|
|
13
|
+
versionPlanMessage?: string;
|
|
13
14
|
amountApiExistPlan?: number;
|
|
14
15
|
amountUploadExistPlan?: number;
|
|
15
16
|
email?: string;
|
|
@@ -37,6 +38,7 @@ export interface UserDoc extends mongoose.Document {
|
|
|
37
38
|
planName?: string;
|
|
38
39
|
startTimePlan?: string;
|
|
39
40
|
exTimePlan: string;
|
|
41
|
+
versionPlanMessage: string;
|
|
40
42
|
amountApiExistPlan: number;
|
|
41
43
|
amountUploadExistPlan: number;
|
|
42
44
|
email?: string;
|
package/build/models/app/user.js
CHANGED
|
@@ -14,7 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.User = exports.userStatusEnum = void 0;
|
|
16
16
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
17
|
-
|
|
17
|
+
// import { updateIfCurrentPlugin } from 'mongoose-update-if-current';
|
|
18
|
+
const password_1 = require("../../services/password");
|
|
18
19
|
var userStatusEnum;
|
|
19
20
|
(function (userStatusEnum) {
|
|
20
21
|
userStatusEnum["active"] = "active";
|
|
@@ -38,6 +39,11 @@ const userSchema = new mongoose_1.default.Schema({
|
|
|
38
39
|
ref: 'Plan',
|
|
39
40
|
required: false,
|
|
40
41
|
},
|
|
42
|
+
versionPlanMessage: {
|
|
43
|
+
type: Number,
|
|
44
|
+
required: true,
|
|
45
|
+
default: 0,
|
|
46
|
+
},
|
|
41
47
|
username: {
|
|
42
48
|
type: String,
|
|
43
49
|
required: false,
|
|
@@ -123,10 +129,31 @@ const userSchema = new mongoose_1.default.Schema({
|
|
|
123
129
|
},
|
|
124
130
|
});
|
|
125
131
|
userSchema.set('versionKey', 'version');
|
|
126
|
-
userSchema.plugin(
|
|
132
|
+
// userSchema.plugin(updateIfCurrentPlugin);
|
|
127
133
|
userSchema.statics.build = (attrs) => {
|
|
128
134
|
return new User(attrs);
|
|
129
135
|
};
|
|
136
|
+
userSchema.pre('save', function (done) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
if (this.isModified('password')) {
|
|
139
|
+
if (this.get('password')) {
|
|
140
|
+
const hashed = yield password_1.Password.toHash(this.get('password'));
|
|
141
|
+
this.set('password', hashed);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (this.isModified('versionPlanMessage')) {
|
|
145
|
+
this.$where = {
|
|
146
|
+
versionPlanMessage: this.get('versionPlanMessage'),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.$where = {
|
|
151
|
+
version: this.get('version'),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
done();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
130
157
|
userSchema.methods.updateWalletBalance = function (amount) {
|
|
131
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
159
|
const currentBalance = parseFloat(this.walletBalance.toString());
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Password = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const util_1 = require("util");
|
|
15
|
+
const scryptAsync = (0, util_1.promisify)(crypto_1.scrypt);
|
|
16
|
+
class Password {
|
|
17
|
+
static toHash(password) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const salt = (0, crypto_1.randomBytes)(8).toString('hex');
|
|
20
|
+
const buf = (yield scryptAsync(password, salt, 64));
|
|
21
|
+
return `${buf.toString('hex')}.${salt}`;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static compare(storedPassword, suppliedPassword) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const [hashedPassword, salt] = storedPassword.split('.');
|
|
27
|
+
const buf = (yield scryptAsync(suppliedPassword, salt, 64));
|
|
28
|
+
return buf.toString('hex') === hashedPassword;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Password = Password;
|