Skip to content

Commit

Permalink
Merge pull request #147 from ThomasTJdev/fixBackward1.6
Browse files Browse the repository at this point in the history
Fix backward1.6
  • Loading branch information
ThomasTJdev authored Feb 23, 2024
2 parents c673430 + 3b8e71e commit ed8dcea
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 15 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
#- windows-latest
#- macOS-latest
version:
- stable
- 1.6.18
# - stable

steps:
- uses: actions/checkout@v1
Expand All @@ -41,7 +42,10 @@ jobs:
run: nimble build

- name: Compile RELEASE Mode
run: nimble build -d:release
run: |
nimble build -d:release
cp config/config_default.cfg config/config.cfg
./nimwc --quitAfterCompile

- name: Nimble install
run: nimble install
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
#- windows-latest
#- macOS-latest
version:
- stable
- 1.6.18
# - stable

steps:
- uses: actions/checkout@v2
Expand All @@ -37,7 +38,10 @@ jobs:
run: nimble -y install --depsOnly

- name: Build binaries
run: nimble build -d:release
run: |
nimble build -d:release
cp config/config_default.cfg config/config.cfg
./nimwc --quitAfterCompile

- name: Archive Release
uses: papeloto/action-zip@v1
Expand Down
12 changes: 10 additions & 2 deletions nimwc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ proc startupCheck(cfg: Config) =
if not fileExists(appPath) or defined(rc):
# Ensure that the DB tables are created
echo compile_start_msg & userArgs & "\n\n"
let nimv2 = if NimMajor >= 2: " --mm:orc " else: ""

let (output, exitCode) = execCmdEx("nim c --out:" & appPath & " " & compileOptions & " " & getAppDir() & "/nimwcpkg/nimwc_main.nim")
let (output, exitCode) = execCmdEx("nim c --out:" & appPath & " " & compileOptions & " " & nimv2 & " " & getAppDir() & "/nimwcpkg/nimwc_main.nim")
if exitCode != 0:
styledEcho(fgRed, bgBlack, compile_fail_msg)
echo output
Expand All @@ -247,6 +248,8 @@ when isMainModule:
when defined(dev):
echo($compileOptions, "\n\n")

var quitAfterCompile = false

for keysType, keys, values in getopt():
case keysType
of cmdShortOption, cmdLongOption:
Expand Down Expand Up @@ -279,15 +282,20 @@ when isMainModule:
echo backupDb(cfg.getSectionValue("Database", when defined(postgres): "name" else: "host"), checksum=false, sign=false, targz=false)
of "backuplogs":
echo backupOldLogs(splitPath(cfg.getSectionValue("Logging", when defined(release): "logfile" else: "logfiledev")).head)
of "quitAfterCompile":
quitAfterCompile = true

of cmdArgument:
discard

of cmdEnd:
quit("Wrong arguments, please see help with: --help", 1)

if keys.len != 0:
if keys.len != 0 and not quitAfterCompile:
quit("Run again with no arguments, please see help with: --help", 0)

startupCheck(cfg)
if quitAfterCompile:
sleep(1000)
launcherActivated(cfg)

7 changes: 5 additions & 2 deletions nimwc.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ installDirs = @["config", "nimwcpkg", "plugins", "public"]
when NimMajor >= 2:
requires "db_connector >= 0.1.0"
requires "smtp >= 0.1.0"
requires "https://github.com/ThomasTJdev/otp.nim == 0.3.3"
requires "https://github.com/ThomasTJdev/jester_fork >= 1.0.0"
else:
requires "https://github.com/ThomasTJdev/otp.nim == 0.1.5"
requires "jester >= 0.4.3"


# Dependencies
requires "nim >= 1.6.0"
requires "jester >= 0.4.3"
requires "bcrypt >= 0.2.1"
requires "datetime2human >= 0.2.5"
requires "firejail >= 0.5.0"
requires "otp >= 0.1.1"
requires "recaptcha >= 1.0.3"
requires "webp >= 0.2.5"
requires "packedjson >= 0.1.0"
Expand Down
11 changes: 9 additions & 2 deletions nimwcpkg/nimwc_main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ import
import
bcrypt,
datetime2human,
jester,
otp

when NimMajor > 2:
import jester_fork
else:
import jester

import
constants/constants, enums/enums, databases/databases, emails/emails, files/files,
passwords/passwords, sessions/sessions, utils/loggers, plugins/plugins, webs/html_utils
Expand Down Expand Up @@ -316,7 +320,10 @@ 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 = $(Totp.init(row[7]).now())
when NimMajor >= 2:
let totpServerSide = $(Totp.init(row[7]).now())
else:
let totpServerSide = $(newTotp(row[7]).now())
when not defined(release):
echo "TOTP SERVER: " & totpServerSide
echo "TOTP USER : " & $totp
Expand Down
6 changes: 5 additions & 1 deletion nimwcpkg/sessions/sessions.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from jester import Request


when NimMajor > 2:
from jester_fork import Request
else:
from jester import Request

type
Rank* = enum ## Rank for the User.
User
Expand Down
17 changes: 13 additions & 4 deletions nimwcpkg/webs/routes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ routes:
let (loginB, loginS) = login(c, replace(toLowerAscii(@"email"), " ", ""), replace(@"password", " ", ""), replace(@"totp", " ", ""))
when defined(dev): echo("\nMail: ", @"email", "\nPassword2 (HoneyPot): ", @"password2", "\n(loginB, loginS): ", (loginB, loginS))
if loginB:
jester.setCookie("sid", loginS, daysForward(7))
when NimMajor > 2:
jester_fork.setCookie("sid", loginS, daysForward(7))
else:
jester.setCookie("sid", loginS, daysForward(7))
redirect("/settings")
else:
redirect("/login?msg=" & encodeUrl(loginS))
Expand Down Expand Up @@ -556,10 +559,16 @@ routes:
restrictTestuser(HttpGet)
if unlikely(not c.loggedIn): redirect("/")
try:
if $(Totp.init(@"twofakey").now()) == @"testcode":
resp("Success, the code matched")
when NimMajor >= 2:
if $(Totp.init(@"twofakey").now()) == @"testcode":
resp("Success, the code matched")
else:
resp("Error, code did not match")
else:
resp("Error, code did not match")
if $(newTotp(@"twofakey").now()) == @"testcode":
resp("Success, the code matched")
else:
resp("Error, code did not match")
except:
resp("Error generating 2FA")

Expand Down

0 comments on commit ed8dcea

Please sign in to comment.