@tomei/sso 0.8.8 → 0.8.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.8.8",
3
+ "version": "0.8.9",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@prisma/client": "^4.14.1",
61
- "@tomei/general": "^0.3.0",
61
+ "@tomei/general": "^0.4.0",
62
62
  "@types/jest": "^29.5.2",
63
63
  "argon2": "^0.30.3",
64
64
  "cls-hooked": "^4.2.2",
@@ -73,7 +73,7 @@
73
73
  ]
74
74
  },
75
75
  "dependencies": {
76
- "@tomei/mailer": "^0.1.3",
76
+ "@tomei/mailer": "^0.5.2",
77
77
  "reflect-metadata": "^0.1.13",
78
78
  "sequelize": "^6.32.1",
79
79
  "sequelize-typescript": "^2.1.5"
@@ -11,7 +11,7 @@ import { PasswordHashService } from '../password-hash/password-hash.service';
11
11
  import { SessionService } from '../../session/session.service';
12
12
  import { UserGroupRepository } from '../user-group/user-group.repository';
13
13
  import * as nodemailer from 'nodemailer';
14
- import { Mailer } from '@tomei/mailer';
14
+ import { SMTPMailer } from '@tomei/mailer';
15
15
  import { ISystemLogin } from '../../../src/interfaces/system-login.interface';
16
16
  import Staff from '../../models/staff.entity';
17
17
  import SystemPrivilege from '../../models/system-privilege.entity';
@@ -19,7 +19,7 @@ import LoginHistory from '../../models/login-history.entity';
19
19
  import GroupSystemPrivilege from '../../models/group-system-privilege.entity';
20
20
  import GroupRolePrivilege from '../../models/group-role-privilege.entity';
21
21
  import UserGroup from '../../models/user-group.entity';
22
- import UserSystemPrivileges from '../../models/user-system-privileges.entity';
22
+
23
23
  export class LoginUser extends ObjectBase implements IPerson {
24
24
  FullName: string;
25
25
  IDNo: string;
@@ -100,12 +100,6 @@ export class LoginUser extends ObjectBase implements IPerson {
100
100
  {
101
101
  model: Staff,
102
102
  },
103
- // {
104
- // model: SystemPrivilege,
105
- // Include: {
106
- // model: SystemPrivilege,
107
- // },
108
- // },
109
103
  ],
110
104
  });
111
105
 
@@ -136,8 +130,37 @@ export class LoginUser extends ObjectBase implements IPerson {
136
130
  ): Promise<string> {
137
131
  try {
138
132
  //validate email
139
- if (this.Email !== email) {
133
+ if (this.ObjectId && this.Email !== email) {
140
134
  throw new Error('Invalid credentials.');
135
+ } else {
136
+ const user = await LoginUser._Repository.findOne({
137
+ where: {
138
+ Email: email,
139
+ },
140
+ include: [
141
+ {
142
+ model: Staff,
143
+ },
144
+ ],
145
+ });
146
+
147
+ const userInfo: IUserInfo = {
148
+ ObjectId: user.id.toString(),
149
+ FullName: user.Staff.FullName,
150
+ IDNo: user.Staff.IdNo,
151
+ ContactNo: user.Staff.Mobile,
152
+ Email: user.Staff.Email,
153
+ Password: user.Password,
154
+ staffs: user.Staff,
155
+ };
156
+
157
+ this.ObjectId = userInfo.ObjectId;
158
+ this.FullName = userInfo.FullName;
159
+ this.IDNo = userInfo.IDNo;
160
+ this.Email = userInfo.Email;
161
+ this.ContactNo = userInfo.ContactNo;
162
+ this.Password = userInfo.Password;
163
+ this.staffs = userInfo.staffs;
141
164
  }
142
165
 
143
166
  //validate password
@@ -252,23 +275,12 @@ export class LoginUser extends ObjectBase implements IPerson {
252
275
  }
253
276
 
254
277
  if (gotPreviousLogins && !ipFound) {
255
- const SMTP_HOST = process.env.SMTP_HOST || '';
256
- const SMTP_PORT = process.env.SMTP_PORT || '';
257
- const EMAIL_SENDER = process.env.EMAIL_SENDER || '';
258
- const EMAIL_PASSWORD = process.env.EMAIL_PASSWORD || '';
259
-
260
- const mailer = new Mailer(nodemailer, {
261
- host: SMTP_HOST,
262
- port: Number(SMTP_PORT),
263
- secure: Number(SMTP_PORT) === 465,
264
- auth: {
265
- user: EMAIL_SENDER,
266
- pass: EMAIL_PASSWORD,
267
- },
268
- });
278
+ const EMAIL_SENDER =
279
+ process.env.EMAIL_SENDER || 'itd-system@tomei.com.my';
280
+ const transporter = new SMTPMailer();
269
281
 
270
- await mailer.sendMail({
271
- from: process.env.EMAIL_SENDER,
282
+ await transporter.sendMail({
283
+ from: EMAIL_SENDER,
272
284
  to: this.Email,
273
285
  subject: 'New Login Alert',
274
286
  html: `<p>Dear ${this.FullName},</p>