Skip to content

Commit

Permalink
Merge pull request #145 from prasad83/master
Browse files Browse the repository at this point in the history
Updated db_connector and otp package changes.
  • Loading branch information
ThomasTJdev authored Nov 19, 2023
2 parents 25da50c + 4f92623 commit 8832ea1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
8 changes: 6 additions & 2 deletions nimwc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import
nimwcpkg/constants/constants, nimwcpkg/enums/enums,
nimwcpkg/databases/databases, nimwcpkg/files/files, nimwcpkg/utils/loggers

when defined(postgres): import db_postgres
else: import db_sqlite
when NimMajor < 2:
when defined(postgres): import db_postgres
else: import db_sqlite
else:
when defined(postgres): import db_connector/db_postgres
else: import db_connector/db_sqlite

when defined(firejail): from firejail import firejailVersion, firejailFeatures

Expand Down
5 changes: 4 additions & 1 deletion nimwcpkg/constants/_sqls.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## Static Postgres/SQLite string constants, do NOT put any run-time logic here, only consts.
## Do NOT import this file directly, instead import ``constants.nim``
from strutils import format
from db_common import sql

when NimMajor < 2:
from db_common import sql
else:
from db_connector/db_common import sql

when defined(postgres):
const
Expand Down
9 changes: 6 additions & 3 deletions nimwcpkg/databases/databases.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import os, parsecfg, tables, osproc, logging, times, nativesockets, strutils, rd
import ../constants/constants, ../utils/configs, ../passwords/passwords, ../enums/enums
export head, navbar, footer, title # HTML template fragments

when defined(postgres): import db_postgres
else: import db_sqlite

when NimMajor < 2:
when defined(postgres): import db_postgres
else: import db_sqlite
else:
when defined(postgres): import db_connector/db_postgres
else: import db_connector/db_sqlite

let nimwcpkgDir = getAppDir().replace("/nimwcpkg", "")
assert dirExists(nimwcpkgDir), "nimwcpkg directory not found"
Expand Down
12 changes: 6 additions & 6 deletions nimwcpkg/nimwc_main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import
constants/constants, enums/enums, databases/databases, emails/emails, files/files,
passwords/passwords, sessions/sessions, utils/loggers, plugins/plugins, webs/html_utils


when defined(postgres):
import db_postgres
when NimMajor < 2:
when defined(postgres): import db_postgres
else: import db_sqlite
else:
import db_sqlite

when defined(postgres): import db_connector/db_postgres
else: import db_connector/db_sqlite

when defined(webp):
from webp import cwebp
Expand Down Expand Up @@ -316,7 +316,7 @@ proc login(c: var TData, email, pass, totpRaw: string): tuple[isLoginOk: bool, s
if totp in [000000, 111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999]:
return (false, "2 Factor Authentication Number must not be 6 identical digits")

let totpServerSide = $newTotp(row[7]).now()
let totpServerSide = $(Totp.init(row[7]).now())
when not defined(release):
echo "TOTP SERVER: " & totpServerSide
echo "TOTP USER : " & $totp
Expand Down
4 changes: 2 additions & 2 deletions nimwcpkg/webs/routes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ routes:
restrictTestuser(HttpGet)
if unlikely(not c.loggedIn): redirect("/")
try:
if $newTotp(@"twofakey").now() == @"testcode":
if $(Totp.init(@"twofakey").now()) == @"testcode":
resp("Success, the code matched")
else:
resp("Error, code did not match")
Expand Down Expand Up @@ -838,4 +838,4 @@ routes:
error {Http401 .. Http408}:
createTFD()
if error.data.code in [Http401, Http403]: pass
resp error.data.code, "<h1>Page not found</h1><p>You should go back.</p>"
resp error.data.code, "<h1>Page not found</h1><p>You should go back.</p>"

0 comments on commit 8832ea1

Please sign in to comment.