ztechno_core 0.0.36 → 0.0.38

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.
@@ -1,4 +1,13 @@
1
1
  import { ZSqlService } from './sql_service';
2
+ type ZUser = {
3
+ id: number;
4
+ name: string;
5
+ session: string;
6
+ role: string | null;
7
+ admin: 0 | 1;
8
+ updated_at: any;
9
+ created_at: any;
10
+ };
2
11
  type ZRequiredUserColumns = {
3
12
  name: string;
4
13
  role: string | null;
@@ -24,7 +33,9 @@ export declare class ZUserService {
24
33
  register({ name, pass, role, admin }: ZRequiredUserColumns): Promise<{
25
34
  session: string;
26
35
  }>;
36
+ find(opt: { email: string }): Promise<ZUser | undefined>;
27
37
  auth(opt: ZUserSession | ZUserCredentials): Promise<{
38
+ user?: ZUser;
28
39
  session?: string;
29
40
  authenticated: boolean;
30
41
  }>;
@@ -59,6 +59,15 @@ class ZUserService {
59
59
  );
60
60
  return { session };
61
61
  }
62
+ async find(opt) {
63
+ const rows = await this.sqlService.query(
64
+ `
65
+ SELECT id, name, session, role, admin, updated_at, created_at FROM \`${this.tableName}\`
66
+ WHERE name=?`,
67
+ [opt.email],
68
+ );
69
+ return rows[0];
70
+ }
62
71
  async auth(opt) {
63
72
  if (!opt.session && !opt.name && !opt.pass) {
64
73
  return { authenticated: false };
@@ -76,7 +85,7 @@ class ZUserService {
76
85
  WHERE name=? AND pass=?`,
77
86
  [opt.name, this.hashPass(opt)],
78
87
  ));
79
- return res.length === 0 ? { authenticated: false } : { session: res[0].session, authenticated: true };
88
+ return res.length === 0 ? { authenticated: false } : { user: res[0], session: res[0].session, authenticated: true };
80
89
  }
81
90
  genSession({ name }) {
82
91
  const salt = this.salt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztechno_core",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",