@rpcbase/server 0.83.0 → 0.87.0

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.
package/database.js CHANGED
@@ -1,7 +1,14 @@
1
1
  /* @flow */
2
- const mongoose = require("mongoose")
3
2
  const isPort = require("validator/lib/isPort")
4
3
 
4
+ const mongoose = require("./mongoose")
5
+
6
+ // load internal models
7
+ require("./src/models/User")
8
+ require("./src/models/Invite")
9
+ require("./src/models/ResetPasswordToken")
10
+
11
+
5
12
  const {DATABASE_NAME, DATABASE_PORT, CONTAINER_MODE} = process.env
6
13
 
7
14
 
package/mailer/index.js CHANGED
@@ -3,7 +3,7 @@ const postmark = require("postmark")
3
3
 
4
4
  const {POSTMARK_API_KEY, IS_PRODUCTION} = process.env
5
5
 
6
- const is_production = true //IS_PRODUCTION === "yes"
6
+ const is_production = IS_PRODUCTION === "yes"
7
7
  console.warn("email sender forcing is production")
8
8
 
9
9
  let client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.83.0",
3
+ "version": "0.87.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -10,10 +10,10 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 0"
11
11
  },
12
12
  "dependencies": {
13
- "@rpcbase/agent": "0.9.0",
13
+ "@rpcbase/agent": "0.10.0",
14
14
  "@rpcbase/std": "0.3.0",
15
15
  "body-parser": "1.20.0",
16
- "bull": "4.8.4",
16
+ "bull": "4.8.5",
17
17
  "connect-redis": "6.1.3",
18
18
  "cors": "2.8.5",
19
19
  "debug": "4.3.4",
@@ -22,7 +22,7 @@
22
22
  "express-session": "1.17.3",
23
23
  "glob": "8.0.3",
24
24
  "lodash": "4.17.21",
25
- "mongoose": "6.4.3",
25
+ "mongoose": "6.5.1",
26
26
  "picocolors": "1.0.0",
27
27
  "postmark": "3.0.12",
28
28
  "redis": "4.2.0",
package/src/auth/index.js CHANGED
@@ -8,6 +8,7 @@ const reset_password = require("./reset_password")
8
8
  const set_new_password = require("./set_new_password")
9
9
  const check_session = require("./check_session")
10
10
 
11
+
11
12
  const sign_up_handler = async(req, res) => {
12
13
  const result = await sign_up(req.body, {req})
13
14
  res.json(result)
@@ -27,6 +27,7 @@ const sign_in = async({email, password}, ctx) => {
27
27
  const is_match = await compare_hash(password, hashed_pass)
28
28
 
29
29
  if (is_match) {
30
+ console.log("is match, user signed in wow")
30
31
  req.session.user_id = user._id.toString()
31
32
  await req.session.save()
32
33
  return {
@@ -3,6 +3,8 @@ const {hash_password} = require("@rpcbase/std/crypto/hash")
3
3
 
4
4
  const mongoose = require("../../mongoose")
5
5
 
6
+ const HAS_INVITES = process.env.AUTH_DISABLE_INVITES !== "true"
7
+
6
8
  const sign_up = async({email, password}, ctx) => {
7
9
  const User = mongoose.model("User")
8
10
  const Invite = mongoose.model("Invite")
@@ -20,18 +22,22 @@ const sign_up = async({email, password}, ctx) => {
20
22
  }
21
23
 
22
24
  // check if we have an invite for this user
23
- const invite = await Invite.findOne({email}, null, {ctx})
24
- if (invite && !invite.is_ready) {
25
- console.log("found an invite, but not ready", email)
26
- return {
27
- status: "error",
28
- message: "Your invite is still pending approval. Expect an email in the next weeks to activate your account."
29
- }
30
- } else if (!invite) {
31
- console.log("no invite for signup email:", email)
32
- return {
33
- status: "error",
34
- message: "No valid invite was found for this email"
25
+ if (HAS_INVITES) {
26
+ const invite = await Invite.findOne({email}, null, {ctx})
27
+
28
+ // TODO: mark invite as accepted here
29
+ if (invite && !invite.is_ready) {
30
+ console.log("found an invite, but not ready", email)
31
+ return {
32
+ status: "error",
33
+ message: "Your invite is still pending approval. Expect an email in the next weeks to activate your account."
34
+ }
35
+ } else if (!invite) {
36
+ console.log("no invite for signup email:", email)
37
+ return {
38
+ status: "error",
39
+ message: "No valid invite was found for this email"
40
+ }
35
41
  }
36
42
  }
37
43
 
@@ -0,0 +1,23 @@
1
+ /* @flow */
2
+ const mongoose = require("../../mongoose")
3
+
4
+ const Invite = mongoose.model("Invite", {
5
+ email: String,
6
+ email_hash: String, // TODO: unused field?
7
+ token: String,
8
+ expires: Date,
9
+ is_ready: {
10
+ type: Boolean,
11
+ default: false,
12
+ },
13
+ is_sent: {
14
+ type: Boolean,
15
+ default: false,
16
+ },
17
+ is_accepted: {
18
+ type: Boolean,
19
+ default: false,
20
+ },
21
+ })
22
+
23
+ module.exports = Invite
@@ -0,0 +1,17 @@
1
+ /* @flow */
2
+ const mongoose = require("../../mongoose")
3
+
4
+ const User = mongoose.model("User", {
5
+ name: {
6
+ type: String,
7
+ default: "",
8
+ },
9
+ email: String,
10
+ is_email_verified: {
11
+ type: Boolean,
12
+ default: false,
13
+ },
14
+ password_hash: String,
15
+ })
16
+
17
+ module.exports = User